Atmega328 i 4Digit 7-segmentowy duch miga!

Sep 13 2020

Podłączyłem 4 diody 7Seg (CC) z tranzystorami NPN na katodzie każdej cyfry. Używam rejestru przesuwnego 74HC595 podłączonego w obwodzie w dość powszechny sposób. Kod, który używam, jest podstawowym kodem do skanowania dla 7seg. Problem w tym, że zeskanowane numery widzę też na innych cyfrach diody. Załączony jest obraz. Nazywam je „duchami”. Obwód, którego używam, ma Atmega328 z wewnętrznym Osc 8 MHz. Rezystory na segmentach to 220Ohm i 4 BC547 na katodach cyfr z rezystorami 1kOhm na podstawie.

poniżej jest kod:

void loop () {
 
      cathode_high (); // wyczyść ekran
  
      break_number (liczba);
      
      display_number ();
     opóźnienie (1);

    
}

void break_number (int num) {// rozdziel wprowadzoną liczbę na 4 pojedyncze cyfry

  pierwsza_ cyfra = liczba / 1000;
  digits[0] = first_digit;  

  int first_left = num - (first_digit * 1000);
  second_digit = first_left / 100; 
  digits[1] = second_digit;
  int second_left = first_left - (second_digit * 100); 
  third_digit = second_left / 10; 
  digits[2] = third_digit; 
  fourth_digit = second_left - (third_digit * 10);
  digits[3] = fourth_digit;
  
  
}

void display_number() { //scanning
   
  cathode_high(); 
  digitalWrite(latch, LOW); 
  shiftOut(data, clk, LSBFIRST, numbers[digits[count]]); 
  digitalWrite(CAS[count], HIGH); 
  digitalWrite(latch, HIGH); 
  count++; 
  if (count == 4) {
    count = 0;
  }
}

void cathode_high() { //turn off all 4 digit
  digitalWrite(CA_1, LOW);
  digitalWrite(CA_2, LOW);
  digitalWrite(CA_3, LOW);
  digitalWrite(CA_4, LOW);
}

Any help would be highly appreciated. Thanx in advance!

Odpowiedzi

4 Gerben Sep 13 2020 at 20:37

You change cathodes (digits) before latching in the new data. So for a spit second the data for the previous digits is shown on the current digit.

Swapping digitalWrite(CAS[count], HIGH); and digitalWrite(latch, HIGH); should fix that.