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

receive data from UART hardware

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



Joined: 01 May 2008
Posts: 7

View user's profile Send private message

receive data from UART hardware
PostPosted: Thu May 22, 2008 1:29 am     Reply with quote

Hi All...

I want to send and receive data using PIC and UART hardware.

The data to send is:

unsigned char SelectCard[3]={0xBA,0x02,0x01}

putc(SelectCard[3]);


I will receive data like this:

byte0,byt1,byte2,byt3,byte4,byte5,byt6,byt7,byt8
0xBD,0x08,0x01,0x00,0xAA,0xBB,0xCC,0xDD,0x01
..........................0x01....................................0x02
..........................0x0A....................................0x03
..........................0x0F....................................0x04

byte3 and byte8 has four possible. My problem is I dont know how to use getc(); and at that time check data byte3 must be equal to 0x00 and byte8 must be equal to 0x01, else not accept.

Can any one help me?
Ttelmah
Guest







PostPosted: Thu May 22, 2008 2:52 am     Reply with quote

Start with your 'putc'. Putc, accepts _one_ character. Your array has characters at locations SelectCard[0] to SelectCard[2]. The location 'SelectCard[3]', doesn't exist.....
To send the three characters, you need something like:
Code:

int8 ctr;

for (ctr=0;ctr<3;ctr++) putc(SelectCard[ctr]);


The reception is going to need to be basically the same. You will need to read the nine characters, and then 'accept' the value if your conditions are met.
Now, this is _not_ how to do it, if the code needs to be doing much else, but gives a very crude starting point....
Code:

int8 ctr;
char rbuff[9];

for (ctr=0;ctr<3;ctr++) putc(SelectCard[ctr]); //send command
for (ctr=0;ctr<9;ctr++) rbuff[ctr]=getc(); //receive 9 response bytes

if (rbuff[3]==0 && rbuff[8]==1) {
   //only get here, if the third byte is 0, and the ninth is 1
   //execute what you want to do with the data.

}

Hopefully you get the idea.

Best Wishes
azHer



Joined: 01 May 2008
Posts: 7

View user's profile Send private message

PostPosted: Thu May 22, 2008 8:34 am     Reply with quote

Ttelmah wrote:
Start with your 'putc'. Putc, accepts _one_ character. Your array has characters at locations SelectCard[0] to SelectCard[2]. The location 'SelectCard[3]', doesn't exist.....
To send the three characters, you need something like:
Code:

int8 ctr;

for (ctr=0;ctr<3;ctr++) putc(SelectCard[ctr]);


The reception is going to need to be basically the same. You will need to read the nine characters, and then 'accept' the value if your conditions are met.
Now, this is _not_ how to do it, if the code needs to be doing much else, but gives a very crude starting point....
Code:

int8 ctr;
char rbuff[9];

for (ctr=0;ctr<3;ctr++) putc(SelectCard[ctr]); //send command
for (ctr=0;ctr<9;ctr++) rbuff[ctr]=getc(); //receive 9 response bytes

if (rbuff[3]==0 && rbuff[8]==1) {
   //only get here, if the third byte is 0, and the ninth is 1
   //execute what you want to do with the data.

}

Hopefully you get the idea.

Best Wishes


Thank you for reply me...

I use SelectCard[3] because the communication format from Host to Reader like this:

Header Length Command Checksum
...0xBA ....0x02 .....0x01.....


Header 1 byte, 0xBA mean from Host to Reader
Length 1 byte, calculate from command to checksum
Command 1 byte, 0x01 mean SelectCard
Checksum 1 byte, XOR result from Header to datainclusively

Actually I,m not to understand about this, Can you explain should use SelectCard[3] or just SelectCard[2].


One more thing, If I receive char rbuff[11].

rbuff[7], rbuff[8], rbuff[8], rbuff[10] is equal to value. Can I use like this... rbuff[7]+rbuff[8]+rbuff[8]+rbuff[10]!=0 continue the program...
Ttelmah
Guest







PostPosted: Fri May 23, 2008 2:02 am     Reply with quote

This is really 'basic C'. This forum is meant to be about _CCS_ specific problems and questions. I'm afraid you need to get a simple C tutorial. 'SelectCard[3]', _does not exist_. You want to send three characters, then you have to do as I show, and send all three of them _one at a time_.

Best Wishes
azHer



Joined: 01 May 2008
Posts: 7

View user's profile Send private message

PostPosted: Wed May 28, 2008 8:01 am     Reply with quote

Thanks for reply me Very Happy

I'm rellly slow in programming. Thanks for your help before.

Here is one more thing I dont know. After send this data:

unsigned char SendData[5]={0XBA,0x03,0x05,0x01,0xB8}

the UART hardware will return this data:

0xDB,0x07,0x05,0x00,0xA1,0x2C,0xEF,0xDC,0x01

how to get byte colour blue(value) after that display it. lcd_putc();
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