Program E : ;************************************ ; written by : John Morton * ; date : 26/07/97 * ; version : 1.0 * ; file saved as : Traffic * ; for PIC54 * ; clock frequency : 3.82 MHz * ;************************************ ; PROGRAM FUNCTION : A pedestrian traffic lights junction is simulated. list P=16C54 include "c:\pic\p16c5x.inc" ;============ ; Declarations : porta equ 05 portb equ 06 Mark15 equ 08 Post80 equ 09 Counter16 equ 0A Counter8 equ 0B org 1FF goto Start org 0 ;=========== ; Subroutines : Init clrf porta ; resets inputs and outputs clrf portb ; movlw b'0001' ; RA0 : push button, RA1-3 : not connected tris porta ; movlw b'00000000' ; Motorists : RB0 : green, RB1 : amber, tris portb ; RB2 : red. Pedestrians : RB4 : green, ; RB5 : red, RB3 and RB6-7 : not connected movlw b'00000111' ; sets up timing register option retlw 0 delay movlw d'15' ; moves the decimal number 15 into movwf Mark15 ; the G.P.F. called Mark15 movlw d'80' ; moves the decimal number 80 into movwf Post80 ; the G.P.F called Post80 TimeLoop movfw Mark15 ; takes the number out of Mark15 subwf TMR0, w ; subtracts this number from the number in ; TMR0, leaving the result in the working ; register (and leaving TMR0 unchanged) btfss STATUS, Z ; tests the Zero Flag - skip if set, i.e. if the result ; is zero it will skip the next instruction goto TimeLoop ; if the result isn't zero, it loops back to 'Loop' movlw d'15' ; moves the decimal number 15 into the working addwf Mark15, f ; register and then adds it to 'Mark15' decfsz Post80, f ; decrements 'Post80', and skips the next ; instruction if the result is zero goto TimeLoop ; if the result isn't zero, it loops back to 'Loop' retlw 0 ; when half a second has passed, it returns ;============= ; Program Start : Start call Init Main movlw b'00010100' ; motorists : green on, others off movwf portb ; pedestrians : red on, others off ButtonLoop btfss porta, 0 ; is the pedestrian's button pressed? goto ButtonLoop ; no, so loops back bsf porta, 1 ; turns motorist's amber light on bcf porta, 2 ; turns motorist's green light off call delay ; waits half a second call delay ; waits half a second call delay ; waits half a second call delay ; waits half a second movlw b'00100001' ; motorists : red on, amber off movwf portb ; pedestrians : green on, red off movlw d'16' ; moves the decimal number 16 into the general movwf Counter16 ; purpose file register called Counter16 Loop8 call delay ; creates half second decfsz Counter16, f ; does this sixteen times goto Loop8 ; loops back until eight seconds have passed bsf porta, 1 ; turns motorist's amber light on bcf porta, 2 ; turns motorist's red light off movlw d'8' ; moves the decimal number 8 into Counter8 movwf Counter8 ; FlashLoop movlw b'00100000' ; toggles the green pedestrian light xorwf portb, f ; call delay ; creates half second delay decfsz Counter8, f ; makes it happen eight times goto FlashLoop ; loops back goto Main ; loops back to start END