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 CCS Technical Support

require a code snippet for use of the interrupt on change.

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



Joined: 29 Feb 2008
Posts: 1

View user's profile Send private message

require a code snippet for use of the interrupt on change.
PostPosted: Mon Mar 03, 2008 10:19 am     Reply with quote

Hi ppl,
i am a newbie for this forum.. i am a b.tech student... i need the code snippet for using the interrupt on change feature in pic 16f877a... please do help me...
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Mon Mar 03, 2008 10:55 am     Reply with quote

Here is an extract from a shared interrupt handler. The handler is used for interrupt driven software UART. A Timer 3 is used for receive bit timing. IOC is used for start bit detection (INT0 to INT3 would have been beter for this task but were not available on the target hardware platform).

IOC is enabled when the serial interface is waiting for the next character. When an IOC condition occurs, the interrupt source is check to determine it is an IOC event (required because this is a shared handler) and the Rx pin is sampled to see if it is a valid start bit condition. It then enables the serial receive bit timer and disabled the IOC interrrupt.

Code:

   // perform start bit detection   
   // Is this an interrupt on change interrupt?
   if ((INTCON & 0x09) == 0x09)
      {
      // Handle Interrupt on change
      // Only gets here if waiting for a start bit
      if (!bit_test(SWU_Rx))
         {
         // start bit condition
         // load the bit timer and initialise state
         // bit_clear(T3CON, TMR3ON);         // turn off the rx bit timer (already off)
         IH_data_mask = ~(SWU_TmrCnt + (SWU_TmrCnt >> 1) - 87);
         TMR3H = IH_mask;
         TMR3L = IH_data;
         bit_set(T3CON, TMR3ON);            // turn on the bit timer
         clear_interrupt(INT_TIMER3);
         enable_interrupts(INT_TIMER3);
         SWU_RxBCnt = SWU_BITCOUNT;
         disable_interrupts(INT_RB);
         }
      clear_interrupt(INT_RB);
      }

_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Mon Mar 03, 2008 12:04 pm     Reply with quote

Some PIC's specifically here a 12F683 have interrupt on change but allow a specific pin to be chosen via masking of the other pins.
Here the pins are RA and a specific pin RA3 is chosen.
There are difference between PIC'swith respect to interrupt on change.
Some use portB (#int_RB) some allow specific pins to be selected.
Never forget to look up the specifications of you PIC before coding.
Now interrupts occur while your code in main is executing. The CCS compilers ISR handler behind the scenes saves your main code status then gives your isr code a chance to execute and then again behind the scenes restores all that is needed to get your main code back to executing as if the interrupt had not occurred. Communication from the your isr has to be done via global variables no calling parameters can be passed to an isr . It must always have the form
my_isr(); and always be preceded with #INT_XX where XX is the specific interrupt you want your isr to react to.

Code:

///////////////////////////////////////ISR /////////////////////////////////
#int_RA
onchange_isr()
{

/// your code goes here

}

main()
{
enable_interrupts(INT_RA3);
enable_interrupts(GLOBAL);
/// more of your code goes here
while(1);
}
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