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



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
spamsalesspampicnpoke.com

<39336880.5E269458@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...