Wednesday, November 20, 2013

LCD Control using UART Serial Port


When you write an LCD Program to
write your name or any text, you can only display the same text at all times. If you have to change the text, you have to change the code, recompile it again and then reprogram it. Instead of doing all this, you can just connect your circuit to serial port of computer and change the text on LCD instantly using the hyperterminal of the PC. You can just type any text in the hyperterminal and press ENTER key. The text will be displayed on the LCD instantly. You can customize the display by changing the pattern.

Purpose:It will take input from the terminal and writes that on LCD

ATmega8 @ 16MHz 
PC Software : Hyper terminal @ 19200 baud 
No Parity,1 Stop Bit, 
Flow Control = NONE 
#include "uart.h" 
#include "lcd.h" 
static int uart_putchar(char c, FILE *stream);
static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
static int uart_putchar(char c, FILE *stream)
if (c == '\n')
uart_putchar('\r', stream);
loop_until_bit_is_set(UCSRA, UDRE);
UDR = c;
return 0;
int main()
stdout = &mystdout;
   //Initialize the LCD Module. 
   //USART Initialisation 19200bps @ 16MHz crystal 
char str[20],data; int i=0; while(1) { printf("\n PLEASE ENTER THE STRING : "); for(i=0;;i++) { data = USARTReadChar();
//saving the given string
   str[i]= data;
   if((str[i]=='\n') ||( str[i]=='\r'))
//displaying the saved string
printf("\n Finished \n"); _delay_ms(1000); } }

Open the hyperterminal in your computer. Set the settings as per the code. Then reset your microcontroller. You will see "enter the string : ". Enter the text and press ENTER key. You will get "Finished". You will see the text you entered on the display.

Files related to this project. Click here to download

The text will display only when you enter the text from terminal. I am developing this code for new options. In the later version of this project, the entered text is saved in the EEPROM and if you change the code directly from the terminal.
I will be updating this post regularly, so subscribe to my blog newsletter(top right of this page) for updated information. If you have any doubts, post you comments here or mail me @ Arifuddin Sheik

No comments:

Post a Comment