View previous topic :: View next topic |
Author |
Message |
Jasen
Joined: 31 Aug 2009 Posts: 6
|
interrupt int_rda not working |
Posted: Sat Mar 23, 2013 2:23 pm |
|
|
I create a simply program to test rda interrupt, but for some reason the interrupt is not working. When send a TX data expect a message back “Interrupt in execution”, but no message is send back. Look at the program below.
Code: |
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#int_rda
void serial_isr(){
printf("interrupt in execution");
getc();
}
Main{
Enable_interrupt (Global);
Enable_interrupt (int_rda);}
When(true){
}
|
|
|
|
jayanthd
Joined: 06 Dec 2012 Posts: 47 Location: Banned - pirate
|
Re: interrupt int_rda not working |
Posted: Sat Mar 23, 2013 3:15 pm |
|
|
How are you sending data to UART? Only if you send some data like say 'A' serial interrupt occurs and printf is executed. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sat Mar 23, 2013 3:23 pm |
|
|
Several things:-
1) Can you get an LED flasher to work?
2) Add errors to your #use RS232.
3) Where does your code go after the enable rda interrrupt?
4) Does your code ever reach the when statement?
5) Is "when" a valid 'C' word?
6) Have you carefully examined your {} brackets?
7) Does your code compile without errors?
8) Printing inside an ISR is a VERY bad idea.
9) Is this real or simulation?
10) .......................
Mike |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Sun Mar 24, 2013 1:34 am |
|
|
Keyword for a loop is 'while', not 'when'....
So code as posted will not compile. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sun Mar 24, 2013 4:25 am |
|
|
There several reasons why your code won't compile.
My advice on {} brackets (for what it's worth).
Always locate each closing } directly below its opening { with clear space between.
That way you can more easily see your code structure.
Your code now becomes:- Code: | #include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#int_rda
void serial_isr()
{
printf("interrupt in execution");
getc();
}
Main
{
Enable_interrupt (Global);
Enable_interrupt (int_rda);
}
When(true)
{
}
|
It should now be obvious what's wrong with the structure.
I've not altered the sense of your code.
The only editing I've done is to manipulate white space and linefeeds.
It still won't either compile or work for the reasons that were there before.
The compiler complains about things it can't handle, and effectively tells you where to look for errors.
Mike |
|
|
|