I have a rs232 sensor connect to the pic's hardware usart pins c6/c7. I have used an interrupt to get the data when it is being sent. This is then forwarded to the computer via a software usart on pins E0/E1. I used the interrupt as the pic does other stuff which need a constant loop for it to work.
The pic perfectly interrupt and get the reading and send it to the computer, but I want to send commands from the computer to the pic, to perfom a tasks.
I used this code for the sensor: ( I got the interrupt code from the examples in the CCS info folder.) (Code is in a while loop in the main)
Code:
while(bkbhit){
putc( bgetc(),PC );}
so i used this code for the pc: (code is in a while loop in the main)
Code:
while(kbhit (PC))(
cget = fgetc(PC)
if (cget=='g')
output_high(PIN_B2);
But when I send a 'g' from hyperterminal, nothing happens. Do I need to set another interrupt? How do I go about making the command from the computer to work?
Thanks in advance for your help.
makoo
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
Posted: Thu Mar 04, 2010 6:15 pm
Quote:
while(kbhit (PC)) {
Change this to
Code:
while(1) {
The fgetc() function has the kbhit included in it.
makoo Guest
Posted: Fri Mar 05, 2010 2:32 am
i have a while loop in the main already... can i do this?
Code:
while (True) --- already in the code...
{
(if loops)
delay_ms(500); // led delay
while(1) { --- adding this will it work??
cget = fgetc(PC)
if (cget=='g')
output_high(PIN_B2);
}
}
thanks again!
makoo
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
Posted: Fri Mar 05, 2010 2:43 am
I didn't know that you had an outer loop. Is that all the code in the loop
or is it just code fragments ?
Post the complete code in those two while() loops.
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