Program H : ;************************************ ; written by : John Morton * ; date : 19/08/97 * ; version : 3.0 * ; file saved as : Counter * ; for PIC54 * ; clock frequency : 3.82 MHz * ;************************************ ; PROGRAM FUNCTION : To count the number of times a push button is pressed, ; resetting after the sixteenth signal. list P=16C54 include "c:\pic\p16c5x.inc" ;============ ; Declarations : porta equ 05 portb equ 06 Counter equ 08 org 1FF goto Start org 0 ;=========== ; Subroutines : Init clrf porta ; resets I/O ports movlw b'11111100' ; moves the code for a 0 into portb movwf portb ; movlw b'0001' ; RA0 : push button, RA1-3 : not connected tris porta movlw b'00000000' ; RB0 : not connected, RB1-7 : Seven Seg. Code tris portb ; movlw b'00000111' ; TMR0 prescaled at 256 option ; clrf Counter ; resets Counter register retlw 0 _7SegDisp addwf PCL ; skips a certain number of instructions retlw b'11111110' ; code for 0 retlw b'01100000' ; code for 1 retlw b'11011010' ; code for 2 retlw b'11110010' ; code for 3 retlw b'01100110' ; code for 4 retlw b'10110110' ; code for 5 retlw b'10111110 ; code for 6 retlw b'11100000' ; code for 7 retlw b'11111110' ; code for 8 retlw b'11110110' ; code for 9 retlw b'11101110' ; code for A retlw b'00111110' ; code for b retlw b'10011100' ; code for C retlw b'01111010' ; code for d retlw b'10011110' ; code for E retlw b'10001110' ; code for F ;============= ; Program Start : Start call Init ; sets up inputs and outputs Main btfss portb, 0 ; tests push button goto Main ; if not pressed, loops back incf Counter, f ; movlw d'16' ; has Counter reached 16? subwf Counter, w ; btfss STATUS, Z ; clrf Counter ; if yes, resets Counter movfw Counter ; moves Counter into the working reg. call _7SegDisp ; converts into 7 seg code movwf portb ; displays value TestLoop btfsc portb, 0 ; tests push button goto TestLoop ; still pressed, so keeps looping clrf TMR0 ; resets TMR0 TimeLoop movlw d'255' ; has TMR0 reached 255? subwf TMR0, w ; btfss STATUS, Z ; goto TimeLoop ; if not, keeps looping goto Main ; 0.07 seconds has passed, so goes to Main END