关于595芯片IO口拓展应用
- #include <REGX52.H>
- #include <INTRINS.H>
- sbit sh_cp=P2^0;
- sbit ds=P2^1;
- sbit st_cp=P2^2;
- unsigned char table[5]; //定义四个595的变量缓存
- void delayms(unsigned char xms)
- {
- unsigned char i;
- while(--xms)for(i=250;i>0;i--);
- }
- unsigned char table[5]; //定义四个595的变量缓存
- void datout(unsigned char add,dat) //595输出函数,一次输出16位 add595选择,dat数据
- {
- unsigned char i,j,temp;
- table[add]=dat;
- for(j=0;j<5;j++) //一次输出四个值
- {
- temp=table[j];
- for(i=0;i<8;i++)
- {
- temp=temp<<1;
- sh_cp=0;
- ds=CY;
- sh_cp=1;
- }
- }
- st_cp=0;
- st_cp=1;
- }
- void main()
- {
- while(1)
- {
- datout(0,8);//第一个595 输出8 0x08
- datout(1,7);//第二个595 输出7 0x07
- datout(2,6);//第三个595 输出6 0x06
- datout(3,5);//第四个595 输出5 0x05
- datout(4,0x0c);//第五个595 输出4 0x0c
- delayms(1);
- //要改变某个595输出结果就改变数组中对应的值就可以了
- }
- }
复制代码
所有资料下载:
595应用.rar
(31.87 KB, 下载次数: 32)
|