PROGRAM L ;************************************ ; written by : John Morton * ; date : 24/08/97 * ; version : 1.0 * ; file saved as : Bike * ; for PIC16F54 * ; clock frequency : 2.4576 MHz * ;************************************ ; PROGRAM FUNCTION: A bicycle spedometer and mileometer list P=16F54 include "c:\pic\p16f5x.inc" __config _RC_OSC & _WDT_OFF & _CP_OFF ;============ ; Declarations : porta equ 05 portb equ 06 Dist1 equ 09 Dist10 equ 0B Dist100 equ 08 SP10th equ 0D SP1 equ 0F SP10 equ 0C Speed10th equ 10 Speed1 equ 11 Speed10 equ 12 General equ 13 Mark89 equ 14 tempa equ 15 _10 equ 16 #define mode portb, 0 #define counter porta, 3 #define debouncer General, 0 org 1FFh goto Start org 0 ;=========== ; Subroutines : Init movlw b'0001' ; yes, so resets Port A movwf porta ; clrf portb movlw b'1000' ; RA0-2 : controllers for 7 seg tris porta ; display, RA3 - counter movlw b'00000001' ; RB0 : select switch, RB1-7 7 tris portb ; seg code movlw d'9' ; resets speed regs. movwf Speed10th ; movwf Speed1 ; movwf Speed10 ; clrf Dist1 clrf Dist10 clrf Dist100 clrf TMR0 ; clrf SP1 clrf SP10th clrf SP10 retlw 0 Display movwf FSR ; speed, or distance decfsz _10 ; changes display every ten times retlw 0 ; it gets here movlw d'10' ; movwf _10 ; movlw b'0111' andwf porta, w movwf tempa bcf STATUS, C rrf tempa ; selects next display btfss STATUS, C goto CodeSelect movlw b'0100' ; yes, so resets Port A movwf tempa ; CodeSelect movlw b'0111' ; ignores button andwf porta,w ; uses Port A to select correct addwf FSR, f ; file register movfw INDF ; takes out the corect code call _7SegDisp ; converts code movwf portb ; displays number movfw tempa movwf porta retlw 0 ; returns _7SegDisp addwf PCL ; returns with correct code retlw b'01111110' ; 0 retlw b'00001100' ; 1 retlw b'10110110' ; 2 retlw b'10011110' ; 3 retlw b'11001100' ; 4 retlw b'11011010' ; 5 retlw b'11111010' ; 6 retlw b'00001110' ; 7 retlw b'11111110' ; 8 retlw b'11011110' ; 9 retlw b'01110000' ; L Debounce btfsc debouncer ; has signal finished? goto NextTest ; yes, so tests button btfss counter ; has signal finished? bsf debouncer ; yes, so sets bit retlw 0 ; no, so returns NextTest btfss counter ; second signal? retlw 0 ; no, so returns movfw Speed10th ; transfers file regs. so that movwf SP10th ; values are displayed movfw Speed1 ; movwf SP1 ; movfw Speed10 ; movwf SP10 ; movlw d'9' ; resets speed regs. movwf Speed10th ; movwf Speed1 ; movwf Speed10 ; bcf debouncer retlw 0 ;============= ; Program Start : Start call Init Main btfsc mode ; which mode is it in? goto Speed ; Speed mode ;======== Distance movlw b'00110100' ; TMR0 counts external signals option ; prescaled by 32 DistLoop btfsc mode ; checks mode goto Speed ; Speed mode movlw 07h call Display ; movlw d'21' ; has TMR0 reached 21? subwf TMR0, w ; btfss STATUS, Z ; goto DistLoop ; no, so loops back incf Dist1 ; increments 1 kms clrf TMR0 movlw d'10' ; has Dist1 reached 10? subwf Dist1, w ; btfss STATUS, Z ; goto DistLoop ; no, so loops back incf Dist10 ; increments 10 kms clrf Dist1 movlw d'10' ; has Dist10 reached 10? subwf Dist10, w ; btfss STATUS, Z ; goto DistLoop ; no, so loops back incf Dist100 ; increments 100 kms clrf Dist10 movlw d'10' ; has Dist100 reached 10? subwf Dist100, w ; btfss STATUS, Z ; goto DistLoop ; no, so loops back clrf Dist100 ; has passed limit, so resets and goto Main ; loops back ;======== Speed movlw b'00000110' ; TMR0 : internal, prescaled option ; at 128 btfss counter ; waits for first signal goto Speed+2 ; keeps looping BasicTimeLoop btfss mode ; checks mode goto Distance ; Speed mode movlw 0Bh ; call Display ; call Debounce ; movfw Mark89 ; have 0.0185 seconds passed? subwf TMR0, w ; btfss STATUS, Z ; goto BasicTimeLoop ; no, so loops back movlw d'89' ; (adds 89 to marker) addwf Mark89 ; decf Speed10th, f ; yes, so decrements speed by ; one tenth of a km per hour movlw d'255' ; has it passed 0? subwf Speed10th, w ; btfss STATUS, Z ; goto BasicTimeLoop ; no,so loops back movlw d'9' ; resets 10th unit movwf Speed10th ; decf Speed1, f ; movlw d'255' ; has it passed 0? subwf Speed1, w ; btfss STATUS, Z ; goto BasicTimeLoop ; movlw d'9' ; resets 1 unit movwf Speed1 ; decf Speed10,f ; movlw d'255' ; has it passed 0? subwf Speed10, w ; btfss STATUS, Z ; goto BasicTimeLoop ; TooSlow clrf SP10th ; displays "SLO" on the displays movlw d'10' movwf SP1 movlw d'5' movwf SP10 movlw 0Bh ; call Display ; btfss counter ; tests for button goto TooSlow ; no, so keeps looping movlw d'9' ; resets speed regs. movwf Speed10 ; goto BasicTimeLoop ; END