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

PIC16F873A and int_rda

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



Joined: 24 Jul 2004
Posts: 20

View user's profile Send private message

PIC16F873A and int_rda
PostPosted: Sat Jul 24, 2004 2:32 pm     Reply with quote

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
Ttelmah
Guest







Re: PIC16F873A and int_rda
PostPosted: Sat Jul 24, 2004 2:52 pm     Reply with quote

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);
}
dbrown



Joined: 24 Jul 2004
Posts: 20

View user's profile Send private message

PostPosted: Sat Jul 24, 2004 3:43 pm     Reply with quote

I just tried the adding the line while(1), but it still will not cooperate.
Ttelmah
Guest







PostPosted: Sun Jul 25, 2004 2:12 am     Reply with quote

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
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Sun Jul 25, 2004 9:03 am     Reply with quote

You will also need to read the value to prevent getting an overflow condition.
Guest








PostPosted: Sun Jul 25, 2004 11:51 am     Reply with quote

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
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Jul 25, 2004 12:24 pm     Reply with quote

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