View previous topic :: View next topic |
Author |
Message |
collison Guest
|
PIC 16C771 interrupt |
Posted: Tue Oct 25, 2005 2:00 pm |
|
|
I am having trouble using an interrupt with this chip. It does not have a UART, so an interrupt is what I am using. When the enable interrupts line is executed, it goes straight to the interrupt function even though a character has not been sent to it yet. The interrupts are then disabled and the code hangs at the getch() line. Any ideas on why the code sits here and waits for a character instead of going here only when a character is received??? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Oct 25, 2005 2:32 pm |
|
|
Post a very small program that demonstrates the problem. Show all
#include, #fuses, and #use statements. Also post your compiler
version. This will be a number like 3.191, or 3.235, etc. You can find
it at the top of the .LST file which is in your project folder. |
|
|
collison Guest
|
version and code |
Posted: Tue Oct 25, 2005 2:43 pm |
|
|
The version that I am running is V 3.148. Here is some code:
#include <16C771.h>
#use delay (Clock=4000000)
#fuses HS,NOWDT,NOPROTECT
SET_TRIS_B(0x80);
#USE RS232(BAUD=19200, XMIT=PIN_B6, RCV=PIN_B7, STREAM=USB)
#INT_RB
void serial_isr()
{
keypress=0;
disable_interrupts(INT_RB);
disable_interrupts(global);
keypress=getch();
newchar_flag=1;
}
void init_hardware()
{
enable_interrupts(INT_RB);
enable_interrupts(global);
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(sAN0);
setup_adc_ports(sAN1);
}
When the program starts up, the init_hardware() is executed. When the enable interrupts are executed, it automatically goes to the #INT_RB, disables the interrupts and hangs at the getch() line without a character being sent to it. Any ideas of why this hangs here instead of executing the rest of the program? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Oct 25, 2005 2:57 pm |
|
|
Most people would use #INT_EXT (on Pin B0 for the UART Receive pin)
for a hardware interrupt with a software UART. |
|
|
Ttelmah Guest
|
|
Posted: Tue Oct 25, 2005 3:02 pm |
|
|
First, before enabling interrupts, always 'clear' the interrupt, otherwise if the condition to trigger it has existed at any time in the past since the chip powered up, the flag will already be set, and you will get an immediate interrupt.
You also need to set which edge you want the interrupt to occur on. Presumably 'high to low'. This is settable by the 'ext_int_edge' function, and the default in this register from 'power up' is for interrupts on low to high. Arriving in the handler routine on the wrong edge, will result in the getc hanging, since a start bit has not arrived.
Do change the interrupt direction, then clear the interrupt flag, then enable the interrupts, and see what happens.
Best Wishes |
|
|
collison Guest
|
how... |
Posted: Wed Oct 26, 2005 1:57 pm |
|
|
How would you go about clearing the interrupt. I have tried a few different commands and still having no luck........ |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Oct 26, 2005 4:20 pm |
|
|
Quote: | How would you go about clearing the interrupt ? | http://www.ccsinfo.com/forum/viewtopic.php?t=17080&highlight=intrb |
|
|
|