Em sửa mãi mà không ra xin mấy pro giúp em với ạ :
#include<regx52.h>
#include<stdio.h>
unsigned int soxung;
float tocdo;
unsigned char dem;
sbit RS =P1^0;
sbit RW =P1^1;
sbit EN =P1^2;
char x;
void delay(unsigned long int t)
{
unsigned long int i;
for (i=0;i<n;i++)
}
void busy(void)
{
p2=0xff;
RS=0;
do {EN=1; //k cho fep tin hieu vao LCD
delay(10);
En=0;
x=p2;
x=x&0x80;
}
while (x!=0x80)
}
void ghilenh(unsigned char lenh)
{ busy();
p2=lenh;
RS=0; RW=0;EN=1;
delay(50);
}
void ghidulieu(unsigned char data)
{ busy();
p2=data;
RS=1; RW=0; EN=1;
delay(50);
EN=0;
delay(50);
}
void ghikytu(char *s)
{while(*s)
{ghidulieu(*s);
s++;
}
}
void hienthi(int data)
{if (data<10)
ghidulieu(data);
if (data<100)
{ ghidulieu(data/10);
data=data%10;
ghidulieu(data);
}
if (data<1000)
{ ghidulieu(data/100);
data=data%100;
ghidulieu(data/10);
data=data%10;
ghidulieu(data);
}
if (data<10000)
{ ghidulieu(data/1000);
data=data%1000;
ghidulieu(data/100);
data=data%100;
ghidulieu(data/10);
data=data%10;
ghidulieu(data);
}
}
void khoitaoLCD(void)
{ ghilenh(0x03);
ghilenh(0x38);
ghilenh(0x06);
ghilenh(0x0e);
}
void ngatngoai0() interrupt 0
{dem++;
if (dem==20)
{dem=o;TH0=0;
tocdo=soxung/100;
soxung=0;
TH0=-50000/256;
TL0=-50000/256;
}}
void ngatngoai1() interrupt 2
{
soxung++; }
voi main()
{TMOD=0x21;
TL1=TH1=-3;TH0=-50000%256;
TL0=-50000%256;
SCON=0X52;
IT1=1;
IR1=0X85 //NGAT NGOAI 0 & 1
dem=0;
khoitaoLCD();
while(1)
{ghidulieu(0x01);
ghidulieu(0x08);
ghikytu(vantoc:v/s);
hienthi(soxung);
soxung=0; tocdo=0;
TR0=1;//cho fep timer hoat dong
}
}
#include<regx52.h>
#include<stdio.h>
unsigned int soxung;
float tocdo;
unsigned char dem;
sbit RS =P1^0;
sbit RW =P1^1;
sbit EN =P1^2;
char x;
void delay(unsigned long int t)
{
unsigned long int i;
for (i=0;i<n;i++)
}
void busy(void)
{
p2=0xff;
RS=0;
do {EN=1; //k cho fep tin hieu vao LCD
delay(10);
En=0;
x=p2;
x=x&0x80;
}
while (x!=0x80)
}
void ghilenh(unsigned char lenh)
{ busy();
p2=lenh;
RS=0; RW=0;EN=1;
delay(50);
}
void ghidulieu(unsigned char data)
{ busy();
p2=data;
RS=1; RW=0; EN=1;
delay(50);
EN=0;
delay(50);
}
void ghikytu(char *s)
{while(*s)
{ghidulieu(*s);
s++;
}
}
void hienthi(int data)
{if (data<10)
ghidulieu(data);
if (data<100)
{ ghidulieu(data/10);
data=data%10;
ghidulieu(data);
}
if (data<1000)
{ ghidulieu(data/100);
data=data%100;
ghidulieu(data/10);
data=data%10;
ghidulieu(data);
}
if (data<10000)
{ ghidulieu(data/1000);
data=data%1000;
ghidulieu(data/100);
data=data%100;
ghidulieu(data/10);
data=data%10;
ghidulieu(data);
}
}
void khoitaoLCD(void)
{ ghilenh(0x03);
ghilenh(0x38);
ghilenh(0x06);
ghilenh(0x0e);
}
void ngatngoai0() interrupt 0
{dem++;
if (dem==20)
{dem=o;TH0=0;
tocdo=soxung/100;
soxung=0;
TH0=-50000/256;
TL0=-50000/256;
}}
void ngatngoai1() interrupt 2
{
soxung++; }
voi main()
{TMOD=0x21;
TL1=TH1=-3;TH0=-50000%256;
TL0=-50000%256;
SCON=0X52;
IT1=1;
IR1=0X85 //NGAT NGOAI 0 & 1
dem=0;
khoitaoLCD();
while(1)
{ghidulieu(0x01);
ghidulieu(0x08);
ghikytu(vantoc:v/s);
hienthi(soxung);
soxung=0; tocdo=0;
TR0=1;//cho fep timer hoat dong
}
}
Comment