HC595联级使用时要等全部数据传输完毕再发锁存信号。
- #include "reg51.h"
- #include<intrins.h>
- typedef unsigned int u16;
- typedef unsigned char u8;
- sbit SRCLK=P0^0;
- sbit RCLK=P0^2;
- sbit SER=P0^1;
- u8 code smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
- 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//显示0~F段码
- u8 code smgwela[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//位码
- void delay(u16 t)
- {
- while(t--);
- }
- void Hc595SendByte(u8 dat)
- {
- u8 a;
- // SRCLK=0;
- // RCLK=0;
- for(a=0;a<8;a++)
- {
- SER=dat>>7;
- SRCLK=1;
- _nop_();
- _nop_();
- SRCLK=0;
- dat<<=1;
- }
- // RCLK=1;
- // _nop_();
- // _nop_();
- // RCLK=0;
- }
- void main()
- {
- u8 i;
- SRCLK=0;
- RCLK=0;
- while(1)
- {
- for(i=0;i<8;i++)
- {
- Hc595SendByte(smgwela[i]);//先送位码
- Hc595SendByte(smgduan[i]);//后送段码
- RCLK=1; //锁存
- _nop_();
- _nop_();
- RCLK=0;
- delay(100);
- }
- }
- }
复制代码
|