![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
dbrown
Joined: 24 Jul 2004 Posts: 20
|
PIC16F873A and int_rda |
Posted: Sat Jul 24, 2004 2:32 pm |
|
|
I have been trying to detect an input on the RS232 port of the pic, and turn on an led. I use Visual basic to send the string "*R" to the port. The signal is at pin a5(recieve pin) but no change in led state. I have tried using #int_rda with no success, however when I use #int_ext that does work with an input on pin B0. I have posted both the working #int_ext code, and the non-working #int_rda code. Any suggestions would be appreciated.
Working code below:
Code: | #include <16F873A.h>
#use delay (clock=4000000)
#fuses XT,NOWDT,NOPROTECT,nolvp
#USE RS232(BAUD=9600, XMIT=PIN_a4, RCV=PIN_a5,errors)
INT T;
#INT_EXT
ISR(){
OUTPUT_HIGH(PIN_B5);
}
main(){
enable_interrupts(GLOBAL);
enable_interrupts(INT_EXT);
OUTPUT_LOW(PIN_B5);
} |
Non-working code below:
Code: | ]#use delay (clock=4000000)
#fuses XT,NOWDT,NOPROTECT,nolvp
#USE RS232(BAUD=9600, XMIT=PIN_a4, RCV=PIN_a5,errors)
INT T;
#INT_RDA
ISR(){
OUTPUT_HIGH(PIN_B5);
}
main(){
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
OUTPUT_LOW(PIN_B5);
} |
Thanks
Dave B |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
Re: PIC16F873A and int_rda |
Posted: Sat Jul 24, 2004 2:52 pm |
|
|
dbrown wrote: | I have been trying to detect an input on the RS232 port of the pic, and turn on an led. I use Visual basic to send the string "*R" to the port. The signal is at pin a5(recieve pin) but no change in led state. I have tried using #int_rda with no success, however when I use #int_ext that does work with an input on pin B0. I have posted both the working #int_ext code, and the non-working #int_rda code. Any suggestions would be appreciated.
Working code below:
Code: | #include <16F873A.h>
#use delay (clock=4000000)
#fuses XT,NOWDT,NOPROTECT,nolvp
#USE RS232(BAUD=9600, XMIT=PIN_a4, RCV=PIN_a5,errors)
INT T;
#INT_EXT
ISR(){
OUTPUT_HIGH(PIN_B5);
}
main(){
enable_interrupts(GLOBAL);
enable_interrupts(INT_EXT);
OUTPUT_LOW(PIN_B5);
} |
Non-working code below:
Code: | ]#use delay (clock=4000000)
#fuses XT,NOWDT,NOPROTECT,nolvp
#USE RS232(BAUD=9600, XMIT=PIN_a4, RCV=PIN_a5,errors)
INT T;
#INT_RDA
ISR(){
OUTPUT_HIGH(PIN_B5);
}
main(){
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
OUTPUT_LOW(PIN_B5);
} |
Thanks
Dave B |
The problem is that you are letting the code run 'off the end'. CCS, puts a sleep instruction after the last byte of your program. Once asleep, the receive interrupt cannot wake the chip (the only events that can wake the chip, are MCLR, a watchdog timeout, or a RB interrupt.
Change the code to:
Code: |
#use delay (clock=4000000)
#fuses XT,NOWDT,NOPROTECT,nolvp
#USE RS232(BAUD=9600, XMIT=PIN_a4, RCV=PIN_a5,errors)
INT T;
#INT_RDA
ISR(){
OUTPUT_HIGH(PIN_B5);
}
main(){
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
OUTPUT_LOW(PIN_B5);
//This stops the code running off the end.
while (TRUE);
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
dbrown
Joined: 24 Jul 2004 Posts: 20
|
|
Posted: Sat Jul 24, 2004 3:43 pm |
|
|
I just tried the adding the line while(1), but it still will not cooperate. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Sun Jul 25, 2004 2:12 am |
|
|
dbrown wrote: | I just tried the adding the line while(1), but it still will not cooperate. |
The obvious remaining 'major mistake', is that you are not connecting to the UART, so the RDA interrupt will nevr occur...
The hardware UART on a 16F873, is on pins RC6(TX), and RC7(RX). These are the pins you have to connect to to use the UART...
A4, and A5, will not work.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sun Jul 25, 2004 9:03 am |
|
|
You will also need to read the value to prevent getting an overflow condition. |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Sun Jul 25, 2004 11:51 am |
|
|
Thank-you for the responses, they are much appreciated.
Just to clairify my understanding on int_rda. If I redefine the TX and RX pins from the hardware location ie: move RX from C7 to A5 the interrupt will not be re-mapped to match the new location? Therefore the only way that int_rda will function is if the #use statement conforms to the hardware location of the RX and TX pins?
Thanks again
Dave B |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Jul 25, 2004 12:24 pm |
|
|
Quote: | Just to clairify my understanding on int_rda. If I redefine the TX and RX pins from the hardware location ie: move RX from C7 to A5 the interrupt will not be re-mapped to match the new location? Therefore the only way that int_rda will function is if the #use statement conforms to the hardware location of the RX and TX pins? |
This is correct. Only the hardware based UART is capable of generating an interrupt and this hardware UART is connected to C7 and can not be changed to iother pins. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|