Getting started with 7 segment module
What is a segment display? and Why to use MAX7219 display module?
Suppose you have made a counting device or measuring device. The output of the device is a number. It can be displayed on your mobile display, computer display or any display but the most basic one is the seven segment display that's because using only seven led's (each for one segment) you get to display all the numbers from 0 to 9. Less bits more data that's what every display designer aims for and that's the reason why the seven segment is still used along with microcontrollers because it's the most efficient way to display numbers.
You can directly interface the 7 segment display to microcontroller but it will take 8 pins just for one display. Now, what if you have to display 3 digit number then you may need 8x3 pins, that's 24 pins just for displaying 3 digits, not good. To solve this issue there are two ways:-
1. Multiplexing - Switching on and off the individual display one after the other by sending the corresponding data in right time slot. This happens at high frequency in KHz and the number appears to be stable.
2. Using 8 bit registers:- Cascading three SIPO (serial in parallel out) shift registers can be used to display three digits. This seems good so far because using only two pins, one for clock and another for data, we can send 24 bit data to display 3 digits. There are some drawbacks in this, the cost is increased as every display has got it's own register and also the power consumption is more as each chip draws current along with the segment led's.
The solution is to combine these two ways. Now we need to shift the data but we also need scanning of the individual digits like in multiplexing. That's what the designers of MAX7219 did, they used a 16 bit shift register to control the 8 digits. The 16 bit data is divided into address data of 4 bits , 8 bit data that represents the number on display and rest 4 bits are not used.
Apart from selecting individual digit the 4 address bits helps us to select different modes like shutdown mode, display test mode, intensity set mode, scan rate mode, and decode mode. You can refer the datasheet of MAX7219 to see what each mode does.
The interesting thing is just by shifting the correct register data in sequence using the din (data in), cs (Latch), and clk (clock) we can display 8 digit numbers.
I have made a library for the MAX7219 module in Arduino that will help you to display any integer or string on the display by just passing it as an argument in specific function. First lets see the hardware connections and then how to use the library functions. The library will be provided at the end of this blog.
Wiring the circuit on breadboard
Components needed :-
1. MAX7219 display module.
2. Arduino pro mini.
3. Breadboard.
4. Jumper wires (5pcs - F to F and 5pcs - F to M).
5. CP210x USB to UART bridge. (to program Arduino mini, not required for other Arduinos. )
Circuit block diagram:-
Make connections on breadboard as shown in above circuit diagram.
Using library functions :-
There are six functions in this library that you need to know. Lets understand them so that we can use them according to our application.
1. wipe( din, cs, clk)
The wipe function takes three arguments the data pin (9) , the cs aka latch pin (8) and the clock pin (7). This function clears the display when you call it.
2. shut_dwn( din, cs, clk)
This function clears the register data when it's called.
3. set_bright( level, din, cs, clk)
This function has one extra argument called level which sets the brightness level of the display. level can be of any value between 0 to 15. 15 being maximum bright and 0 is minimum bright.
4. decode_mode(din, cs, clk)
There are two modes in MAX7219. one is BCD mode in which binary 0000 to 1001 represents 0 to 9 and other is normal mode in which individual segments are turned on or off by 1's and 0's. So calling this function initially sets the MAX7219 in normal mode. I have kept it in normal mode because then we can also display alphabets possible on 7 segment.
5. seg_dis("string", din, cs, clk)
This function displays the string on the segment display. The first argument is a string that you want to be display. It can be a string of numbers eg- "1234" or the string of possible alphabets on seven segment eg- "ACFEOHPY".
6. disp(num, din, cs, clk)
The disp function displays integer on the display. The first argument is a number which is a integer variable. The value of the integer variable is displayed.
7. disp_init( din, cs, clk)
This function must be called initially before the main code runs. This runs all the initial commands which sets the scan rate of display, default brightness, and other initial settings. It must be called in void setup.
Adding library to Arduino IDE
1. Download the library from the link provided below:-
2. After downloading the zip file you need to add it in Arduino IDE.
Then browse to the folder where you have downloaded the zip file then hit enter.
Sample code to display count.
#include<seg_display_lib.h> //include the library
int d = 9; // data pin is on 9
int s = 8; // CS pin is on 8
int c = 7; // clock pin is on 7
int co=10;
void setup() {
Serial.begin(9600); // this has to be called to set bit rate.
pinMode(d,OUTPUT);
pinMode(s,OUTPUT);
pinMode(c,OUTPUT);
disp_init(d,s,c); //initialize the display module
}
void loop() {
while(co>=1) // run the while loop till count is greater than 0
{
disp(co,d,s,c); // display count on 7 segment module
co--; // decrement count
delay(995); // wait for 995ms
}
co=10; // make count equal to 10 after exiting while loop.
}
Result after running the code:-
THANK YOU! FOR READING. I hope you will make it. If you have any questions regarding this post you can contact me through my email Id- prachethire@gmail.com
If you found this blog useful and want to support me, then you can donate me. The money you give will be used to make more advance electronics projects and setting up better lab.

Comments
Post a Comment