MAX7219 multi-chip cascade drive dot matrix microcontroller program writing experience

Publisher:CrystalClearLatest update time:2020-12-23 Source: 51heiKeywords:MAX7219 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

main.c

#include

#include "intrins.h"

#include "Max7219.h"


uchar code laji[][8]={

{0x18,0x24,0x42,0x42,0x7E,0x42,0x42,0x42},//A

{0x7C,0x42,0x42,0x7C,0x42,0x42,0x42,0x7C},//B

{0x3C,0x42,0x40,0x40,0x40,0x40,0x42,0x7C},//C

{0x7C,0x42,0x42,0x42,0x42,0x42,0x42,0x7C},//D

};

/*n milliseconds delay program*/

/*void Delay_xms(uint x)

{

  uint i,j;

  for(i=0;i  for(j=0;j<112;j++);

}*/

void main()

{

  flying i,j;

  //Delay_xms(50);

  MAX7219Init();  

  while(1)

  {

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

    {

      for(i=0;i      {

        Max7219WR(j+1,laji[i][j]);

            }

      CS=1; _nop_(); CS=0;

                        //Delay_xms(100);

    }  

  }

}



Max7219.h

#ifndef _Max7219_H_

#define _Max7219_H_


#define uchar unsigned char

#define uint  unsigned int

#define number 4 //Number of dot matrix cascades

#define lum 5 //Brightness level, 0-F, 16 levels in total


//Define Max7219 port

sbit CLK = P2^2; //Clock Max7219_pin

sbit CS = P2^1; // latch

sbit DIN = P2^0; //data


//Write address and data to MAX7219

void Max7219WR(fly addr,fly dat)

{

  fly n=8;

        CLK=0;

        CS=0; //CS=0 is valid, CS=1 is latched

        /*Send data high bit first*/

        while(n--)

        {

          DIN = addr & 0x80;

                CLK=1;

                addr <<= 1;

                CLK=0;

        }

        n=8;

        /*Send data high bit first*/

        while(n--)

        {

          DIN = dat & 0x80;

                CLK=1;

                dat <<= 1;

                CLK=0;

        }

}

void MAX7219Init()

{

  flying i,j;

        for(i=0;i<5;i++)  //

        {

          for(j=number;j>0;j--)

                switch(i)

                {

                  case 0:Max7219WR(0x09, 0x00); break; //Decoding mode: BCD code is not decoded

                        case 1:Max7219WR(0x0A, lum); break; //Brightness 0-15, 16 levels in total

                        case 2:Max7219WR(0x0B, 0x07); break; //Scan limit; 8-bit display

                        case 3:Max7219WR(0x0C, 0x01); break; //Power-down mode: 0, normal mode: 1

                        case 4:Max7219WR(0x0F, 0x00); break; //Display test: 1; Test ends, normal display: 0

                }

                CS=1; _nop_(); CS=0; //Give a latch pulse every four writes

        }

}

#endif


Keywords:MAX7219 Reference address:MAX7219 multi-chip cascade drive dot matrix microcontroller program writing experience

Previous article:Single chip electronic password lock program design (assembly language) display *
Next article:Campus work and rest control system based on 51 single chip microcomputer assembly

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • 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)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号