hi everyone,
I am new with the Timer modules on the PIC and I have just implemented using 876A with a 4MHz crystal a code which counts up to 60 seconds and then lights and LED on PORTB,0.
Using Timer1, TMR1L and TMR1H combines to overflow when reaching 0xFFFF. Therefore, to get up to a count of 1 second, (using a prescaler of 1:8) I'm adding an outer loop counter (which after calculations) is set as d'114'.
In short, Timer 1 overflows 114 times to equal to 1 minute (60secs)
The code I've done works and is as follows:
Apart from the mini question I inserted in the code excerpt, I now would like to be able to add a feature whereby I press a button within this 1 minute interval and from there, read the current time passed at the instant of which the button is pressed. Say I press a button and the program reads the Timer and tells me that X seconds have passed, I would then like to update this value in hex to an entire Port. After 60 seconds, the program will just stop and wait for reset.
Is what I'm trying to achieve suitable for implementation using the Timer module? I actually intend to do a 30 minute timer and with the push of a button, get an update on how much time has passed in minute resolution. If it is possible to use Timer 1, could anyone give me a rough idea of how I can set out to achieve this? thanks=)
I am new with the Timer modules on the PIC and I have just implemented using 876A with a 4MHz crystal a code which counts up to 60 seconds and then lights and LED on PORTB,0.
Using Timer1, TMR1L and TMR1H combines to overflow when reaching 0xFFFF. Therefore, to get up to a count of 1 second, (using a prescaler of 1:8) I'm adding an outer loop counter (which after calculations) is set as d'114'.
In short, Timer 1 overflows 114 times to equal to 1 minute (60secs)
The code I've done works and is as follows:
Code:
org 0x00
BANK1
movlw 0x00
movwf PORTA
movlw b'10000000'
movwf TRISB
bsf PIE1,0
BANK0
clrf PORTB
movlw d'114'
movwf timer_count
settime movlw b'00110000'
movwf T1CON
; movlw 0xFF apparently I don't have to insert these 4 lines
; movwf TMR1L of code. Without it, the Timer automatically
; movlw 0xFF counts up to 0xFFFF. If I do insert this 4 lines,
; movwf TMR1H the Timer does not work as intended and the LED
;lights up upon power on. Any one know why?
bsf T1CON,0
wait btfss PIR1,0
goto wait
bcf T1CON,0
bcf PIR1,0
decfsz timer_count,f
goto settime
bsf PORTB,0
goto $+0
end
Apart from the mini question I inserted in the code excerpt, I now would like to be able to add a feature whereby I press a button within this 1 minute interval and from there, read the current time passed at the instant of which the button is pressed. Say I press a button and the program reads the Timer and tells me that X seconds have passed, I would then like to update this value in hex to an entire Port. After 60 seconds, the program will just stop and wait for reset.
Is what I'm trying to achieve suitable for implementation using the Timer module? I actually intend to do a 30 minute timer and with the push of a button, get an update on how much time has passed in minute resolution. If it is possible to use Timer 1, could anyone give me a rough idea of how I can set out to achieve this? thanks=)