#include <reg52.h>
char code segcode[]={0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90}; //共陽段碼
char code secWcode[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; //位碼
void delay(int del) //延時1ms
{
int i,j;
for(i=0;i<del;i++)
for(j=0;j<110;j++);
}
main()
{
unsigned int a,b;
while(1)
{
for(a=0;a<16;a++)
{
for(b=0;b<1000;b++) //
{
P1=0xff; //關閉段碼
P2=~secWcode[0]; // 驅動共陽位碼
P1=segcode[a]; //驅動段碼
delay(1); //適當延時
}
}
}
}
|