Dem san phan don gian.DSN
EM sửa hoài code mà sao con LED ở giữa nó cứ nhảy số lung tung trong khi 2 con ngoài thì bình thường mấy đại ca giúp em với
/*====================khai bao thu vien lenh va dinh nghia chan vdk ===========*/
#include<regx51.h> // thu vien lenh
#define leddata P2 // dinh nghia duong du lieu le 7 thanh noi P2
#define led1 P3_0
#define led2 P3_1
#define led3 P3_2
#define led4 P3_3
#define led5 P3_4
#define led6 P3_5
#define nut P1_0 // dinh nghia nut an noi voi P1.3
#define nut1 P1_3// dinh nghia nut an noi voi P1.0
#define nut2 P1_4// dinh nghia nut an noi voi P1.4
/*============================khai bao bien ===========*/
unsigned char cao,tb,thap;
unsigned char so[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x9 0}; // ma led 7 thanh anot chung tuong ung voi tu 0 den 9
unsigned char a,b,c,d,e,f;
/*============================chuong trinh con tao tre ===========*/
void delay( unsigned int m )
{
unsigned int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<125;j++)
{}
}
}
/*============================chuong trinh con hien thi quet led===========*/
void hien_thi(unsigned char cao,unsigned char tb,unsigned char thap)
{
a=cao/10;
b=(cao-a*10);
c=tb/10;
d=(tb-c*10);
e=thap/10;
f=(thap-e*10);
led1=1;led2=0,led3=0,led4=0,led5=0,led6=0;
leddata=so[a];
delay(3);
led1=0;led2=1,led3=0,led4=0,led5=0,led6=0;
leddata=so[b];
delay(3);
led1=0;led2=0,led3=1,led4=0,led5=0,led6=0;
leddata=so[c];
delay(3);
led1=0;led2=0,led3=0,led4=1,led5=0,led6=0;
leddata=so[d];
delay(3);
led1=0;led2=0,led3=0,led4=0,led5=1,led6=0;
leddata=so[e];
delay(3);
led1=0;led2=0,led3=0,led4=1,led5=0,led6=1;
leddata=so[f];
delay(3);
}
/*============================chuong trinh chinh ===========*/
void main()
{
cao=0;
tb=0;
thap=0;
while(1)
{
if(nut==0)
{
delay(200);
cao=cao+1;
}
if(cao==100)
{
tb=0;
thap=0;
cao=cao+0;
}
if(cao==100)
cao=0;
hien_thi(cao,tb,thap);
if(nut1==0)
{
delay(200);
tb=tb+1;
}
if(tb==100)
{
cao=0;
thap=0;
tb=tb+0;
}
if(tb==100)
tb=0;
hien_thi(cao,tb,thap);
if(nut2==0)
{
delay(200);
thap=thap+1;
}
if(thap==100)
{
cao=0;
tb=0;
thap=thap+0;
}
if(thap==100)
thap=0;
hien_thi(cao,tb,thap);
}
}
EM sửa hoài code mà sao con LED ở giữa nó cứ nhảy số lung tung trong khi 2 con ngoài thì bình thường mấy đại ca giúp em với
/*====================khai bao thu vien lenh va dinh nghia chan vdk ===========*/
#include<regx51.h> // thu vien lenh
#define leddata P2 // dinh nghia duong du lieu le 7 thanh noi P2
#define led1 P3_0
#define led2 P3_1
#define led3 P3_2
#define led4 P3_3
#define led5 P3_4
#define led6 P3_5
#define nut P1_0 // dinh nghia nut an noi voi P1.3
#define nut1 P1_3// dinh nghia nut an noi voi P1.0
#define nut2 P1_4// dinh nghia nut an noi voi P1.4
/*============================khai bao bien ===========*/
unsigned char cao,tb,thap;
unsigned char so[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x9 0}; // ma led 7 thanh anot chung tuong ung voi tu 0 den 9
unsigned char a,b,c,d,e,f;
/*============================chuong trinh con tao tre ===========*/
void delay( unsigned int m )
{
unsigned int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<125;j++)
{}
}
}
/*============================chuong trinh con hien thi quet led===========*/
void hien_thi(unsigned char cao,unsigned char tb,unsigned char thap)
{
a=cao/10;
b=(cao-a*10);
c=tb/10;
d=(tb-c*10);
e=thap/10;
f=(thap-e*10);
led1=1;led2=0,led3=0,led4=0,led5=0,led6=0;
leddata=so[a];
delay(3);
led1=0;led2=1,led3=0,led4=0,led5=0,led6=0;
leddata=so[b];
delay(3);
led1=0;led2=0,led3=1,led4=0,led5=0,led6=0;
leddata=so[c];
delay(3);
led1=0;led2=0,led3=0,led4=1,led5=0,led6=0;
leddata=so[d];
delay(3);
led1=0;led2=0,led3=0,led4=0,led5=1,led6=0;
leddata=so[e];
delay(3);
led1=0;led2=0,led3=0,led4=1,led5=0,led6=1;
leddata=so[f];
delay(3);
}
/*============================chuong trinh chinh ===========*/
void main()
{
cao=0;
tb=0;
thap=0;
while(1)
{
if(nut==0)
{
delay(200);
cao=cao+1;
}
if(cao==100)
{
tb=0;
thap=0;
cao=cao+0;
}
if(cao==100)
cao=0;
hien_thi(cao,tb,thap);
if(nut1==0)
{
delay(200);
tb=tb+1;
}
if(tb==100)
{
cao=0;
thap=0;
tb=tb+0;
}
if(tb==100)
tb=0;
hien_thi(cao,tb,thap);
if(nut2==0)
{
delay(200);
thap=thap+1;
}
if(thap==100)
{
cao=0;
tb=0;
thap=thap+0;
}
if(thap==100)
thap=0;
hien_thi(cao,tb,thap);
}
}
Comment