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 CCS Technical Support

2 x rs232 16f877a

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







2 x rs232 16f877a
PostPosted: Thu Mar 04, 2010 5:29 pm     Reply with quote

hi there,

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

View user's profile Send private message

PostPosted: Thu Mar 04, 2010 6:15 pm     Reply with quote

Quote:
while(kbhit (PC)) {

Change this to
Code:
while(1) {

The fgetc() function has the kbhit included in it.
makoo
Guest







PostPosted: Fri Mar 05, 2010 2:32 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Mar 05, 2010 2:43 am     Reply with quote

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