给你写了一个示例参考
595驱动LED仿真.zip
(103.94 KB, 下载次数: 27)
- #include<REG51.H>
- sbit Sh=P2^0;
- sbit Ds=P2^1;
- sbit St=P2^2;
- unsigned char a1=0xff,b1=0xff,c1=0xff,d1=0xff,e1=0xfe;
- void DelayMS(unsigned int ms)
- {
- unsigned char i;
- while(ms--)
- for(i=0;i<120;i++);
- }
- void In_Data(unsigned char a,b,c,d,e)
- {
- unsigned char i,j,k;
- for(i=0;i<5;i++)
- {
- if(i==0)k=a;
- if(i==1)k=b;
- if(i==2)k=c;
- if(i==3)k=d;
- if(i==4)k=e;
- for(j=0;j<8;j++)
- {
- k<<=1;
- Ds=CY;
- Sh=0;
- Sh=1;
- }
- }
- St=0;
- St=1;
- }
- void main()
- {
- while(1)
- {
- In_Data(a1,b1,c1,d1,e1);
- DelayMS(500);
- if(e1!=0xff)
- {
- e1=e1<<1|0x01;
- if(e1==0xff)
- d1=0xfe;
- }
- else if(d1!=0xff)
- {
- d1=d1<<1|0x01;
- if(d1==0xff)
- c1=0xfe;
- }
- else if(c1!=0xff)
- {
- c1=c1<<1|0x01;
- if(c1==0xff)
- b1=0xfe;
- }
- else if(b1!=0xff)
- {
- b1=b1<<1|0x01;
- if(b1==0xff)
- a1=0xfe;
- }
- else if(a1!=0xff)
- {
- a1=a1<<1|0x01;
- if(a1==0xff)
- e1=0xfe;
- }
- }
- }
复制代码
|