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

Please advise... (newbee question)

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



Joined: 10 Mar 2004
Posts: 3

View user's profile Send private message

Please advise... (newbee question)
PostPosted: Sun Nov 21, 2004 1:28 pm     Reply with quote

Hello everybody

I would like to have some help if its possible.

I have established an RS232 asynchronous communication of a PIC16877 with my PC.

I am sending the 'A' and 'F' from the PC. I get them at the PIC (data type int8) do the proper manipulation (UART receiving etc) and endup with data1='A' and data2='F' (I have verified that using LED testing).

Now my problem is this:

I want to convert 'A' and 'F' into 'AF' and then to 0xAF. The reason is to send 0xAF through SPI to another chip.

What I have thought is to turn both of them into hex (0x0A and 0x0F respectively) and then to use make16() to make 0x00AF and then to use make8() to take the LSB thus 0xAF and program it through SPI.

The problem with make16(), as I understand, is that it will not give me 0x00AF but 0x0A0F. Is that correct?
Thus if I use make8() I will be at the beginning again since I will get 0x0F as the LSB and not what I want.

Can you please advise me how to achieve what I want?
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Sun Nov 21, 2004 4:19 pm     Reply with quote

This is how I have done in the past:

Code:

#include <stdlib.h>

char Str[5];
byte Result;

Str[0]='0';
Str[1]='x';
Str[2]=getch();  //Read the 'A'
Str[3]=getch();  //Read the 'F'
Str[4]=0;          //Null character, Now Str="0xAF"

Result=atoi(Str); //Now result is 175, or 0xAF


SherpaDoug



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

View user's profile Send private message

PostPosted: Mon Nov 22, 2004 8:08 am     Reply with quote

Maybe you are looking for the swap() function, which swaps high and low nibbles of a byte? Check it out to see if it does what you want.
_________________
The search for better is endless. Instead simply find very good and get the job done.
panayig



Joined: 10 Mar 2004
Posts: 3

View user's profile Send private message

PostPosted: Wed Nov 24, 2004 11:59 am     Reply with quote

Guys thank you very much for your replies. Very Happy

Haplo I have used your method and worked perfectly. Thank you.

Sherpadoug thank you for the time you 've taken to consider my question. I have looked at the swap() as you suggested but the code I produced using it is far bulkier than Haplos is so I will go with Haplos suggestion. Wink
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