You are on page 1of 2

#include<AT89X51.

h>
void lcd_cmd(unsigned char);
void lcd_data(unsigned char);
void lcd_convert(unsigned long);
unsigned long count=0;
unsigned int val=0;
unsigned long sol;

sbit rs =P2^4;
sbit rw =P2^5;
sbit en =P2^6;

void main()
{
lcd_cmd(0x38);
lcd_cmd(0x01);
lcd_cmd(0x84);
lcd_cmd(0x0f);
lcd_data('0');
lcd_data('0');
lcd_data('0');
lcd_data('0');
lcd_data('0');
lcd_data('0');
lcd_data('0');
lcd_data('0');
lcd_data('0');
lcd_data('0');
TMOD =0x16;
IE =0x8A;
IP =0x02;
TH0 =0xff;
TL0 =0xff;
TH1=TL1 =0;
TR0 =1;
while(1);
}

void timer1(void) interrupt 3


{
count++;
}

void counter0(void) interrupt 1


{
EA=0;
TR1=TR0=0;
val=TL1;
val|=(TH1<<8);
sol=60000000/(((65536*count)+val)*1.085);
lcd_convert(sol);
count=0;
val=0;
TH1=TL1=0;
TR1=TR0=1;
EA=1;
}

void lcd_cmd(unsigned char dat)


{
unsigned int c;
P0=dat;
rs=0;
rw=0;
en=1;
for(c=0;c<2000;c++);
en=0;
}

void lcd_data(unsigned char dat)


{
unsigned int c;
P0=dat;
rw=0;
rs=en=1;
for(c=0;c<2000;c++);
en=0;
}

void lcd_convert(unsigned long da)


{
unsigned long a,b,c,d,e,f,g,h,i,j,k,l,m,n;

a=da/10;
b=da%10;
c=a/10;
d=a%10;
e=c/10;
f=c%10;
g=e/10;
h=e%10;
i=g/10;
j=g%10;
k=i/10;
l=i%10;
m=k%10;
n=k/10;
lcd_cmd(0x01);
lcd_cmd(0x84);
lcd_data(n|0x30);
lcd_data(m|0x30);
lcd_data(l|0x30);
lcd_data(j|0x30);
lcd_data(h|0x30);
lcd_data(f|0x30);
lcd_data(d|0x30);
lcd_data(b|0x30);
}