This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:examples:display:segment_display [2010/04/13 07:29] – raivo.sell | en:examples:display:segment_display [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | < | ||
| ====== 7-segment LED display ====== | ====== 7-segment LED display ====== | ||
| - | //Necessary knowledge: [HW] [[en: | + | //Necessary knowledge: |
| + | [HW] [[en: | ||
| + | [LIB] [[en: | ||
| + | [PRT] [[en: | ||
| ===== Theory ===== | ===== Theory ===== | ||
| + | |||
| + | [{{ : | ||
| 7-segmented LED number-indicator is a display which consists of 7 LEDs positioned in the shape of number 8. By lighting or switching off the corresponding LEDs (segments), it is possible to display numbers from 0 to nine as well as some letters. | 7-segmented LED number-indicator is a display which consists of 7 LEDs positioned in the shape of number 8. By lighting or switching off the corresponding LEDs (segments), it is possible to display numbers from 0 to nine as well as some letters. | ||
| - | |||
| - | [{{ : | ||
| 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, | 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, | ||
| - | LED number-indicators are easy to use, they can be controlled directly from the pins of the microcontroller, | + | [{{ : |
| - | + | ||
| - | ===== Practice ===== | + | |
| - | + | ||
| - | There is one 7-segment | + | |
| [{{ : | [{{ : | ||
| - | * Latch-signal (// | + | LED number-indicators are easy to use, they can be controlled directly from the pins of the microcontroller, |
| - | * Clock-signal (//clock//) - PC7 | + | |
| - | * Data-signal | + | |
| - | ~~CL~~ | + | * Latch-signal |
| + | * Clock-signal | ||
| + | * Data-signal | ||
| - | The data is delivered by bits through the data pin. Every time the clock signal goes high, the contents of the shift-index is shifted to the right and the bit from the data-pin is read to the left most cell. By this 8-bits are loaded to the shift-index. If the latch signal is set high, the value of the shift-index is loaded to the latch-index, | + | ===== Practice ===== |
| - | For displaying the numbers on the HomeLabs Digital module indicator, the following functionality is written to the library of the HomeLab. | + | There is one 7-segment LED number-indicator on the Digital i/o module. It is controlled through a driver with serial interface. |
| + | For displaying the numbers on the HomeLabs Digital | ||
| <code c> | <code c> | ||
| - | // | + | // Marking card |
| - | // Set-up of the pins | + | // The bits are marking the segments. Lower ranking is A, higher ranking is DP |
| - | // | + | const unsigned char __attribute__ ((weak)) |
| - | 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 | + | |
| { | { | ||
| 0b00111111, | 0b00111111, | ||
| Line 57: | Line 48: | ||
| }; | }; | ||
| - | // | + | // Start-up of the 7-segment indicator |
| - | // Start-up of the 7-segment indicator. | + | |
| - | // | + | |
| void segment_display_init(void) | void segment_display_init(void) | ||
| { | { | ||
| Line 68: | Line 57: | ||
| } | } | ||
| - | // | + | // Displaying number on the 7-segment indicator |
| - | // Displaying number on the 7-segment indicator. | + | |
| - | // | + | |
| void segment_display_write(unsigned char digit) | void segment_display_write(unsigned char digit) | ||
| { | { | ||
| Line 82: | Line 69: | ||
| } | } | ||
| - | // Number as the card of the segments. | + | // Number as the card of the segments |
| map = segment_char_map[digit]; | map = segment_char_map[digit]; | ||
| Line 88: | Line 75: | ||
| pin_clear(segment_display_latch); | pin_clear(segment_display_latch); | ||
| - | // Sending he bits. Higher ranking goes first. | + | // Sending he bits. Higher ranking goes first |
| for (i = 7; i >= 0; i--) | for (i = 7; i >= 0; i--) | ||
| { | { | ||
| - | // Setting the pin according to the value of the bit of the card. | + | // Setting the pin according to the value of the bit of the card |
| pin_set_to(segment_display_data_out, | pin_set_to(segment_display_data_out, | ||
| - | // The clock-signal as high for a moment. | + | // The clock-signal as high for a moment |
| pin_set(segment_display_clock); | pin_set(segment_display_clock); | ||
| _delay_us(1); | _delay_us(1); | ||
| - | // The clock-signal as low. | + | // The clock-signal as low |
| pin_clear(segment_display_clock); | pin_clear(segment_display_clock); | ||
| _delay_us(1); | _delay_us(1); | ||
| } | } | ||
| - | // Latch-signal on. | + | // Latch-signal on |
| pin_set(segment_display_latch); | pin_set(segment_display_latch); | ||
| } | } | ||
| </ | </ | ||
| - | For displaying numbers and the letter “E”, is created a constant array // | + | For displaying numbers and the letter “E”, is created a " |
| - | The following is a more concrete example of a program for using the number-indicator. | + | The following is a more concrete example of a program for using the number-indicator. |
| <code c> | <code c> | ||
| - | // | ||
| // The example program of the 7-segment LED indicator of the HomeLab' | // The example program of the 7-segment LED indicator of the HomeLab' | ||
| - | // input-output module. | ||
| - | // | ||
| #include < | #include < | ||
| #include < | #include < | ||
| - | // | + | // Main program |
| - | // Main program. | + | |
| - | // | + | |
| int main(void) | int main(void) | ||
| { | { | ||
| int counter = 0; | int counter = 0; | ||
| - | // Set-up of the 7-segment indicator. | + | // Set-up of the 7-segment indicator |
| segment_display_init(); | segment_display_init(); | ||
| - | // Endless loop. | + | // Endless loop |
| while (true) | while (true) | ||
| { | { | ||
| - | // Displaying the ones values of the counter. | + | // Displaying the values of the counter |
| segment_display_write(counter % 10); | segment_display_write(counter % 10); | ||
| - | // Counting | + | // Counting |
| counter++; | counter++; | ||
| + | if (counter> | ||
| - | // Delay for 1 second. | + | // Delay for 1 second |
| sw_delay_ms(1000); | sw_delay_ms(1000); | ||
| } | } | ||
| } | } | ||
| </ | </ | ||