CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC 16C771 interrupt

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
collison
Guest







PIC 16C771 interrupt
PostPosted: Tue Oct 25, 2005 2:00 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Oct 25, 2005 2:32 pm     Reply with quote

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
PostPosted: Tue Oct 25, 2005 2:43 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Oct 25, 2005 2:57 pm     Reply with quote

Most people would use #INT_EXT (on Pin B0 for the UART Receive pin)
for a hardware interrupt with a software UART.
Ttelmah
Guest







PostPosted: Tue Oct 25, 2005 3:02 pm     Reply with quote

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...
PostPosted: Wed Oct 26, 2005 1:57 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Oct 26, 2005 4:20 pm     Reply with quote

Quote:
How would you go about clearing the interrupt ?
http://www.ccsinfo.com/forum/viewtopic.php?t=17080&highlight=intrb
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group