{"id":4935,"date":"2012-05-07T22:38:06","date_gmt":"2012-05-08T02:38:06","guid":{"rendered":"http:\/\/embedded-lab.com\/blog\/?p=4935"},"modified":"2016-10-27T22:24:12","modified_gmt":"2016-10-28T02:24:12","slug":"serial-four-digit-7-segment-led-display-module","status":"publish","type":"post","link":"https:\/\/embedded-lab.com\/blog\/serial-four-digit-7-segment-led-display-module\/","title":{"rendered":"Serial four digit 7-segment LED display module"},"content":{"rendered":"<p>Seven segment LED displays are a very popular mean of displaying numerical information and finds application in front panel display boards of microwave ovens, washers and dryers, digital clocks, frequency counters, and many other gadgets. Compared to the LCD displays, the seven segment LED displays are brighter and provide a far viewing distance and a wide viewing angle. However, the downside is they are resource-hungry. It requires at least 12 I\/O pins of a microcontroller to drive a standard 4-digit seven segment LED module. Consequently, their use with low pin-count microcontrollers (such as PIC12F series) is not practically feasible. Here&#8217;s a solution for that. The following 4-digit seven segment LED module features a serial interface that requires only 3 I\/O pins of a microcontroller and provides full control of all digits and decimal points .<\/p>\n<div id=\"attachment_4939\" style=\"width: 580px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/Finished2.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4939\" class=\"size-full wp-image-4939\" title=\"Finished2\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/Finished2.jpg\" alt=\"\" width=\"570\" height=\"423\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/Finished2.jpg 570w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/Finished2-550x408.jpg 550w\" sizes=\"auto, (max-width: 570px) 100vw, 570px\" \/><\/a><p id=\"caption-attachment-4939\" class=\"wp-caption-text\">Four digit serial 7-segment LED display<\/p><\/div>\n<p><!--more--><\/p>\n<p><strong>Description<\/strong><\/p>\n<p>This display module is based on the MAX7219 display driver chip from MAXIM. It provides a serial interface to drive 7-segment LED displays (common-cathode type) up to 8 digits.\u00a0Included on-chip are a BCD decoder, multiplex scan circuitry, segment and digit\u00a0drivers, and an 8&#215;8 static RAM to store the digit values. The segment current for all LEDs is set through only one external resistor. However, the device also provides a digital control of the display brightness (16 steps from minimum to maximum) through an internal pulse-width modulator.<\/p>\n<div id=\"attachment_4939-2\" style=\"width: 580px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/Finished2.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4939-2\" class=\"size-full wp-image-4939\" title=\"Finished2\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/Finished2.jpg\" alt=\"\" width=\"570\" height=\"423\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/Finished2.jpg 570w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/Finished2-550x408.jpg 550w\" sizes=\"auto, (max-width: 570px) 100vw, 570px\" \/><\/a><p id=\"caption-attachment-4939-2\" class=\"wp-caption-text\">Finished<\/p><\/div>\n<p>The display module is powered with +5V supply applied to its Vcc pin. Data can be transferred to the display module through SPI interface. Connections are available on the board to access the required signal lines (MOSI, CLK, and CS) for communication between the SPI Master (microcontroller) and the MAX7219 chip. Data is sent in 16-bit packets (two bytes) which is shifted into the internal 16-bit shift register with each rising edge of CLK. The 16-bit packet is labeled as D0-D15, where D0-D7 contain the data, D8-D11 contain the register address, and D12-D15 are don&#8217;t care bits. D15 is the most significant bit (MSB) and is the first bit to receive. Although the MAX7219 chip can drive up to 8 digits, only 4 digits are implemented here. They are DIG0 through DIG3, arranged in sequence from the right to the left.\u00a0The 4-bit addresses (D8-D11) of their corresponding digit registers are 0x01, 0x02, 0x03, and 0x04, respectively. The digit registers are realized with an on-chip 8&#215;8 SRAM, and are addressed directly so that individual digits can be updated at any time.\u00a0The following table lists the complete addressable digit and control registers of the MAX7219 device.<\/p>\n<div id=\"attachment_5033\" style=\"width: 489px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/RegisterAddressMap.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-5033\" class=\"size-full wp-image-5033\" title=\"RegisterAddressMap\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/RegisterAddressMap.png\" alt=\"\" width=\"479\" height=\"528\" \/><\/a><p id=\"caption-attachment-5033\" class=\"wp-caption-text\">Register address map of MAX7219<\/p><\/div>\n<p><strong>Control Registers<\/strong><\/p>\n<p>The MAX7219 contains 5 control registers: decode mode, display intensity, scan limit\u00a0(number of scanned digits), shutdown, and display test\u00a0(all LEDs on).<\/p>\n<p><em><strong>Shutdown<\/strong><\/em><\/p>\n<p>On initial power-up, all control registers are reset, and the MAX7219\/MAX7221 enters into Shutdown mode. In the shutdown mode,\u00a0the\u00a0display is blanked. The D0 bit of the Shutdown register (address 0x0C) must be set to bring the display to normal operation. The same bit can be cleared anytime during operation to enter back into the Shutdown mode. During Shutdown, the contents of the data and control registers are unaltered. Shutdown can be used to save power or as an alarm to flash the display by successively entering and leaving the Shutdown mode.<\/p>\n<p>The MAX7219 device can be put in the Shutdown mode by sending two bytes 0x0C (address) and 0x00 (data) in sequence. Similarly, 0x0C followed by 0x01 brings it back to normal operation.<\/p>\n<p><strong><em>Decode-Mode<\/em><\/strong><\/p>\n<p>The decode-mode register (address 0x09) sets BCD code B (0-9, E, H, L, P, and -) or no-decode operation for each digit. Each bit in the register corresponds to one digit. A logic high selects code B decoding while logic low bypasses the decoder.\u00a0When the code B decode mode is used, the decoder\u00a0looks only at the lower nibble of the data in the digit\u00a0registers (D3\u2013D0), disregarding bits D4\u2013D6. The D7 bit is independent of the decoder and turns the decimal point on if it is set (D7=1). For example, sending bytes 0x02 and 0x05 in sequence sets the DIG1 (second digit from the right) to display decimal 5. Similarly, 0x01 followed by 0x89 displays decimal 9 at DIG0 with its decimal point set. The following table provides the complete\u00a0list of the code B font.<\/p>\n<div id=\"attachment_5034\" style=\"width: 580px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/CodeFont.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-5034\" class=\"size-full wp-image-5034\" title=\"CodeFont\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/CodeFont.png\" alt=\"\" width=\"570\" height=\"316\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/CodeFont.png 570w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/CodeFont-550x304.png 550w\" sizes=\"auto, (max-width: 570px) 100vw, 570px\" \/><\/a><p id=\"caption-attachment-5034\" class=\"wp-caption-text\">Code B font<\/p><\/div>\n<p>When no-decode is selected, data bits D7\u2013D0 correspond\u00a0to the segment lines (A-G and DP) of the seven segment display.<\/p>\n<div id=\"attachment_5035\" style=\"width: 478px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/NoDecodeMode.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-5035\" class=\"size-full wp-image-5035\" title=\"NoDecodeMode\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/NoDecodeMode.png\" alt=\"\" width=\"468\" height=\"359\" \/><\/a><p id=\"caption-attachment-5035\" class=\"wp-caption-text\">No-Decode Mode Data Bits and Corresponding Segment Lines<\/p><\/div>\n<p><em><strong>Intensity control<\/strong><\/em><\/p>\n<p>The MAX7219 allows display brightness to be controlled through software by an internal pulse-width modulator (PWM). The PWM output is controlled by the lower nibble (D3-D0) of the intensity register (address 0x0A) and allows 16 brightness levels. The zero nibble value sets the display intensity to minimum, whereas all nibble bits set to 1 selects the maximum intensity level for the display.<\/p>\n<p><em><strong>Scan-Limit<\/strong><\/em><\/p>\n<p>The scan-limit register (address 0x0B) sets how many digits are to be displayed from 1 to 8. For a 4-digit display, the scan-limit register value should be set to 0x03.<\/p>\n<p><em><strong>Display-Test<\/strong><\/em><\/p>\n<p>The display-test register has address 0x0F and allows to turn all LEDs on by overriding, but not altering, the values of the control and digit registers. In order to enable the display-test mode, the D0 bit of the display-test register must be set. The same bit must be cleared to get back to the normal operation.<\/p>\n<p><strong>Interfacing with a microcontroller<\/strong><\/p>\n<p>The serial 7-segment LED display module can be interfaced with any microcontroller that has 3 I\/O pins available. If the microcontroller features a built-in hardware SPI, then the display module can be interfaced as a SPI slave device. In that case the SPI signal lines SDO (serial data out), SCLK (serial clock), and SS (slave select) from the microcontroller can be directly connected to the MOSI, CLK, and CS pins labeled on the display module. CS is active low signal.<\/p>\n<p>In case the host microcontroller doesn&#8217;t have a hardware SPI module, the interface can be implemented in software. The SPI communication starts with holding CS pin LOW and then sending 16 bits of data serially (MSB first) over the MOSI pin at the rising edge of CLK signal, and finally pulling the CS pin back to HIGH. The following example illustrates how to write a software SPI routine to drive the display module with three general purpose I\/O pins of the PIC12F683 microcontroller. The program is written in mikroC Pro for PIC compiler but can be easily modified for other high-level compilers. The GP0, GP1, and GP2 pins of the PIC12F683 drives the CS, MOSI, and CLK pins, respectively, of the 7-segment display module to create a 4-digit up-counter. The counter counts from 0000 to 9999 and then reset to zero and start again.<\/p>\n\n<div class=\"wp_syntax\"><table><tr><td class=\"code\"><pre class=\"c\" style=\"font-family:monospace;\"><span style=\"color: #666666; font-style: italic;\">\/\/ Define Soft-SPI connections<\/span>\n<span style=\"color: #339933;\">#define CS_Pin       GP0_bit<\/span>\n<span style=\"color: #339933;\">#define MOSI_Pin     GP1_bit<\/span>\n<span style=\"color: #339933;\">#define CLK_Pin      GP2_bit<\/span>\n&nbsp;\n<span style=\"color: #993333;\">void<\/span> SPI_Write_Byte<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">short<\/span> num<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#123;<\/span>\n <span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">short<\/span> t<span style=\"color: #339933;\">,<\/span> Mask<span style=\"color: #339933;\">,<\/span> Flag<span style=\"color: #339933;\">;<\/span>\n CLK_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>\n Mask <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">128<\/span><span style=\"color: #339933;\">;<\/span>\n <span style=\"color: #b1b100;\">for<\/span> <span style=\"color: #009900;\">&#40;<\/span>t<span style=\"color: #339933;\">=<\/span><span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span> t<span style=\"color: #339933;\">&amp;<\/span>lt<span style=\"color: #339933;\">;<\/span><span style=\"color: #0000dd;\">8<\/span><span style=\"color: #339933;\">;<\/span> t<span style=\"color: #339933;\">++<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#123;<\/span>\n  Flag <span style=\"color: #339933;\">=<\/span> num <span style=\"color: #339933;\">&amp;<\/span>amp<span style=\"color: #339933;\">;<\/span> Mask<span style=\"color: #339933;\">;<\/span>\n  <span style=\"color: #b1b100;\">if<\/span><span style=\"color: #009900;\">&#40;<\/span>Flag <span style=\"color: #339933;\">==<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #009900;\">&#41;<\/span> MOSI_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>\n  <span style=\"color: #b1b100;\">else<\/span> MOSI_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>\n  CLK_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>\n  CLK_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>\n  Mask <span style=\"color: #339933;\">=<\/span> Mask <span style=\"color: #339933;\">&amp;<\/span>gt<span style=\"color: #339933;\">;&amp;<\/span>gt<span style=\"color: #339933;\">;<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>\n <span style=\"color: #009900;\">&#125;<\/span>\n<span style=\"color: #009900;\">&#125;<\/span>\n&nbsp;\n<span style=\"color: #993333;\">void<\/span> MAX7219_INIT<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #009900;\">&#123;<\/span>\n  <span style=\"color: #666666; font-style: italic;\">\/\/ Disable Shutdown mode<\/span>\n  CS_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>              <span style=\"color: #666666; font-style: italic;\">\/\/ CS pin is pulled LOW<\/span>\n  SPI_Write_Byte<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #208080;\">0x0C<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>    <span style=\"color: #666666; font-style: italic;\">\/\/ Select Shutdown register<\/span>\n  SPI_Write_Byte<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #208080;\">0x01<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>    <span style=\"color: #666666; font-style: italic;\">\/\/ Set D0 bit to return to normal operation<\/span>\n  CS_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>              <span style=\"color: #666666; font-style: italic;\">\/\/ CS pin is pulled HIGH<\/span>\n&nbsp;\n  <span style=\"color: #666666; font-style: italic;\">\/\/ Set BCD decode mode for digits DIG0-DIG3<\/span>\n  CS_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>              <span style=\"color: #666666; font-style: italic;\">\/\/ CS pin is pulled LOW<\/span>\n  SPI_Write_Byte<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #208080;\">0x09<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>    <span style=\"color: #666666; font-style: italic;\">\/\/ Select Decode Mode register<\/span>\n  SPI_Write_Byte<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #208080;\">0x0F<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>    <span style=\"color: #666666; font-style: italic;\">\/\/ Select BCD mode for digits DIG0-DIG3<\/span>\n  CS_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>              <span style=\"color: #666666; font-style: italic;\">\/\/ CS pin is pulled HIGH<\/span>\n&nbsp;\n  <span style=\"color: #666666; font-style: italic;\">\/\/ Set display brighness<\/span>\n  CS_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>              <span style=\"color: #666666; font-style: italic;\">\/\/ CS pin is pulled LOW<\/span>\n  SPI_Write_Byte<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #208080;\">0x0A<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>    <span style=\"color: #666666; font-style: italic;\">\/\/ Select Intensity register<\/span>\n  SPI_Write_Byte<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #208080;\">0x0a<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>    <span style=\"color: #666666; font-style: italic;\">\/\/ Set maximum brightness<\/span>\n  CS_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>              <span style=\"color: #666666; font-style: italic;\">\/\/ CS pin is pulled HIGH<\/span>\n&nbsp;\n   <span style=\"color: #666666; font-style: italic;\">\/\/ Set display refresh<\/span>\n  CS_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>              <span style=\"color: #666666; font-style: italic;\">\/\/ CS pin is pulled LOW<\/span>\n  SPI_Write_Byte<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #208080;\">0x0B<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>    <span style=\"color: #666666; font-style: italic;\">\/\/ Select Scan-Limit register<\/span>\n  SPI_Write_Byte<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #208080;\">0x03<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>    <span style=\"color: #666666; font-style: italic;\">\/\/ Select digits DIG0-DIG3<\/span>\n  CS_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>              <span style=\"color: #666666; font-style: italic;\">\/\/ CS pin is pulled HIGH<\/span>\n&nbsp;\n <span style=\"color: #666666; font-style: italic;\">\/\/ Enable Display-Test<\/span>\n  CS_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>              <span style=\"color: #666666; font-style: italic;\">\/\/ CS pin is pulled LOW<\/span>\n  SPI_Write_Byte<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #208080;\">0x0F<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>    <span style=\"color: #666666; font-style: italic;\">\/\/ Select Display-Test register<\/span>\n  SPI_Write_Byte<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #208080;\">0x01<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>    <span style=\"color: #666666; font-style: italic;\">\/\/ Enable Display-Test<\/span>\n  CS_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>              <span style=\"color: #666666; font-style: italic;\">\/\/ CS pin is pulled HIGH<\/span>\n&nbsp;\n  Delay_ms<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">1000<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n <span style=\"color: #666666; font-style: italic;\">\/\/ Disable Display-Test<\/span>\n  CS_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>              <span style=\"color: #666666; font-style: italic;\">\/\/ CS pin is pulled LOW<\/span>\n  SPI_Write_Byte<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #208080;\">0x0F<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>    <span style=\"color: #666666; font-style: italic;\">\/\/ Select Display-Test register<\/span>\n  SPI_Write_Byte<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #208080;\">0x00<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>    <span style=\"color: #666666; font-style: italic;\">\/\/ Disable Display-Test<\/span>\n  CS_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>              <span style=\"color: #666666; font-style: italic;\">\/\/ CS pin is pulled HIGH<\/span>\n&nbsp;\n<span style=\"color: #009900;\">&#125;<\/span>\n&nbsp;\n <span style=\"color: #993333;\">void<\/span> Display_Counter<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">int<\/span> j<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#123;<\/span>\n  CS_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>                    <span style=\"color: #666666; font-style: italic;\">\/\/ CS pin is pulled LOW<\/span>\n  SPI_Write_Byte<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">4<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>             <span style=\"color: #666666; font-style: italic;\">\/\/ Send thousands digit<\/span>\n  SPI_Write_Byte<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#40;<\/span>j<span style=\"color: #339933;\">\/<\/span><span style=\"color: #0000dd;\">1000<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">%<\/span><span style=\"color:#800080;\">10<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  CS_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>                    <span style=\"color: #666666; font-style: italic;\">\/\/ CS pin is pulled HIGH<\/span>\n&nbsp;\n  CS_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>                    <span style=\"color: #666666; font-style: italic;\">\/\/ CS pin is pulled LOW<\/span>\n  SPI_Write_Byte<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">3<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>             <span style=\"color: #666666; font-style: italic;\">\/\/ Send hundreds digit<\/span>\n  SPI_Write_Byte<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#40;<\/span>j<span style=\"color: #339933;\">\/<\/span><span style=\"color: #0000dd;\">100<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">%<\/span><span style=\"color:#800080;\">10<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  CS_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>                    <span style=\"color: #666666; font-style: italic;\">\/\/ CS pin is pulled HIGH<\/span>\n&nbsp;\n  CS_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>                    <span style=\"color: #666666; font-style: italic;\">\/\/ CS pin is pulled LOW<\/span>\n  SPI_Write_Byte<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">2<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>             <span style=\"color: #666666; font-style: italic;\">\/\/ Send tens digit<\/span>\n  SPI_Write_Byte<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#40;<\/span>j<span style=\"color: #339933;\">\/<\/span><span style=\"color: #0000dd;\">10<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">%<\/span><span style=\"color:#800080;\">10<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  CS_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>                    <span style=\"color: #666666; font-style: italic;\">\/\/ CS pin is pulled HIGH<\/span>\n&nbsp;\n  CS_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>                    <span style=\"color: #666666; font-style: italic;\">\/\/ CS pin is pulled LOW<\/span>\n  SPI_Write_Byte<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>             <span style=\"color: #666666; font-style: italic;\">\/\/ Send ones digit<\/span>\n  SPI_Write_Byte<span style=\"color: #009900;\">&#40;<\/span>j<span style=\"color: #339933;\">%<\/span><span style=\"color:#800080;\">10<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  CS_Pin <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>                    <span style=\"color: #666666; font-style: italic;\">\/\/ CS pin is pulled HIGH<\/span>\n <span style=\"color: #009900;\">&#125;<\/span>\n&nbsp;\n<span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">short<\/span> i<span style=\"color: #339933;\">;<\/span>\n<span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">int<\/span> counter <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>\n&nbsp;\n<span style=\"color: #993333;\">void<\/span> main<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #009900;\">&#123;<\/span>\n  TRISIO<span style=\"color: #339933;\">=<\/span><span style=\"color: #208080;\">0b00001000<\/span><span style=\"color: #339933;\">;<\/span>        <span style=\"color: #666666; font-style: italic;\">\/\/ GP3 is input only<\/span>\n  CMCON0 <span style=\"color: #339933;\">=<\/span> <span style=\"color: #208080;\">0x07<\/span><span style=\"color: #339933;\">;<\/span>\n  ANSEL <span style=\"color: #339933;\">=<\/span> <span style=\"color: #208080;\">0x00<\/span><span style=\"color: #339933;\">;<\/span>\n  MAX7219_INIT<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>              <span style=\"color: #666666; font-style: italic;\">\/\/ initialize  max7219<\/span>\n  <span style=\"color: #b1b100;\">do<\/span><span style=\"color: #009900;\">&#123;<\/span>\n   <span style=\"color: #b1b100;\">for<\/span> <span style=\"color: #009900;\">&#40;<\/span>counter<span style=\"color: #339933;\">=<\/span><span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span> counter<span style=\"color: #339933;\">&amp;<\/span>lt<span style=\"color: #339933;\">;<\/span><span style=\"color: #0000dd;\">10000<\/span><span style=\"color: #339933;\">;<\/span> counter<span style=\"color: #339933;\">++<\/span><span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #009900;\">&#123;<\/span>\n    Display_Counter<span style=\"color: #009900;\">&#40;<\/span>counter<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n    Delay_ms<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">1000<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n   <span style=\"color: #009900;\">&#125;<\/span>\n  <span style=\"color: #009900;\">&#125;<\/span><span style=\"color: #b1b100;\">while<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n<span style=\"color: #009900;\">&#125;<\/span><\/pre><\/td><\/tr><\/table><\/div>\n\n<p><strong><a href=\"http:\/\/embedded-lab.com\/uploads\/HexFiles\/PIC12F\/PIC12FSPI_Test.zip\" target=\"_blank\">Download source and HEX files<\/a><\/strong><\/p>\n<p>The PIC12F683 microcontroller runs at 4.0 MHz internal clock and MCLR is disabled. In the picture below, the <a href=\"http:\/\/www.piccircuit.com\/shop\/pic-io-board\/76-icp07-iboard-tiny.html\" target=\"_blank\">tiny PIC12F683 board<\/a> is from <a href=\"http:\/\/www.piccircuit.com\/\" target=\"_blank\">iCircuit Technologies<\/a>.<\/p>\n<div id=\"attachment_5041\" style=\"width: 580px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/PIC12FCounterOP2.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-5041\" class=\"size-full wp-image-5041\" title=\"PIC12FCounterOP2\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/PIC12FCounterOP2.jpg\" alt=\"\" width=\"570\" height=\"630\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/PIC12FCounterOP2.jpg 570w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/PIC12FCounterOP2-550x607.jpg 550w\" sizes=\"auto, (max-width: 570px) 100vw, 570px\" \/><\/a><p id=\"caption-attachment-5041\" class=\"wp-caption-text\">4-digit UP-counter using PIC12F683<\/p><\/div>\n<p>The LED display module can also be interfaced with Arduino board using the <strong><a href=\"http:\/\/arduino.cc\/playground\/Main\/LedControl\" target=\"_blank\">LedControl<\/a><\/strong> library.<\/p>\n<div id=\"attachment_5024\" style=\"width: 580px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/ArduinoSPILED2.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-5024\" class=\"size-full wp-image-5024\" title=\"ArduinoSPILED2\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/ArduinoSPILED2.jpg\" alt=\"\" width=\"570\" height=\"453\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/ArduinoSPILED2.jpg 570w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/ArduinoSPILED2-550x437.jpg 550w\" sizes=\"auto, (max-width: 570px) 100vw, 570px\" \/><\/a><p id=\"caption-attachment-5024\" class=\"wp-caption-text\">Interfacing with Arduino<\/p><\/div>\n<p><strong>Summary<\/strong><\/p>\n<p>This MAX7219 based LED display module allows you to interface a 4-digit 7-segment LED display to low-pin count microcontrollers using only three I\/O pins. It gives you full control of all digits, decimal points, and the display brightness.<\/p>\n<p>For purchasing an assembled and tested version of this display module, visit our <a href=\"https:\/\/www.tindie.com\/stores\/rajbex\/\" target=\"_blank\"><strong>Tindie Store<\/strong><\/a>.<\/p>\n<p><span style=\"color: #ff0000;\"><strong>Revision 1 (12\/15\/2012)<\/strong><\/span><\/p>\n<p>The PCB has slightly been revised recently. Everything remains the same except there are two header connectors available now. One for interfacing the display with a microcontroller and other for cascading multiple displays. New PCB is shown below.<\/p>\n<div id=\"attachment_6564\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/SPI7SEG_4Digv1.0KIT.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6564\" class=\"size-full wp-image-6564\" title=\"SPI7SEG_4Digv1.0KIT\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/SPI7SEG_4Digv1.0KIT.jpg\" alt=\"\" width=\"560\" height=\"398\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/SPI7SEG_4Digv1.0KIT.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/SPI7SEG_4Digv1.0KIT-550x390.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-6564\" class=\"wp-caption-text\">SPI 7-segment display kit (four digit)<\/p><\/div>\n<div id=\"attachment_6565\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/SPI7SEG_4Digv1.0Board.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6565\" class=\"size-full wp-image-6565\" title=\"SPI7SEG_4Digv1.0Board\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/SPI7SEG_4Digv1.0Board.jpg\" alt=\"\" width=\"560\" height=\"450\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/SPI7SEG_4Digv1.0Board.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/SPI7SEG_4Digv1.0Board-550x441.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-6565\" class=\"wp-caption-text\">Assembled display board<\/p><\/div>\n<p>Here&#8217;s the circuit diagram of this display board.<\/p>\n<div id=\"attachment_5580\" style=\"width: 539px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/SPIDISP4Digiit.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-5580\" class=\"size-full wp-image-5580\" title=\"SPIDISP4Digiit\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/SPIDISP4Digiit.png\" alt=\"\" width=\"529\" height=\"492\" \/><\/a><p id=\"caption-attachment-5580\" class=\"wp-caption-text\">Serial 4-digit display circuit<\/p><\/div>\n<p><span style=\"color: #ff0000;\"><strong>Revision 2 (02\/20\/2013)<\/strong><\/span><\/p>\n<p>The new revised version has following improvements:<\/p>\n<ul>\n<li>High quality 0.40? display (<strong>LTC-4727JS<\/strong>) with bright yellow light emitting diodes<\/li>\n<li>Four digits, decimal and colon segments<\/li>\n<li>Round PCB corners<\/li>\n<\/ul>\n<div>\n<dl id=\"attachment_7134\" class=\"wp-caption aligncenter\" style=\"width: 575px;\">\n<dt class=\"wp-caption-dt\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/SPI7SEGDISP4.40-1R1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7134\" title=\"SPI7SEGDISP4.40-1R\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/SPI7SEGDISP4.40-1R1.jpg\" alt=\"\" width=\"565\" height=\"419\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/SPI7SEGDISP4.40-1R1.jpg 565w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/SPI7SEGDISP4.40-1R1-550x407.jpg 550w\" sizes=\"auto, (max-width: 565px) 100vw, 565px\" \/><\/a><\/dt>\n<dd class=\"wp-caption-dd\">Rev 2: SPI seven segment LED display<\/dd>\n<\/dl>\n<\/div>\n<div><strong style=\"color: #ff0000;\">Revision 3 (07\/26\/2013)<\/strong><\/div>\n<p>The new version uses all surface mount components.<\/p>\n<div id=\"attachment_7667\" style=\"width: 575px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/SPI7SEGDISP4.401R_1.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-7667\" class=\"size-full wp-image-7667\" title=\"SPI7SEGDISP4.401R_1\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/SPI7SEGDISP4.401R_1.jpg\" alt=\"\" width=\"565\" height=\"426\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/SPI7SEGDISP4.401R_1.jpg 565w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/05\/SPI7SEGDISP4.401R_1-550x414.jpg 550w\" sizes=\"auto, (max-width: 565px) 100vw, 565px\" \/><\/a><p id=\"caption-attachment-7667\" class=\"wp-caption-text\">Revision 3 uses SMT components<\/p><\/div>\n<p>More details on the new board can be found\u00a0<strong><a href=\"http:\/\/embedded-lab.com\/blog\/?p=7136\" target=\"_blank\">here<\/a><\/strong>. You can buy an assembled board for $12.50 on\u00a0<strong><a href=\"https:\/\/www.tindie.com\/products\/rajbex\/spi-4-digit-seven-segment-led-display\/\" target=\"_blank\">Tindie<\/a><\/strong>. International buyers can also buy this from <strong><a href=\"http:\/\/www.elecrow.com\/cooperated-designers\/embedded-lab\/spi7segdisp4401r-p-562.html\" target=\"_blank\">Elecrow<\/a><\/strong>, which ships this item world-wide at a much cheaper shipping cost.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Seven segment LED displays are a very popular mean of displaying numerical information and finds application in front panel display boards of microwave ovens, washers and dryers, digital clocks, frequency counters, and many other gadgets. Compared to the LCD displays, the seven segment LED displays are brighter and provide a far viewing distance and a wide viewing angle. However, the downside is they are resource-hungry. It requires at least 12 I\/O pins of a microcontroller to drive a standard 4-digit seven segment LED module. Consequently, their use with low pin-count microcontrollers (such as PIC12F series) is not practically feasible. Here&#8217;s<\/p>\n","protected":false},"author":1,"featured_media":4936,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[348,437],"tags":[439,438],"class_list":["post-4935","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-product-review","category-products","tag-max7219","tag-spi-led-display"],"_links":{"self":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/4935","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/comments?post=4935"}],"version-history":[{"count":42,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/4935\/revisions"}],"predecessor-version":[{"id":12363,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/4935\/revisions\/12363"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media\/4936"}],"wp:attachment":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media?parent=4935"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/categories?post=4935"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/tags?post=4935"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}