This is an old revision of the document!
Necessary knowledge: [HW] User Interface Module, [LIB] Delay, [LIB] 7-segment LED Display, [PRT] Light-emitting Diode
Der 7-Segment-LED-Indikator ist ein Display, dass aus sieben LED´s, die in Form einer acht positioniert sind, besteht. Beim An- oder Ausschalten der entsprechenden LED´s (Segmente) ist es möglich Zahlen von 0-9 wie auch einige Buchstaben darzustellen.
Elektrisch werden alle Anoden der LED zu einer Anode am Pin ca angeschlossen. LEd´s werden durch das Schalten ihrer Kathoden (a, b, c …).
Electrically all anodes of the LEDs are connected to one anode pin ca. LEDs are lit by switching their cathodes (a, b, c…). Exists also reversed connections, where the indicators have a common cathode cc. Generally several number-indicators are used for displaying multi digit numbers - for this purpose the indicators are equipped with coma (point) segment dp. All in all one indicator has 8 segments, but they are still called 7-segmented according to the number of number-segments.
LED number-indicators are easy to use, they can be controlled directly from the pins of the microcontroller, but there are also special drivers, which able to control number-indicators using fewer pins of the microcontroller. There are different colors of LED number indicators, which can be very bright and very large. For displaying the entire Latin alphabet exist indicators with extra segments.
Es gibt einen 7-Segment-LED-Indikator am digitalen I/O Modul. Es wird über einen Treiber mit dem seriellen Interface A6275 kontrolliert. Das serielle Interface des Treibers ist dem SPI ähnlich, wo sowohl Taktsignal als auch Datensignale genutzt werden. Anders als beim SPI wird chip-select nicht genutzt und wird durch die latch Funktion ersetzt.Es ist mit dem ATmega128 wie folgt verbunden:
Die Daten werden per Bits durch den Datenpin gesendet. Jedes mal wenn das Taktsignal High ist wird der Inhalt des Shift-Indexes nach rechts geschoben und der Bit vom Datenpin wird in die Zelle ganz links gelesen. So werden 8 Bits in den Shift Index geladen. Wenn das Latch-Signal high gesetzt ist wird der Wert des Shift-Indexes in den Latch-Index geladen, wo es bis zu einem erneuten Laden verbleibt. Jedes Bit des Latch-Indexes ist durch eine Spannungsschaltung mit einem Segment eines Indikators verbunden. Das Segment leuchtet während die Bitrate high ist.
Um Nummern an dem HomeLab digitalen I/O Modul Indikator darzustellen sind die folgenden Funktionen in der Library von HomeLab enthalten.
// // Set-up of the pins // static pin segment_display_latch = PIN(G, 2); static pin segment_display_data_out = PIN(C, 6); static pin segment_display_clock = PIN(C, 7); // // Marking card. // The bits are marking the segments. Lower ranking is A, higher ranking is DP. // static const unsigned char segment_char_map[11] = { 0b00111111, 0b00000110, 0b01011011, 0b01001111, 0b01100110, 0b01101101, 0b01111100, 0b00000111, 0b01111111, 0b01100111, 0b01111001 // E like Error }; // // Start-up of the 7-segment indicator. // void segment_display_init(void) { // Set latch, data out and clock pins as output pin_setup_output(segment_display_latch); pin_setup_output(segment_display_data_out); pin_setup_output(segment_display_clock); } // // Displaying number on the 7-segment indicator. // void segment_display_write(unsigned char digit) { unsigned char map; signed char i; // Check-up of the number if (digit > 9) { digit = 10; } // Number as the card of the segments. map = segment_char_map[digit]; // Latch-signal off pin_clear(segment_display_latch); // Sending he bits. Higher ranking goes first. for (i = 7; i >= 0; i--) { // Setting the pin according to the value of the bit of the card. pin_set_to(segment_display_data_out, bit_is_set(map, i)); // The clock-signal as high for a moment. pin_set(segment_display_clock); _delay_us(1); // The clock-signal as low. pin_clear(segment_display_clock); _delay_us(1); } // Latch-signal on. pin_set(segment_display_latch); }
Um Nummern und den Buchstaben “E” darzustellen, wird ein konstantes Array segment_char_map erstellt, wo das Leuchten von allen acht Segmenten mit Bit 1 markiert wird und wenn es ausgeschaltet ist mit einem Bit 0 markiert wird.
For displaying numbers and the letter “E”, is created a constant array segment_char_map, where lighting of all 8 segments is marked with bit 1 and switch off is market with bit 0. The bits form higher to lower (from left to right in binary form) are marking segments DP, G, F, E, D, C, B, A. The control interface of the driver is realized through software SPI, i.e. by using a software for controlling the data communication pins in the program. All three pins are set as output with segment_display_init function. segment_display_write is for displaying the function, which finds the segment-card of the mark from the array and transmits bit by bit all values of the segments to the driver. The frequency of the clock signal with the software delays is now approximately 500 kHz.
The following is a more concrete example of a program for using the number-indicator. Previously described function of the library is described in the program. The program counts numbers from 0 to 9 with approximate interval of 1 second. Such counting is achieved by taking a module from a much larger number.
// // The example program of the 7-segment LED indicator of the HomeLab's // input-output module. // #include <homelab/module/segment_display.h> #include <homelab/delay.h> // // Main program. // int main(void) { int counter = 0; // Set-up of the 7-segment indicator. segment_display_init(); // Endless loop. while (true) { // Displaying the ones values of the counter. segment_display_write(counter % 10); // Counting very long. counter++; // Delay for 1 second. sw_delay_ms(1000); } }