#include <regx51.h>
unsigned char code table1[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char code table2[]={0x7f,0xbf};
unsigned char table3[2];
int count=0;
unsigned char i=0;
/********************Delay func
tion************************/
void delay(unsigned int t)
{
unsigned char i=250;
while(t--)while(i--);
}
/**********************Display function********************/
void smg( int count) //数码管显示2位数字
{
table3[0]=count%10;
table3[1]=count/10;
P3= table2[i];
P0=table1[table3[i]]; //送出段选数据
delay(20);
i++; //扫描指针加计数
if(i==2)
i=0 ;
}
/**********************Main function*************************/
void main()
{
count=0;
P0=0x00;
while(1)
{
smg(count);
count++;
if(count==100) //循环计数
count=0;
}
}
{
table3[0]=count%10;
table3[1]=count/10;
P3= table2[i];
P0=table1[table3[i]]; //送出段选数据
delay(20);
i++;
P3= table2[i];
P0=table1[table3[i]]; //送出段选数据
delay(20);
i=0 ;
}这样改试试看
一周热门 更多>