mọi người giúp minh đoạn code này đếm đến 60s thì hàng trăm giảm nhé. Lập trình hoài mà không được.
#include <REGX51.H>
#define led1 P2_0
#define led2 P2_1
#define led3 P2_2
#define led4 P2_3
#define led5 P1_7
#define led6 P2_4
unsigned int dem, nghin, tram, chuc, donvi;
char i,j;
int gio, phuc, giay;
//char i,j;
// ma hex cua led 7 doan
unsigned char ma[]={0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90};
//khoi tao timer 0 de quyet led
void delay_timer0(void)
{
TMOD=0x01; //chon timer 0 o che do 1 (16 bit)
TH0=-9215/256; //nap gia tri cho bit cao (26ms)
TL0=-9215%256; //nap gia tri cho bit thap (26ms)
TR0=1; //khoi dong bo dinh thoi timer0 chay
while (!TF0); //cho co tran bat len 1
TF0=0; //xoa co tran
TR0=0; // ngung bo dinh thoi
EA=1;
}
//ham quet led de hien thi so
void quet_led(void)
{
led1=1;
P1=ma[nghin];
delay_timer0();
led1=0;
led2=1;
P1=ma[tram] ;
delay_timer0();
led2=0;
led3=1;
P1=ma[chuc];
delay_timer0();
led3=0;
led4=1;
P1=ma[donvi];
delay_timer0();
led4=0;
donvi=dem%10;
chuc=(dem/10)%10;
tram= (dem/100)%10;
nghin=(dem/1000)%10;
}
void main()
{
i=0;
giay=0;
phuc=0;
gio=0;
P1=0x00;
TMOD=0x10; // chon timer 1 o che do 1 (16 bit)
TH1=0x3C; //5ms
TL1=0xB0;
TF1=1;
ET1=1;
EA=1;
TR1=1;
while (1)
{
for(dem=1500;dem>0;dem--)
{
quet_led();
}
}
}
#include <REGX51.H>
#define led1 P2_0
#define led2 P2_1
#define led3 P2_2
#define led4 P2_3
#define led5 P1_7
#define led6 P2_4
unsigned int dem, nghin, tram, chuc, donvi;
char i,j;
int gio, phuc, giay;
//char i,j;
// ma hex cua led 7 doan
unsigned char ma[]={0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90};
//khoi tao timer 0 de quyet led
void delay_timer0(void)
{
TMOD=0x01; //chon timer 0 o che do 1 (16 bit)
TH0=-9215/256; //nap gia tri cho bit cao (26ms)
TL0=-9215%256; //nap gia tri cho bit thap (26ms)
TR0=1; //khoi dong bo dinh thoi timer0 chay
while (!TF0); //cho co tran bat len 1
TF0=0; //xoa co tran
TR0=0; // ngung bo dinh thoi
EA=1;
}
//ham quet led de hien thi so
void quet_led(void)
{
led1=1;
P1=ma[nghin];
delay_timer0();
led1=0;
led2=1;
P1=ma[tram] ;
delay_timer0();
led2=0;
led3=1;
P1=ma[chuc];
delay_timer0();
led3=0;
led4=1;
P1=ma[donvi];
delay_timer0();
led4=0;
donvi=dem%10;
chuc=(dem/10)%10;
tram= (dem/100)%10;
nghin=(dem/1000)%10;
}
void main()
{
i=0;
giay=0;
phuc=0;
gio=0;
P1=0x00;
TMOD=0x10; // chon timer 1 o che do 1 (16 bit)
TH1=0x3C; //5ms
TL1=0xB0;
TF1=1;
ET1=1;
EA=1;
TR1=1;
while (1)
{
for(dem=1500;dem>0;dem--)
{
quet_led();
}
}
}
Comment