Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:examples:display:segment_display [2015/11/05 10:41] heikopikneren:examples:display:segment_display [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
-~~PB~~+<pagebreak>
 ====== 7-segment LED display ====== ====== 7-segment LED display ======
  
-//Necessary knowledge: [HW] [[en:hardware:homelab:digi]], [LIB] [[en:software:homelab:library:delay]], [LIB] [[en:software:homelab:library:module:segment_display]][PRT] [[en:examples:digi:led]]//+//Necessary knowledge:  
 +[HW] [[en:hardware:homelab:digi]],  
 +[LIB] [[en:software:homelab:library:module:segment_display]], \\ [LIB] [[en:software:homelab:library:delay]]  
 +[PRT] [[en:examples:digi:led]]//
  
 ===== Theory ===== ===== Theory =====
Line 15: Line 18:
 [{{  :examples:display:segment_display:segment_display_driver_logic.png?300|The build-up of the LED driver's shift-index with corresponding segments of the indicator.}}] [{{  :examples:display:segment_display:segment_display_driver_logic.png?300|The build-up of the LED driver's shift-index with corresponding segments of the indicator.}}]
  
-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.  +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. There are different drivers, but common drivers using a serial interface, which is similar to the SPI, where both clock signal and data signal are used. Different from SPI the chip-select is not used there, and is replaced with latch function. The above mentioned three lines are connected to the controller pins.  
 + 
 +  * Latch-signal 
 +  * Clock-signal 
 +  * Data-signal
  
 ===== Practice ===== ===== Practice =====
  
-There is one 7-segment LED number-indicator on the Digital i/o module. It is controlled through a driver with serial interface A6275The serial interface of the driver is similar to SPI, where both clock signal and data signal are used. Different from SPI the //chip-select// is not used there, and is replaced with //latch// function. The above mentioned three lines are connected to the ATmega128 as follows:    +There is one 7-segment LED number-indicator on the Digital i/o module. It is controlled through a driver with serial interface. 
- +
- +
-  * Latch-signal (//latch//) - PG2 +
-  * Clock-signal (//clock//) - PC7 +
-  * Data-signal (//data//) - PC6 +
- +
-~~CL~~ +
- +
-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, where it remains until new loading. Each bit of the latch-index is connected through the current switching to one number-indicator’s segment. The segment is lit during the high bit-rate. +
 For displaying the numbers on the HomeLabs Digital i/o module indicator, the following functionality is written to the library of the HomeLab.    For displaying the numbers on the HomeLabs Digital i/o module indicator, the following functionality is written to the library of the HomeLab.   
  
  
 <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)) segment_char_map[11] = 
-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,  0b00111111,
Line 60: 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 71: 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 85: 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 91: 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, bit_is_set(map, i));  pin_set_to(segment_display_data_out, bit_is_set(map, i));
    
- // 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);
 } }
 </code> </code>
  
-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 DPGF, E, D, CBA. 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.+For displaying numbers and the letter “E”, is created a "weak" 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 lower to higher (from right to left in binary form) are marking segments ABC, D, EFG ja DP. 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. When a user defines a variable segment_char_map its own code, it is possible to create other characters on the screen (eg, text, etc.)
  
-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 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 and then displays letter E, because two-digit numbers is not possible to show on the one digit indicator.
  
  
 <code c> <code c>
-// 
 // The example program of the 7-segment LED indicator of the HomeLab's // The example program of the 7-segment LED indicator of the HomeLab's
-// input-output module. 
-// 
 #include <homelab/module/segment_display.h> #include <homelab/module/segment_display.h>
 #include <homelab/delay.h> #include <homelab/delay.h>
  
-// +// 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 values of the counter. + // Displaying the values of the counter 
- segment_display_write(counter);+ segment_display_write(counter % 10);
  
  // Counting up to 10  // Counting up to 10
  counter++;  counter++;
- if (counter>9) counter=0;+ if (counter>19) counter=0;
  
- // Delay for 1 second.+ // Delay for 1 second
  sw_delay_ms(1000);  sw_delay_ms(1000);
  }  }
 } }
 </code> </code>
en/examples/display/segment_display.1446720107.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0