电路很简单,从程序中可以看出来,我就不画了.
- #include
- #define uchar unsigned char
- #define led P1
- bit flag=0;
- uchar code lshift[3]={0x07,0x03,0x01};
- uchar code shift[7]={0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe};
- //imitate PWM data
- uchar code sta0[100]={ 0x0f,0x8f,0x8f,0x8f,0x8f,0x8f,0x8f,0x8f,0x8f,0x8f,
- 0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,
- 0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,
- 0xcf,0xcf,0xcf,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
- 0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
- 0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
- 0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
- 0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
- 0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
- 0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef
- };
- //functions statement
- void delay(uchar ms);
- uchar exchg(uchar dat);
- //main function
- void main()
- {
- uchar i,j,k,x,sdata;
- while(1)
- {
- for(k=1;k<8;k++)
- for(i=0;i<22;i++)
- for(j=0;j<100;j++)
- {
- sdata=(sta0[j]>>k)|shift[k-1];
- if(flag==1) led=exchg(sdata);
- else led=sdata;
- }
- for(x=1;x<4;x++)
- for(i=0;i<22;i++)
- for(j=0;j<100;j++)
- {
- sdata=( sta0[j]<<(4-x) )|lshift[x-1];
- if(flag==1) led=exchg(sdata);
- else led=sdata;
- }
- }
- }
- void delay(uchar ms)
- {
- uchar n;
- while(ms--)
- {
- for(n=125;n>0;n--);
- }
- }
- uchar exchg(uchar dat) //对字节的高位和低位进行互换!
- {
- uchar temp;
- temp=
- ((dat&0x01)<<7)|
- ((dat&0x02)<<5)|
- ((dat&0x04)<<3)|
- ((dat&0x08)<<1)|
- ((dat&0x10)>>1)|
- ((dat&0x20)>>3)|
- ((dat&0x40)>>5)|
- ((dat&0x80)>>7);
- return temp;
- }
|