AVR serial programming with Atmega 644P and USB using FT232RL

Thread Starter

shamili1992

Joined Mar 6, 2017
1
Hello Everyone!

I was trying to receive characters from the PC through serial programming USB with FT232RL and atmega644P and trying to display it on LCD. I have been using PORTB as data port of LCD, PORT D for control pins of LCD.

Below is the code i have been trying to get the output from. I am getting wrong characters displayed on LCD. Also, the characters remains the same even though i am trying to send different ones. I am not able to figure out where i have been going wrong. It would be really great if any of you can help me figure it out. Thank you.
Code:
#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>
#include "lcd.h"                            // include LCD library

#ifndef F_CPU
#define F_CPU 1000000UL                    // set the CPU clock
#endif

#define BAUD 4800                           // define baud
#define BAUDRATE ((F_CPU)/(BAUD*16UL)-1)    // set baudrate value for UBRR


// function to initialize UART
void uart_init (void)
{
    UBRR0H=(BAUDRATE>>8);
    UBRR0L=BAUDRATE;                         //set baud rate
    UCSR0B|=(1<<TXEN0)|(1<<RXEN0);             //enable receiver and transmitter
    UCSR0C|=(0<<UMSEL00)|(3<<UCSZ00);// 8bit data format
}

// function to send data - NOT REQUIRED FOR THIS PROGRAM IMPLEMENTATION
void uart_transmit (unsigned char data)
{
    while (!( UCSR0A & (1<<UDRE0)));            // wait while register is free
    UDR0 = data;                             // load data in the register
}

// function to receive data
unsigned char uart_recieve (void)
{
    while(!(UCSR0A & (1<<RXC0)));           // wait while data is being received
    return UDR0;                             // return 8-bit data
}

// main function: entry point of program
int main (void)
{
    DDRB=0XFF;
    DDRD=0XFF;
    Lcd8_Init();                           // initialize LCD
    unsigned char a;
    char buffer[10];
   
    uart_init();                             // initialize UART
   
   
    while(1)
    {
        a=uart_recieve();                   // save the received data in a variable
        itoa(a,buffer,10);                  // convert numerals into string
        Lcd8_Clear();                       // LCD clear screen
        Lcd8_Cmd(0x80);
        Lcd8_Write_Char(buffer);                   // display the received value on LCD
        _delay_ms(100);                     // wait before next attempt
    }
   
    return 0;
}
 
Top