wulin 发表于 2020-9-5 20:38 ![]() |
wulin 发表于 2020-9-5 20:38 十分感谢!加了初始化以后,完全避免了输出不是想要输出的问题了 |
感谢。 |
缺少 SCK = 0; RCK = 0; 初始化设置,其它没有问题。 #include<reg51.h> #include<intrins.h> typedef unsigned char uchar; typedef unsigned int uint; /**********函数声明********************/ void SendTo595(uchar byteData); /***********************************/ sbit SER = P3^4; //p3.4脚控制串行数据输入 sbit SCK = P3^6; //串行输入时钟 sbit RCK = P3^5; //存储寄存器时钟 void main() { char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; SCK = 0; RCK = 0; SendTo595(table[0]); SendTo595(table[1]); SendTo595(table[2]); SendTo595(table[3]); SendTo595(table[4]); SendTo595(table[5]); SendTo595(table[6]); SendTo595(table[7]); SendTo595(table[8]); SendTo595(table[9]); /*位移寄存器数据准备完毕,转移到存储寄存器*/ RCK = 1; //上升沿,让存储寄存器时钟变为高电平,并延时2个时钟周期 _nop_(); _nop_(); RCK = 0; while(1); } //功能:发送一个字节的数据给595,再并行输出 void SendTo595(uchar byteData) { char i=0; for(;i<8;i++) { SER = byteData>>7; byteData= byteData<<1; SCK = 1; //上升沿,让串行输入时钟变为高电平,并延时2个时钟周期 _nop_(); _nop_(); SCK = 0; //变为低电平,为下次准备 } } |