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

Interrupt for RB6(pin 27) of 16f913

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



Joined: 06 Mar 2007
Posts: 92
Location: Pune,India

View user's profile Send private message AIM Address Yahoo Messenger

Interrupt for RB6(pin 27) of 16f913
PostPosted: Sat Dec 15, 2007 3:28 am     Reply with quote

Dear Sir,
here i am using 16f913, MPLAB 7.5 Ver. & CCS PCM C Compiler, Version 3.249, 34534.
i want to use IOC only for RB6 pin 27 for this my defined statements are,
Code:
/*********************************/
read_port = input_a(); 
clear_interrupt(INT_RB);
enable_interrupts(INT_RB);

/*************************************/

But i checked header file,Only defined statement is
Quote:
#define INT_RB 0x0B08

So if i want to enable interrupt only for RB6,how should i define ?
Actually To this pin i have connected a push button switch,So if i pressed the switch, the interrupt will follow
IOC isr.In this isr i am clearing all EEPROM LOcations.My defined statements are,
Code:
#int_rb
void ioc_isr(void)
{
int8 read_port,clear_ee;
delay_us(10);
for(clear_ee = 0; clear_ee>=255;clear_ee++)
   write_eeprom(clear_ee,0);
read_port = input_b(); 
}


awaiting for your reply
_________________
Thank You,
With Best Regards,
Deepak.
Ttelmah
Guest







PostPosted: Sat Dec 15, 2007 6:09 am     Reply with quote

First comment. You should tweak your interrupt code a little:
Code:

#int_rb
void ioc_isr(void) {
   int8 read_port,clear_ee;
   //Why delay?. - the code itself takes about 1 second... delay_us(10);
   read_port=input_b();
   if ((read_port & 0b01000000) ==0) {
      for(clear_ee = 0; clear_ee>=255;clear_ee++)
         write_eeprom(clear_ee,0);
   }
   //The problem is that the 'changed' interrupt, will trigger on both edges
   //of the signal on the pin, and also the signal may change several times
   //(bounce). Hence you need to ensure that the code is only called on
   //one edge - I check for the _falling_ edge (assuming you have a
   //pullup, and a switch to ground. Unless you can be _absolutely_ sure
   // the button will be released before the code is complete, you need
   //this extra test.
   read_port=input_b(); //extra read here, will ensure the above does
   //happen, if the button _has_ released.
}

In your main 'setup' code, you don't show the]
'enable_interrupts(GLOBAL)' statement. This too is needed.
Now, on later compilers, the other piece of setup, is available 'pre done', but on your version, you need:

Code:

#byte IOCB=0x96

IOCB=0b01000000; //enable changed interrupt on B6 only
read_port=input_a();
clear_interrupt(INT_RB);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);



Best Wishes
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