89C52 controls MAX7219 to drive digital tube

Publisher:SparklingStarLatest update time:2018-05-29 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

89C52 controls MAX7219 to drive digital tubes, providing source code, schematic diagram, welding diagram, etc. Links are at the end of the article.

Driving effect display
Write the picture description here

Schematic

Write the picture description here

Source code

max7219.h

/**********************************************************

* File name: MAX7219.H 

* Description: MAX7219 driver package program 

**********************************************************/

#ifndef _MAX7219_H_

#define _MAX7219_H_


#include

#include


//Pin definition

sbit MAX7219_CS = P2^6;

sbit MAX7219_MOSI = P2^5;

sbit MAX7219_CLK = P2^7;


//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

//Function definition

void MAX7219_WriteByte(unsigned char temp);

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

{

    unsigned char i,temp;

    for(i = 0; i < 8; i++)

    {   

        MAX7219_CLK = 0;

        temp = date & 0X80;

        date = date<<1;

        if(temp == 0X80)

            MAX7219_MOSI = 1;

        else

            MAX7219_SMOKE = 0;

        MAX7219_CLK = 1; //The rising edge of the clock sends the data into the register and locks it   

    }

}

/**************************************************************

** 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)

{

     MAX7219_CS = 0; //Register open, waiting for data to be sent

     _nop_();

     MAX7219_WriteByte(addr); //Select register address

     _nop_();

     MAX7219_WriteByte(dat); //Select the command for the chip to execute

     _nop_();

     MAX7219_CS = 1; //After the 16th rising edge and before the 17th rising edge, CLK must be pulled high, otherwise the data will be lost

}


/**************************************************************

** Function name: void MAX7219_Init(void)  

** Function description: MAX7219 initialization

** Input: None

** Global variables: None

** Calling module: None

** illustrate:

** Note:

**************************************************************/

void MAX7219_Init(void)      

    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

}


Reference address:89C52 controls MAX7219 to drive digital tube

Previous article:Use 51 to simulate I2C slave program
Next article:51 interrupt priority and interrupt nesting

Latest Microcontroller Articles
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
    Since development under LINUX is still quite troublesome, is there a more convenient and simple development method under WINDOWS? The answer is yes. Of course, it is not a development tool like ADS, because it ...
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
  • Learn ARM development(18)
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号