Jump to content
Sign in to follow this  
drumanart

Timer0 Expression

Recommended Posts

Hello folks.

 

The expression "while ((!tmr0if) || (rcif == 0));" never is true, why? The idea is that, if no data is received from USART the timer overflow flag TMR0IF is set (INTCON,2) and the program continuous.

 

 

 

The extraxt of the code is:

 

 

 

volatile bit tmr0if@INTCON.2; // Timer0 overflow.

 

volatile bit tmr0on@T0CON.7; // Timer0 enable bit.

 

 

 

t0con = 00010011b; // disable timer, 16 bit, Prescaler 1/16.

 

tmr0on = 1; // enable (starts) timer0.

 

 

 

while ((!tmr0if) || (rcif == 0)); // for 8Mhz the delay is aprox. 0.5s.

 

set_bit (portc,3); // LED on.

 

tmr0on = 0; // (stops) timer0.

Share this post


Link to post
Share on other sites
Hello folks.

 

The expression "while ((!tmr0if) || (rcif == 0));" never is true, why? The idea is that, if no data is received from USART the timer overflow flag TMR0IF is set (INTCON,2) and the program continuous.

 

 

 

The extraxt of the code is:

 

 

 

volatile bit tmr0if@INTCON.2; // Timer0 overflow.

 

volatile bit tmr0on@T0CON.7; // Timer0 enable bit.

 

 

 

t0con = 00010011b; // disable timer, 16 bit, Prescaler 1/16.

 

tmr0on = 1; // enable (starts) timer0.

 

 

 

while ((!tmr0if) || (rcif == 0)); // for 8Mhz the delay is aprox. 0.5s.

 

set_bit (portc,3); // LED on.

 

tmr0on = 0; // (stops) timer0.

 

After a quick glance I don't see a definition for rcif e.g. volatile bit rcif@PIR1.RCIF; or is this somewhere else?

Alternatively use something like !(test_bit(intcon,TMR0IF)) and !(test_bit(pir1,RCIF)) instead of individually mapping bits.

 

rcreg also needs to be read somewhere to ensure that the receive data interrupt flag is cleared.

 

Also how about initialising timer0 and clearing the interrupt flag tmr0if before starting the timer so you know the initial conditions?

 

Regards

 

davidb

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...