#include<reg51.h>
void lcd_cmd(char);
void lcd_init();
void lcd_data(char[]);
void delay(int);
void lcd_dataint(int);
void counter1(); //to print the count value at counter1 location
void counter2(); //(on lcd)
void counter3();
sbit rs=P2^4;
sbit oe=P2^0;
sbit but1=P2^1; //counter1 button
sbit but2=P2^2; //counter2 button
sbit but3=P2^3; //counter3 button
int token_no=0; //overall count
void main()
{
rs=0;
oe=0;
but1=1;but2=1;but3=1;
TMOD=0x01;
lcd_init();
lcd_data("C1 C2 C3 ");
while(1)
{
while(but1==1 && but2==1 && but3==1);
if(but1==0||but2==0||but3==0)
{
token_no++;
if(but1==0)
counter1();
if(but2==0)
counter2();
if(but3==0)
counter3();
}
}
}
void counter1()
{
lcd_cmd(0xC0);
lcd_dataint(token_no);
}
void counter2()
{
lcd_cmd(0xC6);
lcd_dataint(token_no);
}
void counter3()
{
lcd_cmd(0xCC);
lcd_dataint(token_no);
}
void lcd_dataint(int p)
{
int a[3],i=0;
while((p/10)!=0)
{
a[i]=p%10;
i++;
p=p/10;
}
a[i]=p;
for(i=2;i>=0;i--)
{
rs=1;
P3=48+a[i];
oe=1;
delay(1);
oe=0;
}
}
void lcd_cmd(char x)
{
rs=0;
P3=x;
oe=1; //creating a pulse
delay(1);
oe=0;
}
void lcd_init()
{
lcd_cmd(0x38);
lcd_cmd(0x01);
lcd_cmd(0x06);
lcd_cmd(0x0E);
}
void lcd_data(char x[])
{
int i;
for(i=0;x[i]!='\0';i++)
{
rs=1;
P3=x[i];
oe=1;
delay(1);
oe=0;
}
}
void delay(int n)
{
int i=0;
for(i=0;i<n;i++)
{
TR0=1;
while(TF0!=1);
TF0=0;
TR0=0;
}
}
Saturday, February 25, 2012
Token System Program for 8051
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment