原理图:
- #include<reg52.h>
- #include<intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar t;
- sbit latch=P3^0;//DS
- sbit srclk=P1^0;// SHCP
- sbit ser=P3^1;//STCP
- uchar code table[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,
- ~0xfe,~0xfd,~0xfb,~0xf7,~0xef,~0xdf,~0xbf,~0x7f,
- 0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
- void delay(uint z)
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
-
- void send(uchar dat)
- {
- uchar i;
- srclk=0; //SHCP
- for(i=0;i<24;i++)
- {
- if((dat&0x80)==0x00)
- ser=1;
- else
- ser=0;
- srclk=1;
- dat=dat<<1;
- }
- latch=1; //STCP
- delay(1);
- latch=0;
- }
- void main()
- {
- while(1)
- {
- for(t=0;t<24;t++)
- {
- send(table[t]);
- delay(200);
- }
- latch=1;
- }
- }
复制代码
|