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 support@ccsinfo.com

External Interrupt in a pin different from RB0

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



Joined: 26 Apr 2009
Posts: 9

View user's profile Send private message

External Interrupt in a pin different from RB0
PostPosted: Sun Apr 26, 2009 10:35 pm     Reply with quote

Hello,

I am using a 16f877A, when you use an external interrupt you write:

#int_ext
External_Interrupt(){}

Now, that is for PORTB pin RB0, it is possible to define an external interrupt for any pin in PORTB - pins RB1 to RB7?

Thanks.
--Luis
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 27, 2009 12:18 am     Reply with quote

Pins B4-B7 can be used. See this CCS example:
Quote:
c:\program files\picc\examples\ex_pbutt.c


There are other ways to get another individual external interrupt pin.
One of the most well-known ways is to configure Timer1 for an external
clock. Then load Timer1 with 0xFFFF. When it get the first clock edge, it
will roll over to 0x0000 and generate a Timer1 interrupt. You can detect
an edge this way.

You also have the Comparator interrupt.

There might be other possibilities.
aeroboy



Joined: 26 Apr 2009
Posts: 9

View user's profile Send private message

PostPosted: Mon Apr 27, 2009 12:08 pm     Reply with quote

Thanks,

Now I have another question, you can define a variable to use like:

unsigned char VALUE;

Can I access the individual bits in this variable?, something like

PIN_VALUE1

Obviously this is not a PIN but maybe there is a way to access the bits.

--Luis
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 27, 2009 12:24 pm     Reply with quote

If you want a structure of bit variables (int1), see Mark's example:
http://www.ccsinfo.com/forum/viewtopic.php?t=20186
His example allows you to access individual bits in hardware registers.
That's why he uses the #locate directive after each structure.
If you just want to create a structure of bits in a normal variable, then
you don't need the #locate directive.
aeroboy



Joined: 26 Apr 2009
Posts: 9

View user's profile Send private message

PostPosted: Mon Apr 27, 2009 1:10 pm     Reply with quote

Thanks,

You mean I have to do this:
Code:
struct {
    unsigned char V0:1;
    unsigned char V1:1;
    unsigned char V2:1;
    unsigned char V3:1;
    unsigned char V4:1;
    unsigned char V5:1;
    unsigned char V6:1;
    unsigned char V7:1;
} VALUE;

But then to access them I just do something like:
Code:
VALUE.Vx=0; or 1

--Luis


Last edited by aeroboy on Mon Apr 27, 2009 1:45 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 27, 2009 1:24 pm     Reply with quote

Yes, that's correct.

You can also clear the entire structure (all bits) like this:
Code:
value = 0;
aeroboy



Joined: 26 Apr 2009
Posts: 9

View user's profile Send private message

PostPosted: Mon Apr 27, 2009 1:44 pm     Reply with quote

Thanks a lot, that's very useful.

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