位的选择最好在中断里实现较好
#define A0 P22
#define A1 P23
#define A2 P24
#define DISP P0
//共阴数码管显示段码
u8 code dispcode[] ={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,0x40};
u8 dispbuf[8]={0,1,2,3,4,5,6,7};
void time0() interrupt 1 using 1
{
static u8 wei; //wei用于位扫描
DISP=0; //消影
DISP=SHUZI[dispbuf[wei]]; //显示缓冲区数据依次显示
switch(wei)
{
case 0:A2=1;A1=1;A0=1;break;
case 1:A2=1;A1=1;A0=0;break;
case 2:A2=1;A1=0;A0=1;break;
case 3:A2=1;A1=0;A0=0;break;
case 4:A2=0;A1=1;A0=1;break;
case 5:A2=0;A1=1;A0=0;break;
case 6:A2=0;A1=0;A0=1;break;
case 7:A2=0;A1=0;A0=0;break;
}
wei++;
wei%=8; //m在0-7之间变化
}
TH0 TL0改为
TH0=0xF8;
TL0=0XCD; //11.0592MHZ 或0x30 对应12MHz
主程序只需要:
while(1)
{
;
} |