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

12F675 interrupt on change

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



Joined: 05 Jun 2012
Posts: 2

View user's profile Send private message

12F675 interrupt on change
PostPosted: Tue Jun 05, 2012 8:27 am     Reply with quote

I'm new here and in the CCS community.
I would like to read IR codes using interrupts and would like to read both states of the input pin. Setting the interrupt h_to_l would give only the active states(for inverted communication), but this time includes also the off state. For example, most IC IR receivers are active low so it makes sens to set the interrupt high to low, but after active, follows a break (low to high) that is missed or more precisely, it is included in the total time between the 2 h_to_l.
My question is how can I set the interrupt for a specific pin to be executed on pin change (high to low and low to high)?
Thanks in advance
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Tue Jun 05, 2012 8:54 am     Reply with quote

The GPIO pins on the PIC12F675 have interrupt on change feature.

An interrupt is generated on the next change after a read.

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Tue Jun 05, 2012 9:00 am     Reply with quote

Start by reading the data sheet.
You will find that there is a 'level' interrupt on the EXT pin, which can be set to trigger on either high to low, or low to high _only_, and separately, a 'change' interrupt (just one), which can be set to trigger on changes on any pin. The 'whole' interrupt (set to support changes on any pin), is 'INT_RA', while this enabled to only work on pin A3 (for example), in CCS, is designated INT_RA3. The way you set this up/use this, is slightly dependant on compiler version (get in the habit of posting this, when you ask a question....), but would normally be:
Code:

//Setup and chip config code fuses etc....

#INT_RA
void pins_changed(void) {
   //You get here when the enabled pins change
   int8 changes;
   changes=input_change_a();
   if (bit_test(changes,0)) {
      //Here RA0 has changed
      if (input_PIN_A0)) {
         //here pin has gone high
      }
      else {
         //Here pin has gone low
      }
   }
   if (bit_test(changes,3) {
      //Here RA3 has changed
   }
}

void main(void) {
   int8 dummy;
   //General setup code

   dummy=input_a(); //ensure port is read to clear interrupts that may
   //have triggered during boot
   clear_interrupt(INT_RA);
   enable_interrupts(INT_RA0 | INT_RA3);
   //Unlike every other interrupt type, you can 'OR' these to give
   //multiple pins enabled
   enable_interrupts(GLOBAL);

   do {
       //main code loop
   } while (TRUE);
}


As shown, the 'pins_changed' routine will be called whenever A0, or A3 change level. Then in the routine, I show how to 'parse' which pin(s) have changed, and for pin A0, how to separate the 'high to low' code from the 'low to high'.
The code won't be called if other pins change.

There are three 'versions' of change interrupt, depending on the PIC. Most have a general version, which once enabled applies to a whole set of pins. The second one allows you to select the pins (your PIC), while the third allows you to also specify both a pin, and detect the direction of change as well (a few of the newer NanoWatt PIC's).

Best Wishes
xax



Joined: 05 Jun 2012
Posts: 2

View user's profile Send private message

PostPosted: Wed Jun 13, 2012 3:18 am     Reply with quote

Thank you both for your replies and help.
I will give this a try as soon as the time allows me.
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