Arduino 74HC595 Çıkışları tek tek ayarlayamıyorum

Affansen

Katılımcı Üye
Katılım
15 Ocak 2021
Mesajlar
501
Puanları
56
74HC595 entegresini Arduino ile kullanıyorum. İnternetteki örneklere baktığım zaman örneklerde hep kayar led yapılmış. Kayar led uygulamaları başarıyla çalıştı ancak çıkışları tek tek kontrol edemedim.
C++:
int latchPin = 5;  // Latch pin of 74HC595 is connected to Digital pin 5
int clockPin = 6; // Clock pin of 74HC595 is connected to Digital pin 6
int dataPin = 4;  // Data pin of 74HC595 is connected to Digital pin 4

byte leds = 0;    // Variable to hold the pattern of which LEDs are currently turned on or off

/*
 * setup() - this function runs once when you turn your Arduino on
 * We initialize the serial connection with the computer
 */
void setup()
{
  // Set all the pins of 74HC595 as OUTPUT
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT); 
  pinMode(clockPin, OUTPUT);
}

/*
 * loop() - this function runs over and over again
 */
void loop()
{
  leds = 0; // Initially turns all the LEDs off, by giving the variable 'leds' the value 0
  updateShiftRegister();
  delay(500);
  for (int i = 0; i < 8; i++) // Turn all the LEDs ON one by one.
  {
    bitSet(leds, i);    // Set the bit that controls that LED in the variable 'leds'
    updateShiftRegister();
    delay(500);
  }
}

/*
 * updateShiftRegister() - This function sets the latchPin to low, then calls the Arduino function 'shiftOut' to shift out contents of variable 'leds' in the shift register before putting the 'latchPin' high again.
 */
void updateShiftRegister()
{
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, LSBFIRST, leds);
   digitalWrite(latchPin, HIGH);
}
 
8-bit bilgi yolluyorsunuz. Her defasınında
bu bitleri birleştirip bir byte yollayacaksınız.

Basit bir örnek:
Kod:
typedef struct {
   unsigned int d0:1;
   unsigned int d1:1;
   unsigned int d2:1;
   unsigned int d3:1;
   unsigned int d4:1;
   unsigned int d5:1;
   unsigned int d6:1;
   unsigned int d7:1;
} bit_a;

int main(void)
{
   bit_a bita_var;
   bita_var.d0 = 0b1;
   bita_var.d1 = 0b0;
   HC595_yaz(bita_var);
   return 0;
}
 
Son düzenleme:

Forum istatistikleri

Konular
128,191
Mesajlar
915,733
Kullanıcılar
449,965
Son üye
Pentium55

Yeni konular

Geri
Üst