I'm using a 74HC595 shift register to control a 7 segment display. I'm having issue with the 1, 4, 7, and 8 displaying right. I have went through each one to test them alone and they work just find. Just when I run it in an array is when they mess up. This is how its setup up when I turn each pin on one at a time. I'm not using Q0 on the chip just Q1-7.
F=1 A=2 B=3 C=4 D=5 E=6 G=7
for 1 it light up F,B,C
for 4 it light up B,G,C
for 7 it light up F,A,B,C
for 8 it light up A,B,C,D,E,G
int dataPin = 11;
int clockPin = 12;
int latchPin = 8;
byte data;
byte dataArray[9];
void setup() {
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
//Using Hex decimal
dataArray[0] = 0x7E; //0111 1110 - 0
dataArray[1] = 0x18; //0001 1000 - 1
dataArray[2] = 0xEC; //1110 1100 - 2
dataArray[3] = 0xBC; //1011 1100 - 3
dataArray[4] = 0x9A; //1001 1010 - 4
dataArray[5] = 0xB6; //1011 0110 - 5
dataArray[6] = 0xF2; //1111 0010 - 6
dataArray[7] = 0x1C; //0001 1100 - 7
dataArray[8] = 0xFE; //1111 1110 - 8
}
void loop() {
for (int i = 0; i<9; i++)
{
data = dataArray[i];
//ground latchPin and hold low for as long as you are transmitting
digitalWrite(latchPin, 0);
//move 'em out
shiftOut(dataPin, clockPin, data);
//return the latch pin high to signal chip that it
//no longer needs to listen for information
digitalWrite(latchPin, 1);
delay(300);
delay(1000);
}
}
// the heart of the program
void shiftOut(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);
}