Difference between revisions of "Custom Interrupts - PICmicro"

From Flowcode Help
Jump to navigationJump to search
(Created page with " 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 cod...")
 
 
(30 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
<sidebar>Sidebar: What Is an Interrupt?</sidebar>
 +
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 [[Interrupt Icon Properties|Interrupts]].
  
 
 
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.  
 
'''USART receive''' - This can be nicely integrated with the Flowcode RS232 component.  
Line 10: Line 9:
 
'''Timer1''' rollover - An example of the use of another unsupported, but potentially useful, function.
 
'''Timer1''' rollover - An example of the use of another unsupported, but potentially useful, function.
  
Target PIC Processor ( PIC16F877A )  
+
<span style="color:#FF0000"> '''Target PIC Processor ( PIC16F877A )''' </span>
  
(Note: For other PIC devices you may have to refer to the device datasheet to obtain the correct code)
+
<span style="color:#FF0000"> '''(Note: For other PIC devices you may have to refer to the device datasheet to obtain the correct code)''' </span>
  
  
'''USART receive'''
+
==USART Receive==
  
 +
[[File:Gen_Custom_Interrupts_PICmicro_USART.png|right]]
  
 
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).
 
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).
Line 23: Line 23:
 
'''Enable code:'''
 
'''Enable code:'''
  
intcon.PEIE = 1; // Enable peripheral interrupts
+
<font style="color:#000080"> intcon.PEIE = 1; // Enable peripheral interrupts
  
 
intcon.GIE = 1; // Enable global interrupts
 
intcon.GIE = 1; // Enable global interrupts
  
pie1.RCIE = 1; // Enable USART receive interrupts
+
pie1.RCIE = 1; // Enable USART receive interrupts </font>
  
  
Disable code:
+
'''Disable code:'''
  
pie1.RCIE = 0; // Disable USART receive interrupts
+
<span style="color:#000080"> pie1.RCIE = 0; // Disable USART receive interrupts </span>
  
  
Handler code:
+
'''Handler code:'''
  
if (pir1 & (1 << RCIF))
+
<font style="color:#000080"> if (pir1 & (1 << RCIF)) // Check to see if the interrupt flag is set
  
 
{
 
{
FCM_%n(); // call selected macro
 
  
clear_bit(pir1, RCIF); // clear interrupt
+
FCM_%n(); // Call Flowcode Macro
  
}
+
pir1.RCIF = 0; // Clear interrupt flag
  
 +
} </font>
  
'''<img>'''
 
  
  
'''Analogue comparator'''
+
==Analogue Comparator==
  
Enable code:
+
[[File:Gen_Custom_Interrupts_PICmicro_COMPARE.png|right]]
 +
'''Enable code:'''
  
intcon.PEIE = 1; // Enable peripheral interrupts
+
<font style="color:#000080"> intcon.PEIE = 1; // Enable peripheral interrupts
  
 
intcon.GIE = 1; // Enable global interrupts
 
intcon.GIE = 1; // Enable global interrupts
  
pie1.CCP1IE = 1; // Enable Capture Compare interrupts
+
pie1.CCP1IE = 1; // Enable Capture Compare interrupts </font>
  
  
Disable code:
+
'''Disable code:'''
  
pie1.CCP1IE = 0; // Disable Capture Compare Interrupts
+
<span style="color:#000080"> pie1.CCP1IE = 0; // Disable Capture Compare Interrupts </span>
  
  
Handler code:
+
'''Handler code:'''
  
if (pir1 & (1 << CCP1IF))
+
<font style="color:#000080"> if (pir1 & (1 << CCP1IF)) // Check to see if the interrupt flag is set
  
 
{
 
{
FCM_%n();
 
  
clear_bit(pir1, CCP1IF);
+
FCM_%n(); // Call Flowcode Macro
  
}
+
pir1.CCP1IF= 0; // Clear interrupt flag
 +
 
 +
} </font>
  
  
Line 81: Line 82:
  
  
FCV_COMPSTATE = CCPR1L | ( CCPR1H << 8 );
+
<span style="color:#000080"> FCV_COMPSTATE = ccpr1l | ( ccpr1h << 8 ); </span>
  
 +
{| width="auto"
 +
|<pre>** compstate must be declared as an integer variable **</pre>
 +
|}
  
** compstate must be declared as an integer variable **
+
==Timer1 Rollover==
  
  
'''<img>'''
+
[[File:Gen_Custom_Interrupts_PICmicro_TMR1.png|right]]
 +
'''Enable code:'''
  
 
+
<font style="color:#000080"> t1con = 0x79; // Start timer with Internal clock source, prescaler = 1:8
'''Timer1 rollover'''
 
 
 
 
 
Enable code:
 
 
 
t1con = 0x79; // Start timer with Internal clock source, prescaler = 1:8
 
  
 
intcon.PEIE = 1; // Enable peripheral interrupts
 
intcon.PEIE = 1; // Enable peripheral interrupts
Line 101: Line 100:
 
intcon.GIE = 1; // Enable global interrupts
 
intcon.GIE = 1; // Enable global interrupts
  
pie1.TMR1IE = 1; // Enable Capture Compare interrupts
+
pie1.TMR1IE = 1; // Enable Timer 1 interrupts </font>
  
  
Disable code:
+
'''Disable code:'''
  
pie1.TMR1IE = 0; // Disable Capture Compare interrupts
+
<span style="color:#000080"> pie1.TMR1IE = 0; // Disable Timer 1 interrupts </span>
  
  
Handler code:
+
'''Handler code:'''
  
if (pir1 & (1 << TMR1IF))
+
<font style="color:#000080"> if (pir1 & (1 << TMR1IF)) // Check to see if the interrupt flag is set
  
 
{
 
{
  
FCM_%n();
+
FCM_%n(); // Call Flowcode Macro
  
clear_bit(pir1, TMR1IF);
+
pir1.TMR1IF= 0; // Clear interrupt flag
  
}
+
} </font>
  
  
Line 125: Line 124:
  
  
FCV_CAPTVAL = TMR1L | ( TMR1H << 8 );
+
<span style="color:#000080">FCV_CAPTVAL = tmr1l | ( tmr1h << 8 ); </span>
 
 
 
 
** captval must be declared as an integer variable **
 
  
'''<img>'''
+
{| width="auto"
 +
|<pre>** captval must be declared as an integer variable **</pre>
 +
|}

Latest revision as of 15:18, 21 January 2015

<sidebar>Sidebar: What Is an Interrupt?</sidebar> 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

Gen Custom Interrupts PICmicro USART.png

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)) // Check to see if the interrupt flag is set

{

FCM_%n(); // Call Flowcode Macro

pir1.RCIF = 0; // Clear interrupt flag

}


Analogue Comparator

Gen Custom Interrupts PICmicro COMPARE.png

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)) // Check to see if the interrupt flag is set

{

FCM_%n(); // Call Flowcode Macro

pir1.CCP1IF= 0; // Clear interrupt flag

}


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 **

Timer1 Rollover

Gen Custom Interrupts PICmicro TMR1.png

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 Timer 1 interrupts


Disable code:

pie1.TMR1IE = 0; // Disable Timer 1 interrupts


Handler code:

if (pir1 & (1 << TMR1IF)) // Check to see if the interrupt flag is set

{

FCM_%n(); // Call Flowcode Macro

pir1.TMR1IF= 0; // Clear interrupt flag

}


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 **