|
发表于 2013-4-2 16:50:55
|
显示全部楼层
求解关于74HC595的疑惑
做了以下实验,可是不知为什么子要把手指放到靠近capacitor(电容) 上端16个LED灯就会一个一个的亮起来然后熄灭。手指不靠近时LED灯就不亮
电路图
Arduino 代码:
//Shift Regidter Example for two 74HC595 shift register
//this sketch turns on each of the LEDs attached to two 74HC595 shift register, in sequence from output 0 to output 15.
const int latchPin = 4;
const int clockPin = 5;
const int dataPin = 2;
void setup()
{
//set pins to output because they are address in the main loop
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
Serial.begin(9600);
Serial.println("resent");
}
void loop() {
// iterate over the 16 outputs of the two shift registers
for (int thisLed = 0; thisLed < 16; thisLed++) {
// write data to the shift registers:
registerWrite(thisLed, HIGH);
// if this is not the first LED, turn off the previous LED:
if (thisLed > 0) {
registerWrite(thisLed - 1, LOW);
}
// if this is the first LED, turn off the highest LED:
else {
registerWrite(15, LOW);
}
// pause between LEDs:
delay(500);
}
}
// This method sends bits to the shift registers:
void registerWrite(int whichPin, int whichState) {
// the bits you want to send. Use an unsigned int,
// so you can use all 16 bits:
unsigned int bitsToSend = 0;
// turn off the output so the pins don't light up
// while you're shifting bits:
digitalWrite(latchPin, LOW);
// turn on the next highest bit in bitsToSend:
bitWrite(bitsToSend, whichPin, whichState);
// break the bits into two bytes, one for
// the first register and one for the second:
byte registerOne = highByte(bitsToSend);
byte registerTwo = lowByte(bitsToSend);
// shift the bytes out:
shiftOut(dataPin, clockPin, MSBFIRST, registerTwo);
shiftOut(dataPin, clockPin, MSBFIRST, registerOne);
// turn on the output so the LEDs can light up:
digitalWrite(latchPin, HIGH);
}
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|