View previous topic :: View next topic |
Author |
Message |
aeroboy
Joined: 26 Apr 2009 Posts: 9
|
External Interrupt in a pin different from RB0 |
Posted: Sun Apr 26, 2009 10:35 pm |
|
|
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
|
|
Posted: Mon Apr 27, 2009 12:18 am |
|
|
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
|
|
Posted: Mon Apr 27, 2009 12:08 pm |
|
|
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
|
|
Posted: Mon Apr 27, 2009 12:24 pm |
|
|
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
|
|
Posted: Mon Apr 27, 2009 1:10 pm |
|
|
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:
--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
|
|
Posted: Mon Apr 27, 2009 1:24 pm |
|
|
Yes, that's correct.
You can also clear the entire structure (all bits) like this:
|
|
|
aeroboy
Joined: 26 Apr 2009 Posts: 9
|
|
Posted: Mon Apr 27, 2009 1:44 pm |
|
|
Thanks a lot, that's very useful.
--Luis |
|
|
|