View previous topic :: View next topic |
Author |
Message |
Nick Guest
|
my interrupt code and question |
Posted: Tue Aug 03, 2004 10:48 am |
|
|
I want to put an interrupt on a single pin, the example that comes with CCS does it on an entire RB port with #int_rb.
How do I put an interrupt just on say PIN_RB3?
here is the code I have so far
Code: |
#include <16F876.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#int_rb
void detect_rb_change()
{
printf("wake up");
}
void main() {
enable_interrupts(INT_RB3);
enable_interrupts(GLOBAL);
output_low(PIN_B0);
while (TRUE) {
sleep();
}
}
|
What I'm trying to do is sleep until pin rb3 is set to +5 then say 'wake' and finally go back to sleep again. very simple right? its doable I hope.
Nick |
|
|
Guest
|
|
Posted: Tue Aug 03, 2004 10:55 am |
|
|
PICs aren't Zilog processors. They have limited interrupt capabilities.
You didn't tell what PIC you use. Check out the manual to find out your possibilities (e.g. 16F series have only 1 Ext IT 18F452 (RB0) has 2 (RB0 and RB1) 18F6720 has 4 (pin_b0-3) etc.) |
|
|
Nick Guest
|
|
Posted: Tue Aug 03, 2004 1:36 pm |
|
|
I c, I looked at the datasheet and it shows RB0/INT I assume that is an interput.
#int_rb does that point to pin rb0?
Many Thanks! |
|
|
Nick Guest
|
|
Posted: Tue Aug 03, 2004 1:40 pm |
|
|
I did a google search and it pulled up '#INT_EXT'
Thanks! |
|
|
Nick Guest
|
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Tue Aug 03, 2004 2:09 pm |
|
|
For the 16F876 you have three interrupts available for your use. RB0/INT, which is PortB bit 0 (pin 21 on a DIP package), Timer0 and Input Change on PortB bits 7 - 4. This is what is generated when using the Project Wizard if you want to use RB0 as the interrupt:
Quote: |
Inserted into .c file before main():
#int_EXT
EXT_isr()
{
}
Inserted into .c file in main():
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
|
The '#int_RB' is used on the PortB 4 - 7 'interrupt on change' interrupt.
Ronald |
|
|
|