Arduino and MAX7219, 8 Digit, 7 Segment BCD Counter
by PugazhM in Circuits > Electronics
41104 Views, 23 Favorites, 0 Comments
Arduino and MAX7219, 8 Digit, 7 Segment BCD Counter
In Embedded system design, seven segment displays are playing a major role as numerical visual indications. Seven segment LED displays are brighter, more attractive and provide a far viewing distance as well as a wider viewing angle as compared to LCD displays. Its available wide dimensions (0.3 inch to 6 inch) and different colors (RED, GREEN, BLUE, ORANGE, WHITE). It can display digits from 0 to 9 and quite a few characters like A, b, C, d, E, e, F, n, o, P, t, u, etc. This intractable is about interfacing 8 digits of 7 segment display by using popular MAX7219 display driver with Arduino Uno.
Parts and components
- Arduino Uno board
- Max7219 4 Digit 7Segment Common cathode displays = 2 Nos
- Or Max7219 assembled board
Schematic
- The MAX7219 display driver chip provides a 3-wire serial (SPI) interface to drive 7-segment LED displays (common-cathode type) up to 8 digits.
- The on-chip includes a BCD decoder, multiplex scan circuitry, segment and digit drivers, and an 8×8 static RAM to store the digit values.
- The DIN, LOAD and CLOCK pins of MAX7219 is connected with 4,3 and 2 digital IO pins of Arduino.
- Two (RED and BLUE) 4 digit, common cathode seven segment displays are connected to the drive pins on MAX7219.
- Otherwise, one can use the pre-assembled MAX7219 board with 8 digits, and connect the drive pins accordingly.
Software
- The Arduino LedControl library is used for displaying digits on MAX7219.
- The count variable updated by one count, at every 500mS.
- The count_one variable which is duplicate of count, will be converted into BCD, and displayed at the 4,5,6 and 7th digits.
- The count_two variable which is multiplication 7 of count, will be converted into BCD, and displayed at the 1,2,3 and 4th digits.
- The count will be reset to zero once it reaches 9999.
Conclusion
- The project is successfully simulated by using the Proteus.
- The MAX7219 can be used for many embedded projects as numerical display.
/*
Demonstrates the use of MAX7219 and 2 of 4x7 Segment display.
The Arduino circuit connection for 7219:
* MAX7219 DIN pin to digital pin 4
* MAX7219 LOAD pin to digital pin 3
* MAX7219 CLOCK pin to digital pin 2
*
Name:- M.Pugazhendi
Date:- 05thJul2016
Version:- V0.1
e-mail:- muthuswamy.pugazhendi@gmail.com
*/
#include
// inputs: DIN pin, CLK pin, LOAD pin. number of chips
LedControl mydisplay = LedControl(4, 2, 3, 1);
unsigned int count = 0;
unsigned int count_one = 0;
unsigned int count_two = 0;
void setup()
{
mydisplay.shutdown(0, false); // turns on display
mydisplay.setIntensity(0, 15); // 15 = brightest
mydisplay.setDigit(0, 0, 9, false);
mydisplay.setDigit(0, 1, 8, false);
mydisplay.setDigit(0, 2, 7, false);
mydisplay.setDigit(0, 3, 6, false);
mydisplay.setDigit(0, 4, 5, true);
mydisplay.setDigit(0, 5, 4, false);
mydisplay.setDigit(0, 6, 3, false);
mydisplay.setDigit(0, 7, 2, false);
}
void loop()
{
count++;
if((count*7) >= 9999)
{
count = 0;
}
count_one = HexToBCD(count);
count_two = HexToBCD(count*7);
mydisplay.setDigit(0, 0, ((count_two>>12)&0x0F), false);
mydisplay.setDigit(0, 1, ((count_two>>8)&0x0F), false);
mydisplay.setDigit(0, 2, ((count_two>>4)&0x0F), false);
mydisplay.setDigit(0, 3, ((count_two>>0)&0x0F), false);
mydisplay.setDigit(0, 4, ((count_one>>12)&0x0F), false);
mydisplay.setDigit(0, 5, ((count_one>>8)&0x0F), false);
mydisplay.setDigit(0, 6, ((count_one>>4)&0x0F), false);
mydisplay.setDigit(0, 7, (count_one&0x0F), false);
delay(500);
}
/**************************************************************************
*!
* \brief Coverts hex into BCD
*
* This function will coverts hex into BCD
*
* \param[in] byte
* \param[out] byte
* \return Nill
*
*
**************************************************************************/
unsigned int HexToBCD(unsigned int number)
{
unsigned char i=0;
unsigned int k = 0;
while(number)
{
k = ( k ) | ((number%10) << i*4);
number = number / 10;
i++;
}
return(k);
}