sending data using uart

Thread Starter

sasek

Joined Jan 3, 2010
64
hai all.....

i have involve in project using uart, but the problem occur during i want sending data. i.e if i want send 1010 from pic to pc the output at pc is diffrent. But if i used printf the word i.e "hello world" i send from PIC will occur correctly in pc, are my programming error or something that i don't know occur.


#include<pic.h>
#include<htc.h>
#include<stdio.h>

#define _XTAL_FREQ 20000000 //clock speed

__CONFIG(0x3F32); //16 bit setting


// start write function

#define uart_tx RC6
#define tx_tris TRISC6
#define uart_rx RC7
#define rx_tris TRISC7

void set_com(){

tx_tris = 0;
rx_tris = 1;
SPBRG = 129;
TXSTA = 0b00100100;
RCSTA = 0b10010000;

}

void write(unsigned char byte){

while(!TXIF)
continue;
TXREG = byte;
}

unsigned char read(){
while(!RCIF)
continue;
return RCREG;
}


thanks for viewing........:)
 

n9352527

Joined Oct 14, 2005
1,198
Are trying to send binary 0x1010 or character sequence 1010? If binary, terminal program will not display them correctly, because they are not printable characters.
 

Thread Starter

sasek

Joined Jan 3, 2010
64
ok, thats y the pc display difference with what i send. so how come i can send binary data from pc to pic. could u help me plz......
 

t06afre

Joined May 11, 2009
5,934
Think about the data from a UART as stream of bytes, and then convenient convert them to ASCII codes. But in most cases then I do communication between a PC and uC application I use a binary communication protocol. It is a waste time to send(from the uC) ASCII "1023" (4 bytes) then you just can send two bytes 0x3 and 0xFF and join the two bytes to 16 integer.
 

Thread Starter

sasek

Joined Jan 3, 2010
64
that nice................:),

if i can send using hex, it more short n saving time, it also easy for me to incrase security level. now the problem i dnt know how to do that. nice if u can give me link like tutorial. for info, PC im using VB.................
 

t06afre

Joined May 11, 2009
5,934
The technique is named type casting. It is basically to change the way your program interpret the bytes stored in memory. But I can not help you more. I am Labview programmer. And I do not know anything about Basic
 
Top