本文章详细写了数码管的静态显示,从第一个数码管到第八个数码管每个数码管依次显示0~9,时间间隔1000毫秒。详见代码。
#include<STC15F2K60S2.H>
#include<intrins.h>
unsigned char code a[18]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x80,0xc6,0x86,0x8e,0xbf,0x7f};
unsigned char m,n;
void Delay1000ms() //@12.000MHz
{
unsigned char data i, j, k;
_nop_();
_nop_();
i = 46;
j = 153;
k = 245;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void HC138(unsigned char channel)
{
switch(channel)
{
case 4: P2=P2&0x1f|0x80;break;
case 5: P2=P2&0x1f|0xa0;break;
case 6: P2=P2&0x1f|0xc0;break;
case 7: P2=P2&0x1f|0xe0;break;
case 8: P2=P2&0x1f;break;
}
}
void SMG(unsigned char dat,unsigned char pos)
{
HC138(6);
P0=0x01<<pos;
HC138(8);
HC138(7);
P0=dat;
HC138(8);
}
void smg()
{
for(m=0;m<8;m++)
{
for(n=0;n<10;n++)
{
SMG(a[n],m);
Delay1000ms();
}
}
}
void main()
{
P2=P2&0x1f|0x80;
P0=0xff;
P2=P2&0x1f;
P2=P2&0x1f|0xa0;
P0=0x00;
P2=P2&0x1f;
while(1)
{
smg();
}
}