classicsat

Dual 74HC595 multiplexed display

Feb 15th, 2022
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. // SV4000 panel counter. Salvaged from Sonicview SV4000 satellite receiver
  2. // Its heart is two 74HC595s. Both active low in this case, because Common Anode display (4 digits plus a few other LEDs)
  3. // Anodes driven to Vcc by PNP transistors, which are low to turn on. From first 595.
  4. // Cathodes directly driven by other 595, through resistors. Also low to light segments.
  5. // Keys scanned by same lines that drive the display anode transistors.
  6.  
  7. const byte keyinPin = 12;//Keyin pin
  8. const byte latchPin = 11;//Pin connected to ST_CP of 74HC595
  9. const byte dataPin = 10;//Pin connected to DS of 74HC595
  10. const byte clockPin = 9;//Pin connected to SH_CP of 74HC595
  11.  
  12. // shamelessly stolen from Elegoo example code for 74HC595 seven segment.
  13. byte seven_seg_digits[10] = { B11111100, // = 0
  14. B01100000, // = 1
  15. B11011010, // = 2
  16. B11110010, // = 3
  17. B01100110, // = 4
  18. B10110110, // = 5
  19. B10111110, // = 6
  20. B11100000, // = 7
  21. B11111110, // = 8
  22. B11100110 // = 9
  23. };
  24.  
  25. // 4 digit dual 595 multiplexed display
  26.  
  27. int counter=0;// main counter
  28. byte digit=0; // digit counter
  29. byte digit_array[8];
  30.  
  31. unsigned long previousMillis = 0;
  32. const long interval = 100;
  33.  
  34. void setup() {
  35. // put your setup code here, to run once:
  36. //Serial.begin(9600);
  37. pinMode(latchPin, OUTPUT);
  38. pinMode(dataPin, OUTPUT);
  39. pinMode(clockPin, OUTPUT);
  40. pinMode (keyinPin, INPUT);
  41. }
  42.  
  43. void loop() {
  44.  
  45. // output to display. One digit per go around. Key would be read here
  46. shiftdo(digit,digit_array[digit]);
  47. digit++;
  48. digit=digit&7;
  49.  
  50. // do what you want in the millis if
  51.  
  52. unsigned long currentMillis = millis();
  53.  
  54. if (currentMillis - previousMillis >= interval) {
  55. previousMillis = currentMillis;
  56.  
  57. // here it is a counter. Increment, cap, send to dosplay array
  58.  
  59. counter++;
  60. counter=counter&32767;
  61. inttoarray(counter);
  62.  
  63. } //close if curren Millis
  64.  
  65.  
  66. }//end of loop
  67.  
  68.  
  69. // send sunber to display array. Yeah, that is the easy way.
  70. // I couldn't figure the clever code to do it in a loop, and skip the colon digit spot.
  71. void inttoarray(int outnumber){
  72.  
  73. digit_array[0]=seven_seg_digits[(outnumber/1000)%10];// leftmost digit
  74. digit_array[1]=seven_seg_digits[(outnumber/100)%10];
  75. // digit 2 would be the colon/ dots not the 7 sements and their decimal pointss
  76. digit_array[3]=seven_seg_digits[(outnumber/10)%10];
  77. digit_array[4]=seven_seg_digits[outnumber%10];
  78. }
  79.  
  80. //output data to shift registers
  81. void shiftdo(byte a,byte b)
  82. {
  83.  
  84. digitalWrite(latchPin, LOW);
  85. shiftOut(dataPin, clockPin, MSBFIRST, ~(1<<a));// digit
  86. shiftOut(dataPin, clockPin, LSBFIRST, ~b);
  87. // segments LSBfirst because array is wrong endian for the way the display is wired
  88. // Easier thing to do.
  89. digitalWrite(latchPin, HIGH);
  90. }
  91.  
  92. // test to determine what display digit is each array location
  93. void arraytest(){
  94.  
  95. digit_array[0]=4;
  96. digit_array[1]=3;
  97. digit_array[3]=2;
  98. digit_array[4]=1;
  99. digit_array[5]=7;
  100. digit_array[6]=6;
  101. digit_array[7]=5;
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment