Hi Vasile,

I don't know what the intention of your code is. It looks like you
setup timer1 to run continues without actual interrupts. However when
you enter your procedure, you enable interrupts. If there are
interrupts pending (depending on how and when you call your procedure
- to bad you did not include a working copy of your code ;) there will
be an interrupt at that point. The code that handles that interrupt is
not supplied.

I also noticed you don't handle PIR1_tmr1if in case there is no button
pressed. Is this by design? And also, timer1 is mostly off - it is set
on at the start of you procedure and turned off within a condition or
end of the procedure. A few lines of comment that describe (at a
higher level) what the intention of the code is, would be helpfull.
(Personaly, I write too little comment at the first pass, which makes
me figure out what happens at some point. At that time, I mosty add
some comment - which is too late of course.)

Joep

ps For readability, please choose the most appropriate style of
assigning a particular bit and use it throughout the program. This is
a bit confusing and would be better if you used on/off only:
INTCON_GIE = 0            -- disable all interrupts
intcon_GIE = on ; enable interrupts
intcon_GIE = low ; disable interrupts



2010/5/16 vasile surducan <[email protected]>:
> 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.
>

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

Reply via email to