sending data using uart

Discussion in 'Embedded Systems and Microcontrollers' started by sasek, Jan 25, 2010.

  1. sasek

    Thread Starter Member

    Jan 3, 2010
    64
    0
    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........:)
     
  2. n9352527

    AAC Fanatic!

    Oct 14, 2005
    1,198
    4
    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.
     
  3. sasek

    Thread Starter Member

    Jan 3, 2010
    64
    0
    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......
     
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Hi Sasec
    First I think you should look up ASCII codes. And as always Google is your friends ;) Most treminal program show only printable ASCII codes. But here is one that you should test out. http://realterm.sourceforge.net/
     
  5. sasek

    Thread Starter Member

    Jan 3, 2010
    64
    0
    hai t06afre

    thanks, u help me lot

    what i discover now, actualy i send char from ASCII then i receive decimal number in PIC..........
     
  6. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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.
     
  7. sasek

    Thread Starter Member

    Jan 3, 2010
    64
    0
    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.................
     
  8. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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
     
  9. sasek

    Thread Starter Member

    Jan 3, 2010
    64
    0
    ok no problem heeeee.......

    nice to know u.............. [​IMG] t06afre :)
     
Loading...