- #include <REG51.H>
- #define uchar unsigned char
- #define uint unsigned int
- uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};
- uchar code wei[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
- void delay(uint x)
- {
- uint i,j;
- for(i=0;i<x;i++)
- for(j=0;j<111;j++);
- }
- void main(void)
- {
- uchar i,k;
- uint j;
- while(1)
- {
- P1=0x00;//段消隱
- P0=wei[i];//送位碼
- P1=table[i];//送段碼
- i=++i%8;//8位動態顯示計數
- if(++j>=1000)//約1秒
- {
- j=0;
- table[16]=table[0];
- for(k=0;k<16;k++)//數組循環排序
- table[k]=table[k+1];
- }
- delay(1);
- }
- }
復制代碼
|