piclist 2000\05\30\190317a >
Thread: 16F873 stopwatch code wanted
www.piclist.com/techref/microchip/devices.htm?key=16F
flavicon
picon face BY : Tony Nixon email (remove spam text)



Sorry for the logish post, but this may work better.

I wrote the other in a few spare minutes before knock off last night.

        include "P16f873.inc"

        CBLOCK 0x20

TimeH
TimeL
Debounce
Flags
DelayH
DelayL

        ENDC

;
; Set Delay value 1 - 65535 mS
;

Delay = 1

         org 0h

         clrf PORTA
         clrf PORTB
         clrf PORTC
         bsf STATUS,RP0
         movlw b'11000010'
         movwf OPTION_REG
         movlw b'00000001'
         movwf TRISA
         clrf TRISB
         clrf TRISC
         movlw b'10000110'
         movwf ADCON1
         bcf STATUS,RP0

         clrf Debounce
         movlw b'00000001'   ; flag key is up
         movwf Flags
         clrf TimeH
         clrf TimeL

         clrf DelayH
         clrf DelayL

         movlw 84h
         movwf TMR0
         bcf INTCON,T0IF

WtLoop    btfss INTCON,T0IF   ; 999uS @ 4MHz
         goto WtLoop

         bcf INTCON,T0IF
       movlw 84h
         movwf TMR0

       incf DelayL           ; increment delay count
       btfsc STATUS,Z
       incf DelayH

       movlw High(Delay)     ; if = Delay value then
       xorwf DelayH,W        ; increment the Time counter
       btfss STATUS,Z
       goto ButtChk

       movlw Low(Delay)
       xorwf DelayL,W
       btfss STATUS,Z
       goto ButtChk

       incf TimeL
       btfsc STATUS,Z
       incf TimeH

       clrf DelayH
       clrf DelayL

ButtChk movf Debounce         ; read key if debounce = 0
       btfsc STATUS,Z
       goto DoButt

       decf Debounce
       goto WtLoop
;
; Key input is high when released
;
DoButt  btfss PORTA,0         ; test for low
       goto IzLow

       btfsc Flags,0
       goto WtLoop           ; already released

       bsf Flags,0           ; flag key is now up
       movlw 10h
       movwf Debounce
       goto WtLoop

IzLow   btfss Flags,0
       goto WtLoop           ; already released

       bcf Flags,0           ; flag key now down
       movlw 10h
       movwf Debounce

       movf TimeH,w          ; output data to PortB & C
       movwf PORTB
       movf TimeL,w
       movwf PORTC

       clrf TimeH            ; reset timers
       clrf TimeL
       clrf DelayH
       clrf DelayL
       bcf INTCON,T0IF
       movlw 84h
       movwf TMR0
       goto WtLoop

       end

--
Best regards

Tony

http://www.picnpoke.com
KILLspamsalesEraseMEspamEraseMEpicnpoke.com

<3934487E.664390E5@eng.monash.edu.au> 7BIT

See also: www.piclist.com/techref/microchip/devices.htm?key=16F
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) 16F873 stopwatch code wanted

month overview.

new search...