các bạn ơi giải thích tại sao chương trình này của mình hai đèn led lại không sáng.mình tìm mãi mà không phát hiện ra lỗi ở chỗ nào mọi người sửa giúp mình nhé.
/*--------------------------------------------------------------------------------------------*/
#include <REGX51.H>
sbit SelRed=P0^0;
sbit SelGre=P2^7;
sbit Green=P3^3;//tin hieu xanh
sbit Yellow=P3^4;//tin hieu vang
sbit Red=P3^5;//tin hieu do
sbit Key_test=P3^2;
//Bang ma bay thanh cua hang chuc(khong chon sang den XANH)
unsigned char code Table7S_CH[10]={0x7E,0x30,0x6D,0x79,0x33,0x5B,0x5F,0x70,0x7F,0x7 B};
//Bang ma bay thanh cua hang chuc(chon sang den XANH)
unsigned char code Table7S_CH_X[10]={0xFE,0xB0,0xED,0xF9,0xB3,0xDB,0xDF,0xF0,0xFF,0xF B};
//Bang ma bay thanh cua hang don vi(khong chon sang den DO)
unsigned char code Table7S_DV[10]={0x7E,0x0C,0xB6,0x9E,0xCC,0xDA,0xFA,0x0E,0xFE,0xD E};
//Bang ma bay thanh cua hang don vi(chon sang den DO)
unsigned char code Table7S_DV_D[10]={0x7F,0x0D,0xB7,0x9F,0xCD,0xDB,0xFB,0x0F,0xFF,0xD F};
//************************************************** ****************************
char G_inc=0,G_dec=0,
R_inc=0,R_dec=0;
unsigned char tic=0;
bit Flag_1s;
//*******************
void DispGreenLED(char input)//ham hien thi den led xanh
{
if(input<0)input=0;
P0=Table7S_DV[input%10];//lay phan du
input/=10;
P2=Table7S_CH_X[input%10];
}
void DispRedLED(char input)//hien thi led do
{
if(input<0)input=0;
P0=Table7S_DV_D[input%10];
input/=10;
P2=Table7S_CH[input%10];
}
//****************************************
void main(void)
{
P2=0;P0=0;Flag_1s=0;
P2=0;P0=0;Flag_1s=0;
//Init timer0
TMOD=0x11;//khoi tao cho Timer0 o che do timer 1 16 bits
TR0=0;
TH0=0xD8;//dem tu F0D8 toi FFFF
TL0=0xF0;
tic=0;
ET0=1;//cho phep ngat Timer0
EX0=1;//cho phep ngat ngoai 0
IT0=1;
EA=1;//Cho phep ngat toan cuc
while(!Green);
while(Green);
TR0=1;
while(!Green)
if(Flag_1s)
{
Flag_1s=0;G_inc++;
}
TR0=0;
TH0=0xD8;
TL0=0xF0;
tic=0;
if(G_inc>0)
{
G_dec=G_inc;G_inc=0;
}
while(Red);
TR0=1;
while(!Red)
if(Flag_1s)
{
Flag_1s=0;R_inc++;
}
TR0=0;
TH0=0xD8;
TL0=0xF0;
tic=0;
if(R_inc>0){R_dec=R_inc;R_inc=0;}
//**************************************
while(1){
while(Green);
TR0=1;DispGreenLED(G_dec);
while(!Green)if(Flag_1s){Flag_1s=0;G_inc++;G_dec--;DispGreenLED(G_dec);}
TR0=0;
TH0=0xD8;
TL0=0xF0;
tic=0;
if(G_inc>0)
{
G_dec=G_inc;G_inc=0;
}
P2=0;P0=0;
while(Red);
TR0=1;DispRedLED(R_dec);
while(!Red)
if(Flag_1s)
{
Flag_1s=0;R_inc++;R_dec--;DispRedLED(R_dec);
}
TR0=0;
TH0=0xD8;
TL0=0xF0;
tic=0;
if(R_inc>0)
{
R_dec=R_inc;R_inc=0;
}
P0=0;P2=0;
}
}
//----------------------------------------------------------------------------------------------------------
void TestKEY_INT(void) interrupt 0{
char Test=99,II;
EA=0;TR0=0;ET0=0;
while(Test>=0){
DispGreenLED(Test);Test-=11;
II=100;
while(II--){TH0=0xD8;TL0=0xF0;TR0=1;while(!TF0);TF0=0;}
}
Test=99;
while(Test>=0){
DispRedLED(Test);Test-=11;
II=100;
while(II--){TH0=0xD8;TL0=0xF0;TR0=1;while(!TF0);TF0=0;}
}
P2=0;P0=0;Flag_1s=0;
ET0=1;TR0=1;EA=1;
}
//----------------------------------------------------------------------------------------------------------
void INTTimer0_10ms(void) interrupt 1{
TR0=0;
TH0=0xD8;
TL0=0xF0;
TR0=1;
tic++;
if(tic>=100){tic=0;Flag_1s=1;}
}
/*--------------------------------------------------------------------------------------------*/
#include <REGX51.H>
sbit SelRed=P0^0;
sbit SelGre=P2^7;
sbit Green=P3^3;//tin hieu xanh
sbit Yellow=P3^4;//tin hieu vang
sbit Red=P3^5;//tin hieu do
sbit Key_test=P3^2;
//Bang ma bay thanh cua hang chuc(khong chon sang den XANH)
unsigned char code Table7S_CH[10]={0x7E,0x30,0x6D,0x79,0x33,0x5B,0x5F,0x70,0x7F,0x7 B};
//Bang ma bay thanh cua hang chuc(chon sang den XANH)
unsigned char code Table7S_CH_X[10]={0xFE,0xB0,0xED,0xF9,0xB3,0xDB,0xDF,0xF0,0xFF,0xF B};
//Bang ma bay thanh cua hang don vi(khong chon sang den DO)
unsigned char code Table7S_DV[10]={0x7E,0x0C,0xB6,0x9E,0xCC,0xDA,0xFA,0x0E,0xFE,0xD E};
//Bang ma bay thanh cua hang don vi(chon sang den DO)
unsigned char code Table7S_DV_D[10]={0x7F,0x0D,0xB7,0x9F,0xCD,0xDB,0xFB,0x0F,0xFF,0xD F};
//************************************************** ****************************
char G_inc=0,G_dec=0,
R_inc=0,R_dec=0;
unsigned char tic=0;
bit Flag_1s;
//*******************
void DispGreenLED(char input)//ham hien thi den led xanh
{
if(input<0)input=0;
P0=Table7S_DV[input%10];//lay phan du
input/=10;
P2=Table7S_CH_X[input%10];
}
void DispRedLED(char input)//hien thi led do
{
if(input<0)input=0;
P0=Table7S_DV_D[input%10];
input/=10;
P2=Table7S_CH[input%10];
}
//****************************************
void main(void)
{
P2=0;P0=0;Flag_1s=0;
P2=0;P0=0;Flag_1s=0;
//Init timer0
TMOD=0x11;//khoi tao cho Timer0 o che do timer 1 16 bits
TR0=0;
TH0=0xD8;//dem tu F0D8 toi FFFF
TL0=0xF0;
tic=0;
ET0=1;//cho phep ngat Timer0
EX0=1;//cho phep ngat ngoai 0
IT0=1;
EA=1;//Cho phep ngat toan cuc
while(!Green);
while(Green);
TR0=1;
while(!Green)
if(Flag_1s)
{
Flag_1s=0;G_inc++;
}
TR0=0;
TH0=0xD8;
TL0=0xF0;
tic=0;
if(G_inc>0)
{
G_dec=G_inc;G_inc=0;
}
while(Red);
TR0=1;
while(!Red)
if(Flag_1s)
{
Flag_1s=0;R_inc++;
}
TR0=0;
TH0=0xD8;
TL0=0xF0;
tic=0;
if(R_inc>0){R_dec=R_inc;R_inc=0;}
//**************************************
while(1){
while(Green);
TR0=1;DispGreenLED(G_dec);
while(!Green)if(Flag_1s){Flag_1s=0;G_inc++;G_dec--;DispGreenLED(G_dec);}
TR0=0;
TH0=0xD8;
TL0=0xF0;
tic=0;
if(G_inc>0)
{
G_dec=G_inc;G_inc=0;
}
P2=0;P0=0;
while(Red);
TR0=1;DispRedLED(R_dec);
while(!Red)
if(Flag_1s)
{
Flag_1s=0;R_inc++;R_dec--;DispRedLED(R_dec);
}
TR0=0;
TH0=0xD8;
TL0=0xF0;
tic=0;
if(R_inc>0)
{
R_dec=R_inc;R_inc=0;
}
P0=0;P2=0;
}
}
//----------------------------------------------------------------------------------------------------------
void TestKEY_INT(void) interrupt 0{
char Test=99,II;
EA=0;TR0=0;ET0=0;
while(Test>=0){
DispGreenLED(Test);Test-=11;
II=100;
while(II--){TH0=0xD8;TL0=0xF0;TR0=1;while(!TF0);TF0=0;}
}
Test=99;
while(Test>=0){
DispRedLED(Test);Test-=11;
II=100;
while(II--){TH0=0xD8;TL0=0xF0;TR0=1;while(!TF0);TF0=0;}
}
P2=0;P0=0;Flag_1s=0;
ET0=1;TR0=1;EA=1;
}
//----------------------------------------------------------------------------------------------------------
void INTTimer0_10ms(void) interrupt 1{
TR0=0;
TH0=0xD8;
TL0=0xF0;
TR0=1;
tic++;
if(tic>=100){tic=0;Flag_1s=1;}
}
Comment