Chương trình minh viết hình như không sai mà sao không chạy được vậy. mong các ban giúp đỡ và sửa hộ mình với. hichic
#include <REGX52.H>
code unsigned char table[]=
{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90 };
unsigned char posit=0;
unsigned int count=0;
sbit int1 = P3^3;
sbit SMG_q = P1^0;
sbit SMG_b = P1^1;
sbit SMG_s = P1^2;
sbit SMG_g = P1^3;
void display(unsigned int da);
void delay(unsigned int timer);
void main(void)
{
IE=0x84;
EA=1; // tat ca moi ngat dc hoat dong.
EX1=1; // cho phep ngat ngoai 1
IT1=1; // thiet lap ngat theo suon am.
TL1=0;
TH1=0;
TMOD=0X10;
while(1){
display(count);
delay(100);
}
}
void hongwai(void) interrupt 1
{
TR1=1; // khoi dong timer 1
while(!int1);
TR1=0;
count=(int)(TH1<<8)+TL1;
count/=10;
EX1=0;
TF1=0;
}
void display(unsigned int da)
{
P0=0XFF;
da=da%10000;
switch(posit){
case 0:
SMG_q=0;
SMG_b=1;
SMG_s=1;
SMG_g=1;
P0=table[da/1000];
break;
case 1:
SMG_q=1;
SMG_b=0;
SMG_s=1;
SMG_g=1;
P0=table[da%1000/100]&0x7f;
break;
case 2:
SMG_q=1;
SMG_b=1;
SMG_s=0;
SMG_g=1;
P0=table[da%100/10];
break;
case 3:
SMG_q=1;
SMG_b=1;
SMG_s=1;
SMG_g=0;
P0=table[da%10];
break;
}
posit++;
if(posit>3)
posit=0;
}
void delay(unsigned int timer){
while(timer--);
}
#include <REGX52.H>
code unsigned char table[]=
{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90 };
unsigned char posit=0;
unsigned int count=0;
sbit int1 = P3^3;
sbit SMG_q = P1^0;
sbit SMG_b = P1^1;
sbit SMG_s = P1^2;
sbit SMG_g = P1^3;
void display(unsigned int da);
void delay(unsigned int timer);
void main(void)
{
IE=0x84;
EA=1; // tat ca moi ngat dc hoat dong.
EX1=1; // cho phep ngat ngoai 1
IT1=1; // thiet lap ngat theo suon am.
TL1=0;
TH1=0;
TMOD=0X10;
while(1){
display(count);
delay(100);
}
}
void hongwai(void) interrupt 1
{
TR1=1; // khoi dong timer 1
while(!int1);
TR1=0;
count=(int)(TH1<<8)+TL1;
count/=10;
EX1=0;
TF1=0;
}
void display(unsigned int da)
{
P0=0XFF;
da=da%10000;
switch(posit){
case 0:
SMG_q=0;
SMG_b=1;
SMG_s=1;
SMG_g=1;
P0=table[da/1000];
break;
case 1:
SMG_q=1;
SMG_b=0;
SMG_s=1;
SMG_g=1;
P0=table[da%1000/100]&0x7f;
break;
case 2:
SMG_q=1;
SMG_b=1;
SMG_s=0;
SMG_g=1;
P0=table[da%100/10];
break;
case 3:
SMG_q=1;
SMG_b=1;
SMG_s=1;
SMG_g=0;
P0=table[da%10];
break;
}
posit++;
if(posit>3)
posit=0;
}
void delay(unsigned int timer){
while(timer--);
}
Comment