ATmega16 controls MAX7219 to drive digital tubes, and provides source code, schematics, welding diagrams, etc. See the end of the article for links.
Schematic
Source code
MAX7219.H
/**********************************************************
* File name: MAX7219.H
* Description: MAX7219 driver package program
**********************************************************/
#ifndef _MAX7219_H_
#define _MAX7219_H_
#include
#include
//Function register macro definition
#define DECODEMODE 0X09 //Decoding control register address
#define INTENSITY 0X0A //Brightness control register address
#define SCANLIMIT 0X0B //Scan limit register address
#define SHUTDOWN 0X0C //Shutdown mode register address
#define DISPTEST 0X0F //Test control register address
// External callable function definition
void MAX7219_Write(unsigned char addr, unsigned char dat);
void MAX719_Init(void);
#endif
MAX7219.C
/**********************************************************
* File name: MAX7219.c
* Description: MAX7219 driver package program
**********************************************************/
#include "max7219.h"
/**************************************************************
** Function name: void SPI_Init(void)
** Function description: SPI initialization
** Input: None
** Global variables: None
** Calling module: None
** illustrate:
** Note:
**************************************************************/
void SPI_Init(void)
{
DDRB=0xB0; //Select 7219
SPCR=0x51; //spi settings
}
/**************************************************************
** Function name: void MAX7219_WriteByte(unsigned char date)
** Function description: Write a byte to MAX7219
** Input: unsigned char date byte content
** Global variables: None
** Calling module: None
** illustrate:
** Note:
**************************************************************/
void MAX7219_WriteByte(unsigned char date)
{
SPDR = date; /* Start data transfer */
while (!(SPSR & (1< } /************************************************************** ** Function name: void MAX7219_Write(unsigned char addr, unsigned char dat) ** Function description: Write instructions to MAX7219 ** Input: unsigned char addr address unsigned char dat data ** Global variables: None ** Calling module: None ** illustrate: ** Note: **************************************************************/ void MAX7219_Write(unsigned char addr, unsigned char dat) { PORTB = 0X00; MAX7219_WriteByte(addr); //Select register address MAX7219_WriteByte(dat); //Select the chip to execute the command PORTB = 0X10; } /************************************************************** ** Function name: void MAX7219_Init(void) ** Function description: MAX7219 initialization ** Input: None ** Global variables: None ** Calling module: None ** illustrate: ** Note: **************************************************************/ void MAX7219_Init(void) { SPI_Init(); //SPI function initialization MAX7219_Write(SHUTDOWN, 0x01); //Shutdown mode register; shutdown state, the lowest bit D0 = 0; normal state, the lowest bit D0 = 1 MAX7219_Write(DISPTEST, 0x00); //Display test register; in test state, the lowest bit D0 = 1, all bits are displayed brightly; in normal working state, the lowest bit D0 = 1 MAX7219_Write(DECODEMODE, 0xff); //decoding control register; 0XFF, full decoding MAX7219_Write(SCANLIMIT, 0x07); //Scan limit register; set the number of LEDs to be displayed (1~8). If it is set to 0xX4, LEDs 0~5 will be displayed. MAX7219_Write(INTENSITY, 0x08); //Brightness control register; there are 16 levels to choose from, used to set the display brightness of the LED, 0X00-0X0F }
Previous article:ICCAVR compilation error! E
Next article:AVR microcontroller (ATMEGA16) DA0832 chip D/A conversion
Recommended ReadingLatest update time:2024-11-16 14:38
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- Learn C language for AVR microcontrollers easily (with video tutorial) (Yan Yu, Li Jia, Qin Wenhai)
- ATmega16 MCU C language programming classic example (Chen Zhongping)
- AVR MCU Principles and GCC Programming Practice: System Development of Smart Car
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- STM32F446 NUCLEO 3.5 inch TFT LCD driver
- Allegro reports an error when drilling files
- Digital clock design based on FPGA (video source code)
- ARM bare metal program vs. MCU - personal feelings
- Crystal oscillator is an important component in computers
- 【ST NUCLEO-G071RB Review】——by donatello1996
- What are the maskable interrupts of MSP430?
- 23 million Raspberry Pis have been sold
- Excellent materials: National undergraduate electronic design competition training course album
- Showing goods + almost 20 years old board