Update

One new tab added. Open in browser view if it is not visible. (25/08/2022 08:48)

Up-Counting on LCD+8051

1) Counter.c

//COUNTER PRINT ON LCD
#include<stdio.h>
#include "lcd.h"
void main()
{
int cnt=0,k;
char str[5];
lcd_init();
while(1){
//lcd_disp("here");
cnt++;
delay(1);
sprintf(str,"%d",cnt);
lcd_command(0x01);

for(k=0;k<5;k++)
        {
          lcd_data(str[k]);
        }
}
}

2) LCD Header File (lcd.h)

#include<reg51.h>
sbit rs=P3^4;
sbit rw=P3^5;
sbit en=P3^6;
void delay(int n)
{
int i=0;
for(;i<n*1000;i++);
}
void lcd_command(char c)
{
P0=c;
rs=0;
rw=0;// write
en=1;
delay(1);
en=0;
delay(1);
}
void lcd_data(char d)
{
P0=d;
rs=1;
rw=0;// write
en=1;
delay(1);
en=0;
delay(1);
}
void lcd_init()
{
lcd_command(0x01);
lcd_command(0x38);
lcd_command(0x06);
lcd_command(0x0C);
lcd_command(0x80);
}

Note : In order to display count (which is integer because it has to increment/decrement), it is first converted to string using sprintf function.

For this function stdio.h header file has to be included.

Proteus Simulation







No comments: