gnupic: pulse counting using timer1
Subject:
pulse counting using timer1
From:
Phil ####@####.####
Date:
2 Apr 2004 07:18:48 +0100
Message-Id: <200404021615.50560.phil@spiderweb.com.au>
Hello everyone,
Thank you for reading this and forgive me if this isn't an appropriate
question for this list.
I'm attempting to count pulses using a 16F876A PIC and timer1. The way I
understand timer1's use is that a rising edge on port C0 causes TMR1L to
increment and overflow into TMR1H. So far that doesn't happen and I suspect
that there is more to it than just setting a few bits in the
T1CON register.
This is my initialisation code:
clrf PORTB ; Initialise Port B
clrw ; Clear W register
bsf STATUS,RP0 ; Select Register Bank 1
movwf TRISB ; Set port B to all outputs
movlw b'00000001'
movwf TRISA ; Port A0 input the rest outputs
movlw b'00000011'
movwf TRISC ; Port C0 & C1 inputs the rest outputs
bsf T1CON,0 ; Enable timer1
bsf T1CON,1 ; External clock input from C0
bsf T1CON,2 ; Don't sync external clock input
movlw 0x06
movwf ADCON1 ; Set port A to digital i/o
bcf STATUS,RP0 ; select Register Bank 0
The remainder of the code reads TMR1L and TMR1H (I took this from the
Microchip's docs) and then displays the result on a LCD display. The counter
registers are always 0 and the display code actually works.
Is there more to it? Should double clicking port C0 from within gpsim
increment the counter? Are there other registers that I have to deal with?
I have searched for example code without success and this is my first PIC
project so go easy on the flames.
--
Regards,
Phil.