Thứ Sáu, 14 tháng 12, 2018

Display custom characters on LCD using AVR Microcontroller (ATmega16)

Developed By: 

Akshay Daga
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.
 
Custom Characters Display using ATmega16 AVR microcontroller on LCD Prototype



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.
Circuit:
Circuit Diagram of Display custom characters on LCD using AVR Microcontroller (ATmega16)
Code:
//Program to display special Characters on LCD using AVR Microcontroller (ATmega16)
/*
To display special character on LCD data
LCD DATA port----PORT B
ctrl port------PORT D
rs-------PD0
rw-------PD1
en-------PD2
 
using 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 signal
 
void 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 seconds
LCD_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 stored
LCD_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 displayed
LCD_write(0);  // Displaying the character created at address 0x64 
_delay_ms(10);
 
LCD_cmd(72);  // Address where customized character is to be stored
LCD_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 displayed
LCD_write(1);  // Displaying the character created at address 0x72
_delay_ms(10);
 
LCD_cmd(80);  //Address where customized character is to be stored
LCD_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 displayed
LCD_write(2);  // Displaying the character created at address 0x80 
_delay_ms(10);
 
LCD_cmd(88);  //Address where customized character is to be stored
LCD_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 displayed
LCD_write(3);  // Displaying the character created at address 0x88 
_delay_ms(10);
 
LCD_cmd(96);  // Address where customized character is to be stored
CD_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 displayed
LCD_write(4);  // Display the character created at address 0x96 
_delay_ms(10);
 
LCD_cmd(104);  //Address where customized character is stored
LCD_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 displayed
LCD_write(5);  // Display the character created at address 0x104 
_delay_ms(10);
 
LCD_cmd(112);  // Address where customized character is to be stored
LCD_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 displayed
LCD_write(6);   // Display the character created at address 0x112 
_delay_ms(10);
 
LCD_cmd(120);  // Address where customized character is to be stored
LCD_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 displayed
LCD_write(7);   // Display the character created at address 0x120
_delay_ms(10);
}

Không có nhận xét nào:

Đăng nhận xét

Bài đăng mới nhất

Hướng dẫn sử dụng Cân điện tử Fujihatsu FTC-01

Hướng dẫn sử dụng Cân điện tử Fujihatsu FTC-01 # candientu ,  # fujihatsu ,  # candientufujihatsu  #candientu,  # candientufujhatsu , #fuji...

Bài đăng phổ biến