UART Communication PIC18f4550

Discussion in 'The Projects Forum' started by nandishc057@gmail.com, Dec 11, 2013.

  1. nandishc057@gmail.com

    Thread Starter New Member

    Dec 11, 2013
    1
    0
    i'm new to this, sending data "H" through tis code ,I'm not receiving the code in hyperterminal
    #include <P18F4550.h>
    ///////////////////////////////////////////////////////////////////////////////////
    unsigned char getc_usart1 (void);
    void putc_usart1 (unsigned char );
    void usart1_open(void);
    void Ascii_Convert_TX(unsigned char );
    /////////////////////////////////////////////////////////////////////////////////////
    #pragma config OSC = HS // Using 20 MHz crystal with PLL
    //#pragma config PLLDIV = 5 // Divide by 5 to provide the 96 MHz PLL with 4 MHz input
    //#pragma config CPUDIV = OSC1_PLL2 // Divide 96 MHz PLL output by 2 to get 48 MHz system clock
    //#pragma config USBDIV = 2 // USB clock comes from 96 MHz PLL output / 2
    #pragma config FCMEN = OFF // Disable Fail-Safe Clock Monitor
    #pragma config IESO = OFF // Disable Oscillator Switchover mode
    #pragma config PWRT = OFF // Disable Power-up timer
    //#pragma config BOR = OFF // Disable Brown-out reset
    //#pragma config VREGEN = ON // Use internal USB 3.3V voltage regulator
    #pragma config WDT = OFF // Disable Watchdog timer
    #pragma config MCLRE = ON // Enable MCLR Enable
    #pragma config LVP = OFF // Disable low voltage ICSP
    //#pragma config ICPRT = OFF // Disable dedicated programming port (44-pin devices)
    #pragma config CP0 = OFF // Disable code protection



    //////////////////////////////////////////////////////////////////////////////////////
    void main()
    {
    unsigned char c='H';
    usart1_open();
    putc_usart1 (c);
    }
    ////////////////////////////////////////////////////////////////////////////////////////
    unsigned char getc_usart1 (void)
    {
    while (!PIR1bits.RCIF);
    return RCREG;
    }
    ////////////////////////////////////////////////////////////////////////////////////////////
    void putc_usart1 (unsigned char xc)
    {
    TXREG = xc;
    while (!PIR1bits.TXIF);
    TXREG =0x00;
    }
    /////////////////////////////////////////////////////////////////////////////////////////////
    void usart1_open()
    {
    TXSTA = 0x24; // BRGH =1 asynchronus high baud rate selection , TXEN =1 transmit enabled
    SPBRG = 129;//103; 9600 bits/sec 20MHz
    TRISCbits.RC6 = 0; /* configure TX1 pin for output */
    RCSTA = 0x34;
    TRISCbits.RC7 = 1; /* configure RX1 pin for input */
    //PIE1bits.TXIE = 0; /* disable transmit interrupt */
    //PIE1bits.RCIE = 0; /* disable receive interrupt */
    RCSTAbits.SPEN = 1; /* enable USART port */
    }
    //////////////////////////////////////////////////////////////////////////////////////////////////////
    /*
    * Function Name : Assic Convert Tx()
    * Function : Converts the hex to assic and send on UART1
    * Input Parameters :
    * Output Parameter :
    * Note :
    */
    void Ascii_Convert_TX(unsigned char ddata)
    {
    unsigned char mask,Hdigit,Ldigit;

    mask = ddata&0xF0; // High Byte value
    mask = mask>>4;
    if(mask>9)
    mask = mask+7;
    Hdigit = mask+0x30;

    mask = ddata&0x0F; // Lower Byte value
    if(mask>9)
    mask = mask+7;
    Ldigit = mask+0x30;
    putc_usart1(Hdigit);
    putc_usart1(Ldigit);
    }
     
Loading...