Go Down

Topic: 7-Segment Display Wiring and Programming (Read 66 times) previous topic - next topic

guitarboy667

Right, I switched those somehow. The code you mentioned had a latch pin, so I don't think it will work.

So I send in the 8 bits through SRCK? I thought that was what SER IN did. I can try writing some code once I figure out what information each input needs sent.

Sorry this is taking so long. I appreciate your help. I was sent this site:
http://arduino.cc/en/Tutorial/ShiftOut
and I tried to use that but it seems to be about the other shift register configuration that uses a latch pin. Both shift registers are 595s though.


CrossRoads

You'll need something like this:

Code: [Select]

shiftOut(shiftdatapin, shiftclockpin, MSBFIRST, shiftregdata); // puts the bits into the input register
digitalWrite (RCK, LOW);
digitalWrite (RCK, HIGH); // puts the bits into the output register.


where shiftdatapin connects to SER IN,
shiftclockpin connects to SRCK.
MSBFIRST says bit 7 of your data is going out first,
and shiftregdata is your segment data (bit 0-7 representing segments A-G & DP for example).
595 has lots if variations. Need to read the datasheets and wire accordingly.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

guitarboy667

Wow that works great! Thanks!

Do you know how I could get the code to interpret numbers into bytes that needs to be sent?

Code: [Select]
int shiftdatapin = 48;
int shiftclockpin = 50;
int RCK = 52;

byte numbers[10] =
{
 B00111111, // 0
 B00000110, // 1
 B01010011, // 2
 B01001111, // 3
 B01100110, // 4
 B01101101, // 5
 B01111101, // 6
 B00000111, // 7
 B01111111, // 8
 B01101111  // 9
};

void setup() {
 //set pins to output so you can control the shift register
 pinMode(shiftdatapin, OUTPUT);
 pinMode(shiftclockpin, OUTPUT);
 pinMode(RCK, OUTPUT);
}

void loop() {
shiftOut(shiftdatapin, shiftclockpin, MSBFIRST, B01111111); // puts the bits into the input register
digitalWrite (RCK, LOW);
digitalWrite (RCK, HIGH); // puts the bits into the output register.

}


The above code works, but I'd like to be able to put a variable into the code instead of B01111111.

Would the above code work for multiple digits too?  For example, could I send 1493 to a string of 4 digits of the display and it'd work or do I have to somehow separate 1493 into individual numbers and send them out?

CrossRoads

#38
Jan 19, 2011, 05:11 am Last Edit: Jan 19, 2011, 05:12 am by CrossRoads Reason: 1
Easy question first : 1493. Do you have 4 shift registers connected together, so that the output of one feeds the input of 2, two's output feeds 3's input, etc?
If so, you can just do 4 shiftouts in a row. If not, do 4 shiftouts to the individually controlled registers.  Shiftout is a software feature, pretty similar to:
digitalWrite (pin, bit0);
digitalWrite (clock low);
digitalWrite (clock, high);
//repeat 7  times for bit1, bit2, ...bit7.
You can also do a hardware controlled shiftout that would go faster using SPI, but you have to use specific pins for it. Go do some reading about it.
Code: [Select]

shiftregdata = byte1;
shiftOut(shiftdatapin, shiftclockpin, MSBFIRST, shiftregdata); // puts the bits into the input register
digitalWrite (RCK, LOW);
digitalWrite (RCK, HIGH); // puts the bits into the output register.
shiftregdata =  byte2;
shiftOut(shiftdatapin, shiftclockpin, MSBFIRST, shiftregdata); // puts the bits into the input register
digitalWrite (RCK, LOW);
digitalWrite (RCK, HIGH); // puts the bits into the output register.
shiftregdata  = byte3;
shiftOut(shiftdatapin, shiftclockpin, MSBFIRST, shiftregdata); // puts the bits into the input register
digitalWrite (RCK, LOW);
digitalWrite (RCK, HIGH); // puts the bits into the output register.
shiftregdata  = byte4;
shiftOut(shiftdatapin, shiftclockpin, MSBFIRST, shiftregdata); // puts the bits into the input register
digitalWrite (RCK, LOW);
digitalWrite (RCK, HIGH); // puts the bits into the output register.

now, making bytex= numbers
  • , maybe something like this:
    shiftregdata[1] = numbers[ones_seconds];
    shiftregdata[2] = numbers[tens_seconds];
    shiftregdata[3] = numbers[ones_hours];
    shiftregdata[4] = numbers[tens_hours];

    and the 4 shifts above could be pulled into a loop? Defined as:
    for (initialization; condition; increment) {
    //statement(s);
    }

    This loop should do 4 shiftouts, fancier than anything I've tried yet:

    Code: [Select]

    //for (x=1 to 4)
    for (x=0;  x<5; x=x+1;){  //maybe x==4, and x++ instead x=x+1?? x=x+1 is clearer (to me). Try it.
    shiftOut(shiftdatapin, shiftclockpin, MSBFIRST, shiftregdata[x]); // load input register
    digitalWrite (RCK, LOW);
    digitalWrite (RCK, HIGH); // load output register.
    //Serial.writeln shiftregdata[x];  // to make sure
    }

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

guitarboy667

I have 4 in a row, but the second data input seems to just overwrite the first.

Code: [Select]
int shiftdatapin = 48;
int shiftclockpin = 50;
int RCK = 52;
int shiftregdata;

byte numbers[10] =
{
 B00111111, // 0
 B00000110, // 1
 B01010011, // 2
 B01001111, // 3
 B01100110, // 4
 B01101101, // 5
 B01111101, // 6
 B00000111, // 7
 B01111111, // 8
 B01101111  // 9
};

void setup() {
 //set pins to output so you can control the shift register
 pinMode(shiftdatapin, OUTPUT);
 pinMode(shiftclockpin, OUTPUT);
 pinMode(RCK, OUTPUT);
}

void loop() {
shiftregdata =  B00000111;
shiftOut(shiftdatapin, shiftclockpin, MSBFIRST, shiftregdata); // puts the bits into the input register
digitalWrite (RCK, LOW);
digitalWrite (RCK, HIGH); // puts the bits into the output register.
shiftregdata =  B00000111;
shiftOut(shiftdatapin, shiftclockpin, MSBFIRST, shiftregdata); // puts the bits into the input register
digitalWrite (RCK, LOW);
digitalWrite (RCK, HIGH); // puts the bits into the output register.

}

Go Up