![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
jacqueskleynhans
Joined: 10 Apr 2008 Posts: 109 Location: Cape Town, South Africa
|
8bit data to uart |
Posted: Fri Jun 11, 2010 8:42 am |
|
|
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" |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19360
|
|
Posted: Fri Jun 11, 2010 9:57 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
jacqueskleynhans
Joined: 10 Apr 2008 Posts: 109 Location: Cape Town, South Africa
|
|
Posted: Fri Jun 11, 2010 9:59 am |
|
|
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](images/smiles/icon_smile.gif) _________________ "THE ONLY EASY DAY WAS YESTERDAY" |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19360
|
|
Posted: Fri Jun 11, 2010 2:28 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|