Difference between revisions of "Custom Interrupts - PICmicro"

From Flowcode Help
Jump to navigationJump to search
Line 23: Line 23:
 
'''Enable code:'''
 
'''Enable code:'''
  
<span style="color:#000080"> intcon.PEIE = 1; // Enable peripheral interrupts </span>
+
<font style="color:#000080"> intcon.PEIE = 1; // Enable peripheral interrupts
  
<span style="color:#000080"> intcon.GIE = 1; // Enable global interrupts </span>
+
intcon.GIE = 1; // Enable global interrupts
  
<span style="color:#000080"> pie1.RCIE = 1; // Enable USART receive interrupts </span>
+
pie1.RCIE = 1; // Enable USART receive interrupts </font>
  
  
Line 37: Line 37:
 
Handler code:
 
Handler code:
  
<span style="color:#000080"> if (pir1 & (1 << RCIF)) </span>
+
<font style="color:#000080"> if (pir1 & (1 << RCIF))
  
<span style="color:#000080"> { </span>
+
<span style="color:#000080"> {
  
<span style="color:#000080"> FCM_%n(); // call selected macro </span>
+
<span style="color:#000080"> FCM_%n(); // call selected macro
  
<span style="color:#000080"> clear_bit(pir1, RCIF); // clear interrupt </span>
+
<span style="color:#000080"> clear_bit(pir1, RCIF); // clear interrupt
  
<span style="color:#000080"> } </span>
+
<span style="color:#000080"> } </font>
  
  
Line 56: Line 56:
 
Enable code:
 
Enable code:
  
<span style="color:#000080"> intcon.PEIE = 1; // Enable peripheral interrupts </span>
+
<font style="color:#000080"> intcon.PEIE = 1; // Enable peripheral interrupts
  
<span style="color:#000080"> intcon.GIE = 1; // Enable global interrupts </span>
+
intcon.GIE = 1; // Enable global interrupts
  
<span style="color:#000080"> pie1.CCP1IE = 1; // Enable Capture Compare interrupts </span>
+
pie1.CCP1IE = 1; // Enable Capture Compare interrupts </font>
  
  
Line 70: Line 70:
 
Handler code:
 
Handler code:
  
<span style="color:#000080"> if (pir1 & (1 << CCP1IF)) </span>
+
<font style="color:#000080"> if (pir1 & (1 << CCP1IF))
  
<span style="color:#000080"> { </span>
+
{
  
<span style="color:#000080"> FCM_%n(); </span>
+
FCM_%n();
  
<span style="color:#000080"> clear_bit(pir1, CCP1IF); </span>
+
clear_bit(pir1, CCP1IF);
  
<span style="color:#000080"> } </span>
+
} </span>
  
  

Revision as of 10:06, 16 May 2013


Here are a few examples for such interrupts using PICmicro chips. To create interrupts that are not shown below you will have to refer to the device datasheet. Once the code has been placed into the custom interrupt properties dialog, the interrupt can be enabled and disabled like any of the standard Flowcode Interrupts.

USART receive - This can be nicely integrated with the Flowcode RS232 component.

Comparator - Example of the use of a function not supported by Flowcode.

Timer1 rollover - An example of the use of another unsupported, but potentially useful, function.

Target PIC Processor ( PIC16F877A )

(Note: For other PIC 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:

intcon.PEIE = 1; // Enable peripheral interrupts

intcon.GIE = 1; // Enable global interrupts

pie1.RCIE = 1; // Enable USART receive interrupts


Disable code:

pie1.RCIE = 0; // Disable USART receive interrupts


Handler code:

if (pir1 & (1 << RCIF))

{

FCM_%n(); // call selected macro

clear_bit(pir1, RCIF); // clear interrupt

}


<img>


Analogue comparator


Enable code:

intcon.PEIE = 1; // Enable peripheral interrupts

intcon.GIE = 1; // Enable global interrupts

pie1.CCP1IE = 1; // Enable Capture Compare interrupts


Disable code:

pie1.CCP1IE = 0; // Disable Capture Compare Interrupts


Handler code:

if (pir1 & (1 << CCP1IF))

{

FCM_%n();

clear_bit(pir1, CCP1IF);

}


The state of the comparator input can be read into a Flowcode variable 'compstate' with the following C code line:


FCV_COMPSTATE = CCPR1L | ( CCPR1H << 8 );


** compstate must be declared as an integer variable ** 


<img>


Timer1 rollover


Enable code:

t1con = 0x79; // Start timer with Internal clock source, prescaler = 1:8

intcon.PEIE = 1; // Enable peripheral interrupts

intcon.GIE = 1; // Enable global interrupts

pie1.TMR1IE = 1; // Enable Capture Compare interrupts


Disable code:

pie1.TMR1IE = 0; // Disable Capture Compare interrupts


Handler code:

if (pir1 & (1 << TMR1IF))

{

FCM_%n();

clear_bit(pir1, TMR1IF);

}


The captured 16-bit count value can be read into a Flowcode variable 'captval' with the following C code line:


FCV_CAPTVAL = TMR1L | ( TMR1H << 8 );


** captval must be declared as an integer variable ** 

<img>