The following is the .h file:
#ifndef __MAX7219_H
#define __MAX7219_H
#include "stm8s_gpio.h"
#include "stm8s.h"
#include #include #include "tim1.h" #define uchar unsigned char #define uint unsigned int #define count 8 void Init_MAX7219(void); void MAX7219_Init(void); void Write_Max7219_byte(uchar Data); void Write_Max7219(u8 address1,u8 dat1,u8 address2,u8 dat2); #define High 1 #define Low 0 #define Din(High_Low) if(High_Low == 0)GPIO_WriteLow(GPIOC, GPIO_PIN_4); else GPIO_WriteHigh(GPIOC, GPIO_PIN_4); #define Cs(High_Low) if(High_Low == 0)GPIO_WriteLow(GPIOC, GPIO_PIN_3); else GPIO_WriteHigh(GPIOC, GPIO_PIN_3); #define Clk(High_Low) if(High_Low == 0)GPIO_WriteLow(GPIOC, GPIO_PIN_2); else GPIO_WriteHigh(GPIOC, GPIO_PIN_2); #endif The following is the .c file: #include "main.h" void Init_MAX7219(void) { GPIO_Init(GPIOC, GPIO_PIN_4, GPIO_MODE_OUT_PP_HIGH_FAST); //PC4 high-speed push-pull output high level control DIN GPIO_Init(GPIOC, GPIO_PIN_3, GPIO_MODE_OUT_PP_HIGH_FAST); //PC3 high-speed push-pull output high level control CS GPIO_Init(GPIOC, GPIO_PIN_2, GPIO_MODE_OUT_PP_HIGH_FAST); //PC2 high-speed push-pull output high level control CLK } //-------------------------------------------- //Function: Write bytes to MAX7219 (U3) //Entry parameters: DATA //Export parameters: None //illustrate: void Write_Max7219_byte(uchar Data) { flying i; Cs(0); for(i=8;i>=1;i--) { Clk(0); if(Data&0x80) { From(1); } else { From(0); } Data=Data<<1; Clk(1); delay_us(10); Clk(0); } } //------------------------------------------- //Function: write data to MAX7219 //Entry parameters: address, dat //Export parameters: None //illustrate: void Write_Max7219(u8 address1,u8 dat1,u8 address2,u8 dat2) { Cs(0); Write_Max7219_byte(address1); //Write address, i.e. digital tube number Write_Max7219_byte(dat1); //Write data, i.e. the digital tube displays numbers Write_Max7219_byte(address2); //Write address, i.e. digital tube number Write_Max7219_byte(dat2); //Write data, i.e. the digital tube displays numbers nop(); Cs(1); } void MAX7219_Init(void) { /* Write_Max7219(0x09, 0x00,0x09, 0x00); //Decoding method: BCD code Write_Max7219(0x0a, 0x03,0x0a, 0x03); //Brightness Write_Max7219(0x0b, 0x07,0x0b, 0x07); //Scan limit; 8 digital tubes display Write_Max7219(0x0c, 0x01,0x0c, 0x01); //Power-down mode: 0, normal mode: 1 Write_Max7219(0x0f, 0x00,0x0f, 0x00); //Display test: 1; Test ends, normal display: 0 */ u8 i; Cs(0); for(i=0;i Write_Max7219_byte(0x09); //Decoding method: BCD code Write_Max7219_byte(0x00); } Cs(1); nop(); Cs(0); for(i=0;i Write_Max7219_byte(0x0a); //Brightness Write_Max7219_byte(0x03); } Cs(1); nop(); Cs(0); for(i=0;i Write_Max7219_byte(0x0b); // //Scan boundary; 8 digital tubes display Write_Max7219_byte(0x07); } Cs(1); nop(); Cs(0); for(i=0;i Write_Max7219_byte(0x0c); // //Power-down mode: 0, normal mode: 1 Write_Max7219_byte(0x01); } Cs(1); nop(); Cs(0); for(i=0;i Write_Max7219_byte(0x0f); //Display test: 1; Test ends, normal display: 0 Write_Max7219_byte(0x00); } Cs(1); nop(); }
Previous article:STM8S TM1650 chip control program
Next article:MAX7219 driver, a commonly used chip for single-chip microcomputers
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Why software-defined vehicles transform cars from tools into living spaces
- How Lucid is overtaking Tesla with smaller motors
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Three steps to govern hybrid multicloud environments
- Three steps to govern hybrid multicloud environments
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Summary and analysis of interference problems in circuit design
- Does the dummy pad have any impact on the electrical characteristics of the PCB?
- [HC32F460 Development Board Review] NO.2 Familiarity with the development process and different peripheral functions
- Classification of RFID readers and their advantages
- [Repost] Correctly select low noise amplifier
- NTC thermistor driver for MicroPython
- How does Cyclone2's ep2c8 provide clock to external ADC?
- If I use a battery to power a DCDC circuit, how can I be sure that the battery has enough power?
- Standard USB keyboard data packet
- 【Small home weather station】+ Hardware design, board proofing