Arduino 用74HC595移位寄存器控制4位7段LED显示屏
我在尝试使用两个595移位寄存器在4位7seg显示器上输出数字时遇到问题 我已经到了正确显示数字的地步,但是我现在遇到了一个问题,即输出在显示的数字之间闪烁一些垃圾。如何防止这种情况发生 我很确定问题是,当我使用字节发送到寄存器时,它在显示的字节之间是锁存的 这是我的密码Arduino 用74HC595移位寄存器控制4位7段LED显示屏,arduino,shift-register,seven-segment-display,Arduino,Shift Register,Seven Segment Display,我在尝试使用两个595移位寄存器在4位7seg显示器上输出数字时遇到问题 我已经到了正确显示数字的地步,但是我现在遇到了一个问题,即输出在显示的数字之间闪烁一些垃圾。如何防止这种情况发生 我很确定问题是,当我使用字节发送到寄存器时,它在显示的字节之间是锁存的 这是我的密码 int latchPin = 5; int clockPin = 6; int dataPin = 4; int i = 0; int waitTime = 500; // digits from the right b
int latchPin = 5;
int clockPin = 6;
int dataPin = 4;
int i = 0;
int waitTime = 500;
// digits from the right
byte colDig[4] =
{
B00001000, // digit 1
B00000100, // digit 2
B00000010, // digit 3
B00000001, // digit 4
};
const byte digit[10] = //seven segment digits in bits
{
B11000000, // 0
B11111001, // 1
B10100100, // 2
B10110000, // 3
B10011001, // 4
B10010010, // 5
B10000010, // 6
B11111000, // 7
B10000000, // 8
B10011000, // 9
};
void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop()
{
// step through each digit then increment
// the counter by one, until nine
for(int j = 0;j<9;j++){
updateShiftRegister(0, j);
delay(waitTime);
updateShiftRegister(1, j);
delay(waitTime);
updateShiftRegister(2, j);
delay(waitTime);
updateShiftRegister(3, j);
delay(waitTime);
}
}
void updateShiftRegister(int col, int num)
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, colDig[col]);
shiftOut(dataPin, clockPin, MSBFIRST, digit[num]);
digitalWrite(latchPin, HIGH);
}
int-latchPin=5;
int时钟引脚=6;
int-dataPin=4;
int i=0;
int waitTime=500;
//右边的数字
字节colDig[4]=
{
B00001000,//数字1
B00000100,//数字2
B00000010,//数字3
B00000001,//数字4
};
常量字节数字[10]=//以位为单位的七段数字
{
B11000000,//0
B11111001,//1
B10100100,//2
B1011000,//3
B10011001,//4
B10010010,//5
B10000010,//6
B11111000,//7
B10000000,//8
B10011000,//9
};
无效设置()
{
引脚模式(锁定引脚,输出);
引脚模式(数据引脚,输出);
引脚模式(时钟引脚,输出);
}
void循环()
{
//逐级遍历每个数字,然后递增
//柜台一点开,一直到九点
对于(intj=0;j,看起来我是对的
移位功能在功能结束时将时钟引脚设置为低位,有效地强制锁存
通过稍微修改这个页面上的代码,我就能够阻止这种情况,现在它工作得非常完美。
//程序的核心
无效移位输出(int-myDataPin、int-myClockPin、byte-myDataOut){
//这会首先将8位移出MSB,
//在时钟上升的边缘,
//时钟低怠速
//内部功能设置
int i=0;
int pinState;
pinMode(myClockPin,输出);
pinMode(myDataPin,输出);
//把一切都清理干净,以防万一
//为位移位准备移位寄存器
数字写入(myDataPin,0);
数字写入(myClockPin,0);
//对于字节myDataOut中的每一位
//请注意,我们正在for循环中倒计时
//这意味着%00000001或“1”将通过此类
//这将是引脚Q0的灯。
对于(i=7;i>=0;i--){
数字写入(myClockPin,0);
//如果传递给myDataOut的值和位掩码结果
//如果我们在i=6,我们的值是
//%11010100代码会将其与%01000000进行比较
//并继续将pinState设置为1。
如果(myDataOut&(1)您能显示您的接线图吗?
// the heart of the program
void shiftItOut(int myDataPin, int myClockPin, byte myDataOut) {
// This shifts 8 bits out MSB first,
//on the rising edge of the clock,
//clock idles low
//internal function setup
int i=0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);
//clear everything out just in case to
//prepare shift register for bit shifting
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
//for each bit in the byte myDataOut
//NOTICE THAT WE ARE COUNTING DOWN in our for loop
//This means that %00000001 or "1" will go through such
//that it will be pin Q0 that lights.
for (i=7; i>=0; i--) {
digitalWrite(myClockPin, 0);
//if the value passed to myDataOut and a bitmask result
// true then... so if we are at i=6 and our value is
// %11010100 it would the code compares it to %01000000
// and proceeds to set pinState to 1.
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}
//Sets the pin to HIGH or LOW depending on pinState
digitalWrite(myDataPin, pinState);
//register shifts bits on upstroke of clock pin
digitalWrite(myClockPin, 1);
//zero the data pin after shift to prevent bleed through
digitalWrite(myDataPin, 0);
}
//stop shifting
//digitalWrite(myClockPin, 0);
}