View previous topic :: View next topic |
Author |
Message |
balaji
Joined: 30 Mar 2010 Posts: 21
|
interrupt problem in 16F877A |
Posted: Tue May 04, 2010 1:05 am |
|
|
Hai All,
I am using 16F877A in my project. I use UART, LCD and timer1.
If I enable timer1 then the main program doesn't work. If I disable
global interrupt then the main program works but timer1 doesn't work.
How to handle this ?
My interrupt code: it pops for every 500uSec.
Code: |
#int_timer2
void clock_isr()
{
reader_count--;
if(reader_count == 0)
{
reader_count = 40;
output_toggle(pin_C2);
}
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Tue May 04, 2010 2:40 am |
|
|
You don't show the interrupt, and timer setups, but the obvious comment is 'which timer are you using'. You show a handler for timer2, but talk about enabling timer1. If you enable an interrupt without a handler, the code _will_ fail.
Best Wishes |
|
|
balaji
Joined: 30 Mar 2010 Posts: 21
|
timer1 code |
Posted: Tue May 04, 2010 3:55 am |
|
|
Now i identified the problem like this. when i use timer1 and ADC, timer1 works.(interupt at 500mS) whereas main loop and UART doesn`t work. my crystal frequency is 4MHz. Increasing the crystal to 12MHz shall solve the problem???
My timer1 code:
#int_timer1
void clock_isr()
{
disable_interrupts(int_timer1);
output_toggle(pin_C2);
enable_interrupts(int_timer1);
} |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Tue May 04, 2010 4:55 am |
|
|
You need to post the other code, as I said before. Generate the smallest program that initialises the chip, and shows the problem. You may well find that doing show tells you what is wrong.
There is nothing 'wrong' with the interrupt code as posted (though you don't need to disable and enable the interrupts, the hardware does this automatically for you), _but_ the most likely problem is that your timer interval is so short that the processor is never getting out of the interrupt.
We can't tell, without seeing the timer setup code.
Best Wishes |
|
|
|