Hiện tại em đang làm mạch đo khoảng cách dùng sóng siêu âm SFR-05. Em làm xong đoạn code nhưng nó báo lỗi không cho dịch ra file .HEX . Sau đây là đoạn code em nó, bác nào biết chỗ sai chỉ dùm em nhá Ths!
#include<reg52.h>
//================
sbit Led1 = P0^3;
sbit Led2 = P0^2;
sbit Led3 = P0^1;
sbit Led4 = P0^0;
sbit Led_bao_1 = P3^6;
sbit Led_bao_2 = P3^7;
sbit trig = P3^1;
sbit echo = P3^2;
//=================
unsigned char M[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x9 0};
unsigned char M1[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x1 0};
int a,b,c,d,e,f,g,h;
unsigned char timel,timeh,i;
float time;
bit ok;
void delay(unsigned int t)
{
unsigned int i;
for {i=0;i<=t;i++);
}
void hienthi(float cm)
{
e=cm*100;
e= (int)(e);
g=e/100;
h=e%100;
a=g/100;
b=(g%100)/10;
c= ((g%1000)%10);
d=h/10;
for {f=0;f<100;f++)
{
Led1=1; //led dau tien sang
P2=M[a];
delay(20);
Led1=0;
P2=0xff;//xoa du lieu
Led2=1; //led 2 sang
P2=M[b];
delay(20);
Led2=0;
P2=0xff;//xoa du lieu
Led3=1; //led 3 sang
P2=M1[c];
delay(20);
Led3=0;
P2=0xff;//xoa du lieu
Led4=1; //led 4 sang
P2=M[d];
delay(20);
Led4=0;
P2=0xff;//xoa du lieu
}
}
void ngatINT0 () interrupt 0{
timel=TL0;
timeh=TH0;
TL0=TH0=0;
ok=0;
}
}
void main(){
trig=0;
TMOD=0x09; //timer 0 che do 1 (16bit) cuc GATE mo
TR0=1;
IT0=1; //ngat ngoai 0 che do falling
IT1=1;
EX0=1; //cho phep ngat ngoai 0
EX1=1;
EA=1; // cho phep ngat toan cuc
ok=0;
while(1){
if(ok==0){
trig=1;
delay(20);
trig=0;
ok=1;
}
time=timel+timeh*256;
hienthi(time/58);
}
}
#include<reg52.h>
//================
sbit Led1 = P0^3;
sbit Led2 = P0^2;
sbit Led3 = P0^1;
sbit Led4 = P0^0;
sbit Led_bao_1 = P3^6;
sbit Led_bao_2 = P3^7;
sbit trig = P3^1;
sbit echo = P3^2;
//=================
unsigned char M[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x9 0};
unsigned char M1[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x1 0};
int a,b,c,d,e,f,g,h;
unsigned char timel,timeh,i;
float time;
bit ok;
void delay(unsigned int t)
{
unsigned int i;
for {i=0;i<=t;i++);
}
void hienthi(float cm)
{
e=cm*100;
e= (int)(e);
g=e/100;
h=e%100;
a=g/100;
b=(g%100)/10;
c= ((g%1000)%10);
d=h/10;
for {f=0;f<100;f++)
{
Led1=1; //led dau tien sang
P2=M[a];
delay(20);
Led1=0;
P2=0xff;//xoa du lieu
Led2=1; //led 2 sang
P2=M[b];
delay(20);
Led2=0;
P2=0xff;//xoa du lieu
Led3=1; //led 3 sang
P2=M1[c];
delay(20);
Led3=0;
P2=0xff;//xoa du lieu
Led4=1; //led 4 sang
P2=M[d];
delay(20);
Led4=0;
P2=0xff;//xoa du lieu
}
}
void ngatINT0 () interrupt 0{
timel=TL0;
timeh=TH0;
TL0=TH0=0;
ok=0;
}
}
void main(){
trig=0;
TMOD=0x09; //timer 0 che do 1 (16bit) cuc GATE mo
TR0=1;
IT0=1; //ngat ngoai 0 che do falling
IT1=1;
EX0=1; //cho phep ngat ngoai 0
EX1=1;
EA=1; // cho phep ngat toan cuc
ok=0;
while(1){
if(ok==0){
trig=1;
delay(20);
trig=0;
ok=1;
}
time=timel+timeh*256;
hienthi(time/58);
}
}
Comment