由於我用的是普中幵發板, 所以有少許修改, 並將顯示做到無縫連續顯示, 不會顯 6789後馬上變為0123
#include <REG52.H>
sbit LSA = P1^0;
sbit LSB = P1^1;
sbit LSC = P1^2;
unsigned char SMG[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xc0,0xf9,0xa4,0xb0};
void Delay(unsigned int xms)
{
unsigned char i, j;
while(xms--)
{
i = 2;
j = 239;
do
{
while (--j);
} while (--i);
}
}
void led (unsigned char Location,Number)
{
switch(Location)
{
case 1: LSA = 0; LSB = 0; LSC = 0; break;
case 2: LSA = 1; LSB = 0; LSC = 0; break;
case 3: LSA = 0; LSB = 1; LSC = 0; break;
case 4: LSA = 1; LSB = 1; LSC = 0; break;
}
P0=~SMG[Number];
Delay(1);
P0=0x00;
}
void main()
{
unsigned int i,j;
while(1)
{
i=0;
for(i=0;i<10;i++)
{
for(j=0;j<100;j++)
{
led(1,i+0);
led(2,i+1);
led(3,i+2);
led(4,i+3);
}
}
}
}
|