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

need help in rs232 data send frm PC

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



Joined: 26 Jan 2008
Posts: 15

View user's profile Send private message

need help in rs232 data send frm PC
PostPosted: Fri Feb 22, 2008 10:03 pm     Reply with quote

hi,i'm using PIC16f877 and using 8LEDs to indicate the value i get from PC is correct...but the problem now is i just know to write the receive data from integer 30-40 only.the target i wish to get is from 0-100.it will be too long if i write the receive data as in my code below:

//rs232 data receive sample
#include <16f877a.h>
#device adc=10
#use delay(clock=4915200)
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
#byte portb=6
#byte portc=7

void main()
{
byte mystat=0;
int16 mydata;
set_tris_b(0x00);//all port B is output
set_tris_c(0x80);//C7 is input

do
{
if(kbhit())
{mydata=getch();
mystat=1;}
if (mystat==1)
{
if (mydata==30)
{portb=0xaa;} //1010 1010
else if(mydata==31)
{portb=0x00;} //0000 0000
else if(mydata==32)
{portb=0x01;} //0000 0001
else if(mydata==33)
{portb=0x02;} //0000 0010
else if(mydata==34)
{portb=0x03;} //0000 0011
else if(mydata==35)
{portb=0x04;} //0000 0100
else if(mydata==36)
{portb=0x05;} //0000 0101
else if(mydata==37)
{portb=0x06;} //0000 0110
else if(mydata==38)
{portb=0x07;} //0000 0111
else if(mydata==39)
{portb=0x08;} //0000 1000
else if(mydata==40)
{portb=0xff;} //1111 1111
mystat=0;

}
}
while(TRUE);
}


Do anyone can help me in this?
Any short way to can replace my way as above?
thanks for your help:-)
stefsun



Joined: 23 May 2007
Posts: 22

View user's profile Send private message

PostPosted: Fri Feb 22, 2008 11:07 pm     Reply with quote

mydata=getch();
output_b(mydata);


try it
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Sat Feb 23, 2008 10:36 am     Reply with quote

as for "30-40 only"
Check the ASCII table and you will see why you are getting values between 30h-40h.
These values are ascii values of characters 0,1...to 9.
If you want to get a numerical representation, simply subtract 0x30 (48 in decimal) from the value you receive from the PC.

Anyway, since you want to have values from 0-100, you can either send just one byte from the PC and put them directly to the output port, or you can send the value as a string (understand as '100', with length of 3 characters). However, you will have to buffer these character in the pic because you can receive just 1 character at a time. You can use atoi() function to get a numerical representation of the buffer.
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