Searching \ for '[PIC]: 16F873 stopwatch code wanted' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=16F
Search entire site for: '16F873 stopwatch code wanted'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: 16F873 stopwatch code wanted'
2000\05\30@030810 by Tony Nixon

flavicon
picon face
Mark Willcox wrote:
>
> Hi all
>   I would like to build a simple stopwatch using a 16f873 @ 4Mhz(xt). The
> stop/start could be on RA4/TOCS or an external interrupt on RB0. Once
> started, I would like the counter to incf a register(s)each FF to 00
> overflow and count the number of overflows during run time(# of overflows x
> machine cycles = ms or sec)? I would like this stopwatch to be able to count
> from milliseconds up to seconds(if possible). I would like to display the
> count register(s) total at the end(stop) of count on ports B&C(2 x 8 LED
> bargraphs). Any help you can give will be greatly appreciated, thanks in
> advance, Mark
> ________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

Got no idea if it works properly.

Key press on PORTA,0 reads and sets data on PORTB,C.

       include "P16f873.inc"

       CBLOCK 0x20

TimeH
TimeL
Debounce
KeyFlag

       ENDC

       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 KeyFlag
       clrf TimeH
       clrf TimeL

Reset   movlw 84h
       movwf TMR0
       bcf INTCON,T0IF

WtLoop  btfss INTCON,T0IF       ; 1mS @ 4MHz
       goto WtLoop

       incf TimeL
       btfsc STATUS,Z
       incf TimeH

       movf Debounce
       btfsc STATUS,Z
       goto ButtChk

       decf Debounce
       goto Reset

ButtChk btfss PORTA,0   ; test for low
       goto IzLow

       btfss KeyFlag,0
       goto Reset      ; already pressed

       bcf KeyFlag,0   ; flag key is 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
       goto Reset

IzLow   btfsc KeyFlag,0
       goto Reset      ; already released

       bsf KeyFlag,0   ; flag key up
       movlw 10h               ; just pressed
       movwf Debounce
       goto Reset


       end
--
Best regards

Tony

http://www.picnpoke.com
spam_OUTsalesTakeThisOuTspampicnpoke.com

2000\05\30@190317 by Tony Nixon

flavicon
picon face
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
.....salesKILLspamspam@spam@picnpoke.com

More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...