Page 1 of 1

Custom Interrupts

Posted: Tue Jul 22, 2008 4:19 pm
by kirstom14
Can you help with with a custom interrupt for an RS-232 communication for the 16F877A and for the 18F452?
Thanks in advance

Re: Custom Interrupts

Posted: Tue Jul 22, 2008 4:39 pm
by Steve
This is from the Flowcode help file:
Target PIC Processors ( PIC16F88 )
(Note: For other PICmicro devices you may have to refer to the device datasheet to obtain the correct code)

USART receive

The Flowcode RS232 component can be used to set the Baud rate and configure the mode of operation, and the ReceiveRS232Char function can be used in the handler macro to read the data (clearing the interrupt).

Enable code:

Code: Select all

intcon.PEIE = 1; // Enable peripheral interrupts
intcon.GIE = 1; // Enable global interrupts
pie1.RCIE = 1; // Enable USART receive interrupts
Disable code:

Code: Select all

pie1.RCIE = 0; // Disable USART receive interrupts
Handler code:

Code: Select all

if (pir1 & (1 << RCIF))
{
  FCM_%n(); // call selected macro
  clear_bit(pir1, RCIF); // clear interrupt
}
Note that the "clear_bit(pir1, RCIF); // clear interrupt" line is not needed as this bit cannot be cleared in software. Instead, you must ensure that you read the incoming RS232 character within your interrupt macro using the "ReceiveRS232Char" macro call (or by directly reading the value using C code).

Re: Custom Interrupts

Posted: Tue Jul 22, 2008 4:45 pm
by Benj
Hello

This should work for both the 877A and the 452, however I have not tested it.

Enable Code
pie1.RCIE = 1;
intcon.PEIE = 1;

Disable Code
pie1.RCIE = 0;

Handler Code
pir1.RCIF = 0;

Re: Custom Interrupts

Posted: Tue Jul 22, 2008 4:46 pm
by Benj
Actually Steve's code looks better, I would go with that.