Thursday, June 16, 2022

tinkercad 74HC595 shift register 1


void setup() 
{
  DDRD = 0b01110000;  //pin 4, 5, 6 output
  // arduino pin 4 connects to 74HC595 serial input pin
  // arduino pin 5 connects to 74HC595 output register clock pin
  // arduino pin 6 connects to 74HC595 shift register clock pin
  Serial.begin(9600);
}

void loop() 
{
  updateShiftRegister();
  delay(5000);
}

void updateShiftRegister()
{
   //digitalWrite(latchPin, LOW);
   PORTD = PIND & 0b11011111;
  
   //shiftOut(dataPin, clockPin, LSBFIRST, 0b10101010);
  byte data = random(0, 255);
  printBin(data);
  Serial.println();
  
  shiftOut(4, 6, MSBFIRST, data);
  
   //digitalWrite(latchPin, HIGH);
  PORTD = PIND | 0b00100000;
}

void printBin(byte aByte) {
  for (int8_t aBit = 7; aBit >= 0; aBit--)
    Serial.write(bitRead(aByte, aBit) ? '1' : '0');


printBin

No comments:

Post a Comment