Professional Documents
Culture Documents
nghin = x/1000;
tram = x%1000/100;
chuc = x%100/10;
dv = x%10;
LED1=0;
LED2=0;
LED3=0;
LED4=0;
int xung = 0;
int dem;
void ngatINT0(void) interrupt 0
{
xung++;
}
int thoi_gian=0;
float tocdo=0;
void timer0(void) interrupt 1
{
thoi_gian++;
if(thoi_gian==20,P1_0==0){
tocdo=(float)xung*60/200;
thoi_gian=0;
xung=0;
}
if(thoi_gian==20,P1_1==0){
tocdo=(float)xung*60/150;
thoi_gian=0;
xung=0;
}
if(thoi_gian==20,P1_2==0){
tocdo=(float)xung*60/120;
thoi_gian=0;
xung=0;
}
if(thoi_gian==20,P1_3==0){
tocdo=(float)xung*0;
thoi_gian=0;
xung=0;
}
TH0=0x3C;
TL0=0XB0;
TR0=1;
}
void main () {
EX0=1;
IT0=1;
EA=1;
TMOD = 0X01;
TH0=0X3C;
TL0=0XB0;
ET0=1;
TR0=1;
while(1) {
hienthi_LED_7_THANH(tocdo);
if(P1_0==0) hienthi_LED_7_THANH(tocdo);
if(P1_1==0) hienthi_LED_7_THANH(tocdo);
if(P1_2==0) hienthi_LED_7_THANH(tocdo);
if(P1_3==0) hienthi_LED_7_THANH(tocdo);
}
}
5. Nạp và chạy mô phỏng
Thực hiện nạp chương trình và chạy mô phỏng trong Proteus:
+ Mạch chạy ở chế độ mode 1 với tốc độ 1: