This is the most interesting article to play with LCD. After going through the article, you can create any character/symbol which cannot be created using the ASCII values for example smiley. You can even create small games. Conventionally 16X2 LCD is use to display text or numerical values. It is possible to display special characters, your own designed characters too on LCD by using its 5 x 8 matrix block. These special characters are stored in the CGRAM of LCD. This article shows how to create and display special character on LCD using ATmega16. For more details refer to the article how to create custom characters.
This article assumes that the readers are aware of the concepts of interfacing LCD with AVR microcontroller (ATMEGA 16). For more information about interfacing LCD with AVR, refer How to display string on LCD using AVR. In order to create a custom character its configuration is first defined in the CGRAM of the LCD. A maximum of eight characters can be stored at a time in the 16 x 2 LCD. Every character is assigned eight bytes in the CGRAM and by configuring these bytes any character can be generated. The size of the CGRAM is 64 bytes.
For detailed description about configuring the CGRAM, refer to creating custom characters on LCD using 8051. The concepts of generating a custom character remain the same. The connection of LCD with the AVR is shown in the circuit diagram.
Project Source Code
###
//Program to display special Characters on LCD using AVR Microcontroller (ATmega16)/*To display special character on LCD dataLCD DATA port----PORT Bctrl port------PORT Drs-------PD0rw-------PD1en-------PD2using internal clock frequency 1MHz*/#include<avr/io.h>#include<util/delay.h>#define LCD_DATA PORTB //LCD data port#define signal PORTD#define en PD2 // enable signal#define rw PD1 // read/write signal#define rs PD0 // register select signalvoid LCD_cmd(unsigned char cmd);void init_LCD(void);void LCD_write(unsigned char data);void LCD_character();int main(){DDRB=0xff;DDRD=0x07;init_LCD();_delay_ms(50); // delay of 50 mili secondsLCD_character();return 0;}void init_LCD(void){LCD_cmd(0x38); // initialization of 16X2 LCD in 8bit mode_delay_ms(1);LCD_cmd(0x01); // clear LCD_delay_ms(1);LCD_cmd(0x0E); // cursor ON_delay_ms(1);LCD_cmd(0x80); // ---8 go to first line and --0 is for 0th position_delay_ms(1);return;}void LCD_cmd(unsigned char cmd){LCD_DATA=cmd;ctrl =(0<<rs)|(0<<rw)|(1<<en);_delay_ms(1);ctrl =(0<<rs)|(0<<rw)|(0<<en);_delay_ms(50);return;}void LCD_write(unsigned char data){LCD_DATA= data;ctrl = (1<<rs)|(0<<rw)|(1<<en);_delay_ms(1);ctrl = (1<<rs)|(0<<rw)|(0<<en);_delay_ms(50);return ;}void LCD_character(){LCD_cmd(64); // Address where customized character is to be storedLCD_write(0);LCD_write(14);LCD_write(17);LCD_write(2);LCD_write(4);LCD_write(4);LCD_write(0);LCD_write(4);LCD_cmd(0x80); // Location of LCD where the character is to be displayedLCD_write(0); // Displaying the character created at address 0x64_delay_ms(10);LCD_cmd(72); // Address where customized character is to be storedLCD_write(0);LCD_write(10);LCD_write(21);LCD_write(17);LCD_write(18);LCD_write(4);LCD_write(0);LCD_write(0);LCD_cmd(0x82); // Location of LCD where the character is to be displayedLCD_write(1); // Displaying the character created at address 0x72_delay_ms(10);LCD_cmd(80); //Address where customized character is to be storedLCD_write(0);LCD_write(0);LCD_write(10);LCD_write(0);LCD_write(4);LCD_write(0);LCD_write(14);LCD_write(17);LCD_cmd(0x84); // Location of LCD where the character is to be displayedLCD_write(2); // Displaying the character created at address 0x80_delay_ms(10);LCD_cmd(88); //Address where customized character is to be storedLCD_write(1);LCD_write(3);LCD_write(5);LCD_write(9);LCD_write(9);LCD_write(11);LCD_write(27);LCD_write(24);LCD_cmd(0x86); // Location of LCD where the character is to be displayedLCD_write(3); // Displaying the character created at address 0x88_delay_ms(10);LCD_cmd(96); // Address where customized character is to be storedCD_write(0);LCD_write(0);LCD_write(0);LCD_write(4);LCD_write(0);LCD_write(31);LCD_write(0);LCD_cmd(0xC0); // location where the character is to be displayedLCD_write(4); // Display the character created at address 0x96_delay_ms(10);LCD_cmd(104); //Address where customized character is storedLCD_write(0);LCD_write(17);LCD_write(10);LCD_write(17);LCD_write(4);LCD_write(0);LCD_write(14);LCD_write(17);LCD_cmd(0xC2); // Location of LCD where the character is to be displayedLCD_write(5); // Display the character created at address 0x104_delay_ms(10);LCD_cmd(112); // Address where customized character is to be storedLCD_write(0);LCD_write(14);LCD_write(17);LCD_write(2);LCD_write(4);LCD_write(4);LCD_write(0);LCD_write(4);LCD_cmd(0xC4); // Location of LCD where the character is to be displayedLCD_write(6); // Display the character created at address 0x112_delay_ms(10);LCD_cmd(120); // Address where customized character is to be storedLCD_write(10);LCD_write(0);LCD_write(4);LCD_write(0);LCD_write(14);LCD_write(17);LCD_write(17);LCD_write(14);LCD_cmd(0xC6); // Location of LCD where the character is to be displayedLCD_write(7); // Display the character created at address 0x120_delay_ms(10);}###
Circuit Diagrams
Project Components
Project Video
Filed Under: AVR
Filed Under: AVR
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.