The project is discussed in two parts.
Part 1: To Create LCD module
Project Source Code
###
#define F_CPU 8000000#include <avr/io.h>#include <util/delay.h>#include <avr/interrupt.h>#include <avr/eeprom.h>#include "usart.h"void switch_init ( void );int main ( void ){usart_init ();switch_init ();while ( 1 ){PORTD &= 0x7F;_delay_ms ( 2000 );PORTD |= 0x80;while ( 0x0F == ( PINC & 0x0F ) ); // wait till any key is pressed_delay_ms ( 50 );usart_send_string ( "This is a demonstration of single line LCD scrolling display module interfacingby Engineers Garage !!!n" );_delay_ms ( 500 );}}void switch_init ( void ){cli();DDRC &= 0xE0;PORTC = 0xFF;DDRD |= 0x80;PORTD |= 0x80;}#define _USART_H #ifndef F_CPU #define F_CPU 8000000 #endif #define USART_BAUDRATE 9600 #define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1) #include<avr/io.h> #include<util/delay.h> #include <stdio.h> void usart_init(); void usart_putch(unsigned char send); unsigned int usart_getch(); void usart_send_string(const char* data); int uart_print(char c, FILE *stream); FILE uart_out = FDEV_SETUP_STREAM(uart_print, NULL, _FDEV_SETUP_WRITE); int uart_print(char c, FILE *stream) { if (c == 'n') uart_print('r', stream); loop_until_bit_is_set(UCSRA, UDRE); UDR = c; return 0; } void usart_init () { UCSRB |= (1<<RXCIE) | (1 << RXEN) | (1 << TXEN); // Turn on the transmission reception .. // circuitry and receiver interrupt UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizes UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value.. // into the low byte of the UBRR register UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value.. // into the high byte of the UBRR register stdout = &uart_out; } void usart_putch(unsigned char send) { while ((UCSRA & (1 << UDRE)) == 0); // Do nothing until UDR is ready.. // for more data to be written to it UDR = send; // Send the byte } unsigned int usart_getch() { while ((UCSRA & (1 << RXC)) == 0); // Do nothing until data have been received and is ready to be read from UDR return(UDR); // return the byte } void usart_send_string(const char* data) { for(; *data; data ++) usart_putch(*data); } #endif
###
Project Source Code
###
#ifndef _LCD_H #define _LCD_H #ifndef F_CPU #define F_CPU 8000000 #endif #include<avr/io.h> #include<util/delay.h> #include<inttypes.h> #include <stdio.h> #include <string.h> #define rs PA0 #define rw PA1 #define en PA2 void lcd_init(); void dis_cmd(char); void dis_data(char); void lcdcmd(char); void lcddata(char); void lcd_clear(void); void lcd_2nd_line(void); void lcd_1st_line(void); void lcd_string(const char *data); int lcd_print(char c, FILE *stream); int lcd_scroll(const char *data); FILE lcd_out = FDEV_SETUP_STREAM(lcd_print, NULL, _FDEV_SETUP_WRITE); char disp_beg [] = " "; int lcd_print(char c, FILE *stream) { if('n' == c) lcd_2nd_line(); else dis_data(c); return 0; } #define F_CPU 8000000 #include <avr/io.h> #include <util/delay.h> #include <stdio.h> #include <avr/interrupt.h> #include "lcd.h" #include "usart.h" char A [ 150 ]; char B [ 150 ]; int main ( void ) { int i; usart_init (); cli(); lcd_init (); printf ( " ENGINEERS "); printf ( "n GARAGE "); for ( i = 0; 'n' != ( A [ i ] = usart_getch () ); i ++ ); A [ i ] = '