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

8bit data to uart

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



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

8bit data to uart
PostPosted: Fri Jun 11, 2010 8:42 am     Reply with quote

HI Guys I need to write 8 bits of data to the UART, data is received as input on the pic from an FPGA. I can set the data rate to accommodate the pic.

Can any suggest something that can aid me.

Thx
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
Ttelmah



Joined: 11 Mar 2010
Posts: 19360

View user's profile Send private message

PostPosted: Fri Jun 11, 2010 9:57 am     Reply with quote

You just send it....
If the PIC UART is set to 8bit mode, it'll accept 8bit data. putc, printf, all output 8bit data.
If you look at 'ex_temp.c', this sends the temperature from a sensor, over the RS232 as ASCII text. If you modify the printf lne to:
Code:

printf("%c\",value);
//or
putc(value);


It'll send the reading as successive 8bit bytes instead (without the line feed and carriage return, since these will now be acceptable 'values' for the transmission.

Best Wishes
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

PostPosted: Fri Jun 11, 2010 9:59 am     Reply with quote

HI I wrote this quick to test but I'm getting jibberish on the output

Code:
#include <16F877A.H>
#include <hardware.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#use i2c(Master, sda=PIN_C4, scl=PIN_C3)

#use FAST_IO(D)
#define ALL_IN 0xff

//============================
void main(void)
{
while(1)
{
int8 value;

set_tris_d(ALL_IN);

value = (PORTD);

printf("PortD = %c \n\r", value); 
}
}

ok I changed the the %c to an %u for unsigned and it worked Smile
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
Ttelmah



Joined: 11 Mar 2010
Posts: 19360

View user's profile Send private message

PostPosted: Fri Jun 11, 2010 2:28 pm     Reply with quote

You would get 'gibberish'.
You were asking about sending '8bit values'. This means sending bytes, that hold all possible numeric values from 0 to 255. If displayed as text, these would be 'gibberish'. However store the output, and display the stored values in hex, and the numbers are the numbers being sent, as required.
These can be directly latched by a FPGA, and are the numbers wanted.
Changing to %u, makes the code instead send _multiple bytes_ for each value, in ASCII text. Nice and easy for a human to read, but no use into an FPGA. You would need to generate the hardware in the FPGA, to recognise the ASCII values, decode them back to binary, identify the end of number 'marker' character, and then re-assemble the result. Latching the values with an FPGA, in binary mode (the gibberish), could be done in a few dozen gates. Taking the values in ASCII, and regenerating the binary value, would require a few hundred gates instead.....

Best Wishes
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