单片机数码管应用,数码管扫描
#include
#define uint unsigned int
#define uchar unsigned char
uchar c;
sbit p10=P1^0;
sbit p11=P1^1;
sbit p12=P1^2;
sbit p13=P1^3;
sbit p14=P1^4;
sbit p15=P1^5;
sbit p16=P1^6;
sbit p17=P1^7;
void delay(uint z);
int b[]={0,1,2,3,4,5,6,7};//设置每一位显示的数字
unsigned char code Tab[]={0xc0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,
0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};//共阳极数码管 int a[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
void main()
{
EA=1;
EX0=1;
IT0=1;
P1=0xff;
while(1)
{
for(c=0;c<8;c++)//数码管扫描显示
{
P2=a[c];
P0=Tab[b[c]];
delay (1);
}
}
}
void delay(uint z)
{
uint a,b;
for(a=z;a>0;a--)
for(b=110;b>0;b--);
}
int_0()interrupt 0