Đây là chương trình em viết.dịch ra được file hex nhưng khi mô phỏng thì không chạy !!!!!em mới học vđk nên bác nào biết e sai chỗ nào chỉ em với!file mô phỏng em kèm theo ở dưới.thanks các bác nhiều
#include <AT89X51.H>
#include<stdio.h>
#include<math.h>
#define led P0
#define aled1 P1_0
#define aled2 P1_1
#define aled3 P1_2
#define aled4 P1_3
#define nutnhan P3_2
unsigned char M[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x9 0};
unsigned char donvi,chuc,tram,nghin,num;
unsigned int dem=0;
//----------------------------------------------------------------------------------------------
void delay(unsigned int time)
{
unsigned int i,j;
for(i=1;i<time;i++)
for(j=0;j<100;j++);
}
//----------------------------------------------------------------------------------------------
void clear_led(void)
{
P0=0xff;
P1=0xff;
}
//----------------------------------------------------------------------------------------------
void hienthi(unsigned int num)
{
nghin = num/1000;
tram = (num%1000)/100;
chuc = ((num%1000)%100)/10;
donvi = ((num%1000)%100)%10;
P1=0xf7;
P0=M[donvi];
delay(100);
clear_led();
P1=0xfb;
P0=M[chuc];
delay(100);
clear_led();
P1=0xfd;
P0=M[tram];
delay(100);
clear_led();
P1=0xfe;
P0=M[nghin];
delay(100);
clear_led();
}
//----------------------------------------------------------------------------------------------
unsigned char phim()
{
if(P3_2==0)
{delay(100);
while(P3_2==0){;}
dem++;
if(dem==10000){dem=0;}
}
return dem;
}
//----------------------------------------------------------------------------------------------
void main(void)
{
int m;
while(1)
{
m=phim();
hienthi(m);
delay(1000);
}
}
#include <AT89X51.H>
#include<stdio.h>
#include<math.h>
#define led P0
#define aled1 P1_0
#define aled2 P1_1
#define aled3 P1_2
#define aled4 P1_3
#define nutnhan P3_2
unsigned char M[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x9 0};
unsigned char donvi,chuc,tram,nghin,num;
unsigned int dem=0;
//----------------------------------------------------------------------------------------------
void delay(unsigned int time)
{
unsigned int i,j;
for(i=1;i<time;i++)
for(j=0;j<100;j++);
}
//----------------------------------------------------------------------------------------------
void clear_led(void)
{
P0=0xff;
P1=0xff;
}
//----------------------------------------------------------------------------------------------
void hienthi(unsigned int num)
{
nghin = num/1000;
tram = (num%1000)/100;
chuc = ((num%1000)%100)/10;
donvi = ((num%1000)%100)%10;
P1=0xf7;
P0=M[donvi];
delay(100);
clear_led();
P1=0xfb;
P0=M[chuc];
delay(100);
clear_led();
P1=0xfd;
P0=M[tram];
delay(100);
clear_led();
P1=0xfe;
P0=M[nghin];
delay(100);
clear_led();
}
//----------------------------------------------------------------------------------------------
unsigned char phim()
{
if(P3_2==0)
{delay(100);
while(P3_2==0){;}
dem++;
if(dem==10000){dem=0;}
}
return dem;
}
//----------------------------------------------------------------------------------------------
void main(void)
{
int m;
while(1)
{
m=phim();
hienthi(m);
delay(1000);
}
}
Comment