Custom Interrupts

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
kirstom14
Posts: 40
Joined: Thu Nov 15, 2007 9:13 am
Contact:

Custom Interrupts

Post 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
tomcat14

User avatar
Steve
Matrix Staff
Posts: 3427
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: Custom Interrupts

Post 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).

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Custom Interrupts

Post 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;

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Custom Interrupts

Post by Benj »

Actually Steve's code looks better, I would go with that.

Post Reply