It's quiet here these days...
I have a strange problem with TMR1 reading some buttons. Please take a look
on the code below, do you see something wrong? It seems the PIR1_tmr1 is
never set.
thx,
Vasile
-------------------------------------------------------
-- TMR1 settings, used for buton_read procedure
-------------------------------------------------------
var volatile bit T1CON_T1CKPS0 at T1CON_T1CKPS :0
var volatile bit T1CON_T1CKPS1 at T1CON_T1CKPS :1
var byte tmr1l_l = 0
var byte tmr1h_l = 127
-- initialize timer1 for button delay generation
-- t = TMR1*prescaler*Tcy; prescaler = 1 (2 or 4 or 8)
tcy=1/14745600/4=0.27uS
-- t = (256*127+255)*8*0.27uS = 70mS
T1CON_TMR1CS = 0 -- tmr1 in timer mode,internal osc/4
T1CON_T1CKPS0 = 1
T1CON_T1CKPS1 = 1 -- prescaler 1:8
T1CON_T1OSCEN = 0 -- stop external osc
T1CON_TMR1GE = 0 -- TMR1 always counting
T1CON_TMR1ON = 0 -- tmr1 is off
INTCON_GIE = 0 -- disable all interrupts
PIE1_TMR1IE = 0 -- disable tmr1 overflow interrupt
tmr1l = tmr1l_l
tmr1h = tmr1h_l -- overflow period
T1CON_TMR1ON = off -- tmr1 is off
------------------------------------------------------
--------------------------------------
-- buttons
--------------------------------------
var volatile bit button1 is pin_B5
var volatile bit button1_direction is pin_B5_direction
var volatile bit button2 is pin_B4
var volatile bit button2_direction is pin_B4_direction
var volatile bit button3 is pin_B2
var volatile bit button3_direction is pin_B2_direction
procedure read_button is
intcon_GIE = on ; enable interrupts
PIE1_tmr1ie = on
T1CON_tmr1on = on
button1_direction = input
button2_direction = input
button3_direction = input
if (! button1) & PIR1_tmr1if then
button1 = on
PIR1_tmr1if = low
T1CON_tmr1on = off
tmr1l = tmr1l_l
tmr1h = tmr1h_l
end if
if (! button2) & PIR1_tmr1if then
button2 = on
PIR1_tmr1if = low
T1CON_tmr1on = off
tmr1l = tmr1l_l
tmr1h = tmr1h_l
end if
if (! button3) & PIR1_tmr1if then
button3 = on
PIR1_tmr1if = low
T1CON_tmr1on = off
tmr1l = tmr1l_l
tmr1h = tmr1h_l
end if
intcon_GIE = low ; disable interrupts
PIE1_tmr1ie = low
T1CON_tmr1on = low
button1_direction = output
button2_direction = output
button3_direction = output
end procedure
--------------------------------------------
--
You received this message because you are subscribed to the Google Groups
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/jallib?hl=en.