Program D : ;************************************ ; written by : John Morton * ; date : 26/07/97 * ; version : 1.0 * ; file saved as : Timing * ; for PIC54 * ; clock frequency : 2.4576 MHz * ;************************************ ; PROGRAM FUNCTION : The state of an LED is toggled every second and a buzzer ; sounds for one second every five seconds. list P=16C54 include "c:\pic\p16c5x.inc" ;============ ; Declarations : porta equ 05 portb equ 06 Mark30 equ 08 Post80 equ 09 _5Second equ 0A org 1FF goto Start org 0 ;=========== ; Subroutines : Init clrf porta ; resets inputs and outputs clrf portb ; movlw b'0000' ; RA0 : LED, RA1-3 : not connected tris porta movlw b'00000000' ; RB0 : buzzer, RB1-7 : not connected tris portb movlw b'00000111' ; sets up timing register option movlw d'30' ; sets up marker movwf Mark30 ; movlw d'80' ; sets up first postscaler movwf Post80 ; movlw d'5' ; sets up five second counter movwf _5Second ; retlw 0 ;============= ; Program Start : Start call Init Main movfw Mark30 ; takes the number out of Mark30 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 Main ; if the result isn't zero, it loops back to 'Loop' movlw d'30' ; moves the decimal number 30 into the working addwf Mark30, f ; register and then adds it to 'Mark30' decfsz Post80, f ; decrements 'Post80', and skips the next ; instruction if the result is zero goto Main ; if the result isn't zero, it loops back to 'Loop' ; one second has now passed movlw d'80' ; resets postscaler movwf Post80 ; comf porta, f ; toggles LED state bcf portb, 0 ; turns off buzzer decfsz _5Second, f ; has five seconds passed? goto Main ; no, loop back bsf portb, 0 ; turns on buzzer movlw d'5' ; resets 5 second counter movwf _5Second ; goto Main ; loops back to start END