Code:
#include <REGX51.H> sbit A1 = P1^0; sbit A2 = P1^1; sbit A3 = P1^2; sbit A4 = P1^3; unsigned char so[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; unsigned char xung,i; unsigned int k; void delay(int time) // ham delay phuc vu quet led {int n; for(n=0;n<time;n++) { ; } } void quetled7() // ham quet led 7 { //////////////// hang nghin A1 = 1; P2 = so[i/1000]; delay(50); A1 = 0; P2=0xff; ////////////////////////// hang tram A2=1; P2=so[(i/100)%10]; delay(50); A2=0; P2=0xff; ///////////////////////////////// hang chuc A3=1; P2=so[(i/10)%10]; delay(50); A3=0; P2=0xff; //////////////////////////////// hang don vi A4=1; P2=so[i%10]; delay(50); A4=0; P2=0xff; } void khoitaotimer() // { TMOD = 0X01; // timer0 che do 1 IE = 0x82; TH0 = 0xC3; // tre 50us TL0 = 0x50; EA = 1; ET0 = 1; TR0 = 1; } void khoitaongatngoai() { EA=0; EX0=1; IT0=1; EA=1; } void isr_timer0() interrupt 1 { TF0=0; TR0=0; quetled7(); k++; TH0=0xC3; // gia tri nap lai TL0=0x50; if(k==20) { i=((xung/32)*60); // vong/phut k=0; } TR0=1; } void isr_ex0() interrupt 0 { xung++; } void main() {khoitaotimer(); khoitaongatngoai(); while(1); }
thanks.!
Comment