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

Receiving RS232 for control

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







Receiving RS232 for control
PostPosted: Sun Jun 28, 2009 1:22 pm     Reply with quote

Hi all,
I am trying to write a program that can read data from RS232 sent from a PC or another pic. The chip should be able to do different functions depending on which key I press on the computer. So far I am trying to use something like this:
Code:


if (kbhit()){
keypressed=getc();
printf("key pressed is: %c /r/n",keypressed);
if(keypressed=="a") {
printf("I can do something do to with this key being hit");
output_high(PIN_B2);
}


that is just a general idea of what I'm trying to do, I know this won't compile. I don't know how to really define the if(keypressed=="a") part.

I figured I needed to use the input.c file for this application. I saw a sample step.c in the CCS files, and it included input.c. The problem with input.c is that I can't seem to compile my code when it is included. I am using MPLAB, and I added it to the "other files", and I added the ctype.h header to the folder under "headers". But it just won't compile with it! It has an error that says undefined identifier getc(), and others that are similar. I have not modified it in any way I think.
Anyways, do you guys this that I Am on the right track with this?
Thanks for the help!
Newbie1.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 28, 2009 1:31 pm     Reply with quote

See this example program:
http://www.ccsinfo.com/forum/viewtopic.php?t=39145&start=1
This program receives a single character from the PC, then converts
it to upper case, and then uses a switch-case statement to select the
correct code to execute, based upon the character that was received.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sun Jun 28, 2009 6:33 pm     Reply with quote

Note you need a single quote pair around a constant character. This always catches me.
Code:
 case 'B':     // Read switch on Slave PIC
or
if(keypressed=='a') {

_________________
The search for better is endless. Instead simply find very good and get the job done.
Guest








PostPosted: Sun Jun 28, 2009 11:35 pm     Reply with quote

aha! Thank you all soo much. Got it!
So is this the same method that a wireless remote would work through say an xbee, or even infrared type device. Can we use RS232 on a pic to pic using the xbee or fm radio transmitter and check to see if 'a' or something else was pressed?
Also, any suggestions on the problems I'm having with the input.c file?
Thanks all!
I really appreciate it.
Newbie1.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 28, 2009 11:51 pm     Reply with quote

You need to invoke the rs232 library. It has the getc() function in it.
This is done with a #use rs232() statement. See the example below:
Code:

#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PI7N_C7, ERRORS)

#include <input.c>

//======================================
void main()
{


while(1);
}
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