Mantra counting machine using 8051 micro- controller.
PROGRAM:
LCD header file:
#include<reg51.h>
sbit RS = P3^7;
sbit RW = P3^6;
sbit EN = P3^5;
void delay(int t);
void lcd_init(void);
void lcd_command(char c);
void lcd_data(char d);
void str(char a[]);
void lcd_init(void) // function for initialization of lcd
{
lcd_command(0x38);
lcd_command(0x01);
lcd_command(0x0f);
lcd_command(0x06);
lcd_command(0x0c);
lcd_command(0x80);
}
void lcd_command(char c) // function to execute command
{
P1=c;
RS=0;
RW=0;
EN=1;
delay(5);
EN=0;
delay(5);
}
void lcd_data(char d) // function to display data
{
P1=d;
RS=1;
RW=0;
EN=1;
delay(5);
EN=0;
delay(5);
}
void delay(int t) // delay function
{
int j;
for(j=0;j<t*1275;j++);
}
void str(char a[]) // function to display string
{
int j;
for(j=0;a[j]!='\0';j++)
{
lcd_data(a[j]);
}
}
一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
Main Program:
#include<reg51.h>
#include<string.h>
#include<LCD.h>
sbit start=P2^0; // START button
sbit stop=P2^6; // STOP button
sbit reset=P3^4; // RESET button
unsigned int q,r,s,t,i=0;
void print(unsigned int p);
void main()
{
lcd_init(); // initialization of lcd
while(1)
{
if((start==0)&&(stop==1)&&(reset==1)) // start button
{
i++;
if(i<=5000)
{
while(start==0)
{
print(i);
}
start=1;
}
}
if((reset==0)&&(start==1)&&(stop==1)) // reset button
{
i=0;
}
if((stop==0)&&(start==1)&&(reset==1)) // stop button
{
lcd_command(0x80);
str("Total count:");
print(i);
}
}
}
void print(unsigned int p) // function to display number upto 5000
{
if(p<10)
{
q=p+48;
lcd_data(q);
lcd_command(0x01);
}
else if((p>=10)&&(p<=99))
{
q=p/10;
q=q+48;
r=p%10;
r=r+48;
lcd_data(q);
lcd_data(r);
lcd_command(0x01);
}
else if((p>=100)&&(p<=999))
{
q=p/100;
q=q+48;
r=((p%100)/10);
r=r+48;
s=p%10;
s=s+48;
lcd_data(q);
lcd_data(r);
lcd_data(s);
lcd_command(0x01);
}
else if((p>=1000)&&(p<=5000))
{
q=p/1000;
q=q+48;
r=((p%1000)/100);
r=r+48;
t=(((p%1000)%100)/10);
t=t+48;
s=p%10;
s=s+48;
lcd_data(q);
lcd_data(r);
lcd_data(t);
lcd_data(s);
lcd_command(0x01);
}
VIDEO:
Note:
1.Please refer the below link to know the interfacing of lcd.
http://embeddedprojects222.blogspot.com/2020/07/lcd-interfacing-using-8051-micro.html
2.Please refer the below link to know how to display numbers on an lcd.
http://embeddedprojects222.blogspot.com/2020/07/how-to-display-number-on-lcd.html
Comments
Post a Comment