Mình quét led 7 đoạn anode chung, nối vào port 2, code đếm từ 0-9, nhưng mà nó ko chạy, hjc
#include <REGX52.H>
long n;
void delay(long t)
{
for(n=0;n<t;n++)
{
;
}
}
//...ham cac so
void tat(void)
{
P2=0xff;
}
void Hienthiled( unsigned char x )
{
switch(x)
{
case 1: {tat();P2=0xC0;break;}
case 2: {tat();P2=0xF9;break;}
case 3: {tat();P2=0xA4;break;}
case 4: {tat();P2=0xB0;break;}
case 5: {tat();P2=0x99;break;}
case 6: {tat();P2=0x92;break;}
case 7: {tat();P2=0x82;break;}
case 8: {tat();P2=0xF8;break;}
case 9: {tat();P2=0x80;break;}
case 10: {tat();P2=0x90;break;}
}
}
void main(void)
{
while(1)
{
for(n=0;n<=10;n++)
{
Hienthiled(n);
delay(20000);
}
}
}
#include <REGX52.H>
long n;
void delay(long t)
{
for(n=0;n<t;n++)
{
;
}
}
//...ham cac so
void tat(void)
{
P2=0xff;
}
void Hienthiled( unsigned char x )
{
switch(x)
{
case 1: {tat();P2=0xC0;break;}
case 2: {tat();P2=0xF9;break;}
case 3: {tat();P2=0xA4;break;}
case 4: {tat();P2=0xB0;break;}
case 5: {tat();P2=0x99;break;}
case 6: {tat();P2=0x92;break;}
case 7: {tat();P2=0x82;break;}
case 8: {tat();P2=0xF8;break;}
case 9: {tat();P2=0x80;break;}
case 10: {tat();P2=0x90;break;}
}
}
void main(void)
{
while(1)
{
for(n=0;n<=10;n++)
{
Hienthiled(n);
delay(20000);
}
}
}
Comment