STM8S MAX7219 dot matrix module driver chip program

Publisher:asdfrewqppLatest update time:2019-11-08 Source: 51heiKeywords:STM8S  MAX7219 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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();

}

Keywords:STM8S  MAX7219 Reference address:STM8S MAX7219 dot matrix module driver chip program

Previous article:STM8S TM1650 chip control program
Next article:MAX7219 driver, a commonly used chip for single-chip microcomputers

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号