LCD is a very commonly used output device to display alphanumeric characters. The LCD displays the character corresponding to the data received on its input data port i.e., it treats the data as the ASCII value of the character to be displayed. So if the value 65 is given to its data port the character “A” will be displayed and if the value 49 is given to the LCD the numeric digit “1” will be displayed. At many instances it is required to display a number like 123 on LCD. Displaying this number is tricky. If the data port of the LCD is loaded with the number 123, then the character corresponding to it will be displayed. This article shows the concepts behind displaying a number on LCD.The article uses 8051 microcontroller (AT89C51) to demonstrate the above principle.
The circuit is divided into two units: the controller unit and the display unit. The controller unit consists of a microcontroller circuit. The microcontroller used here is AT89C51 (for details of controller circuit, refer ‘led blinking’ section). The display unit consists of a LCD interfaced to the microcontroller (for details of LCD interfacing circuit, refer ‘lcd single character display’ section). To overcome the problem stated above, the number to be displayed is store in a variable. Then each digit of the number is fetched individually in an array. Since the ASCII value of ‘0’ is 48, 1 is 49 and so on. Thus we come to the conclusion that the ASCII value of a digit (from 0 to 9) can be calculated by adding 48 to it. Thus 48 is added to each value of that array and assigned to the dataport of the LCD one by one. In this way, each digit of the number is displayed on the LCD and as a whole we have succeeded in displaying an integer number on the LCD.
Project Source Code
###
//Program to display numeric digit 0-9 on LCD #include<reg51.h> #define lcd_data_pin P2 sbit rs = P3^0; //Register select (RS) pin sbit rw = P3^1; //Read write (RW) pin sbit en = P3^6; //Enable (EN) pin unsigned char c; int num[10]; void delay(int delay_time) // Time delay function { int j,k; for(j=0;j<=delay_time;j++) for(k=0;k<=1000;k++); } void lcd_cmd(unsigned char cmd_addr) // Funtion to send command on LCD { lcd_data_pin = cmd_addr; en = 1; rs = 0; rw = 0; delay(1); en = 0; return; } void lcd_data(unsigned int i) //Function to send data on LCD { int p; int k=0; while(i>0) { num[k]=i%10; i=i/10; k++; } k--; for (p=k;p>=0;p--) { c=num[p]+48; lcd_data_pin = c; rw = 0; rs = 1; en = 1; delay(1); en = 0; } return; } void lcd_ini() //Function to initialize LCD { lcd_cmd(0x38); // Configuring settings to 8-bit 2 row delay(250); lcd_cmd(0x0E); delay(250); lcd_cmd(0x06); //Display on delay(250); lcd_cmd(0x81); //Set cursor to blink at line 1 positon 1 delay(250); lcd_data(12345); delay(250); } void main() { lcd_ini(); }###
Circuit Diagrams
Project Components
Project Video
Filed Under: 8051 Microcontroller
Filed Under: 8051 Microcontroller
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.