Code:
#include <REGX51.H> sbit Led1 = P1^0; sbit Led2 = P1^1; sbit Led3 = P1^2; sbit Led4 = P1^3; //================= unsigned char M[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x9 0}; int a,b,c,d,e,f,k; //================= void delay(long time) {long n; for(n=0;n<time;n++) {; } } void khoitaongatngoai0() {EA=1; EX0=1; IT0=1; } void ngatngoai0() interrupt 0 { { for(k=0;k<=9999;k++) { a=k/1000; b=(k/100)%10; e=(k/10)%10; f=k%10; Led1=1; //led dau tien sang P2=M[a]; delay(50); Led1=0; P2=0xff;//xoa du lieu Led2=1; //led 2 sang P2=M[b]; delay(50); Led2=0; P2=0xff; Led3=1; P2=M[e]; delay(50); Led3=0; P2=0xff; Led4=1; P2=M[f]; delay(50); Led4=0; P2=0xff; } } } void main() { khoitaongatngoai0(); }
Comment