风轻云淡愿君赏,消尽烦忧心亮敞。夏去秋来添衣裳,一声问候祝安康!

Keil C51学习 10 8*8点阵屏

MAX7219介绍

MAX7219是一种高集成化的串行输入/输出共阴极显示驱动器,可实现微处理器与7段码的接口,可以显示8位或64位单一LED。

芯片上包括BCD码译码器、多位扫描电路、段驱动器、位驱动器、内含8&TImes;8位静态RAM,用于存放显示数据。只需外接一个电阻就可为所有的LED提供段电流。

MAX7219的三线串行接口适用于所有微处理器,单一位数据可被寻址和修正,无需重写整个显示器。

MAX7219具有软件译码和硬件译码两种功能,软件译码是根据各段笔划与数据位的对应关系进行编码,硬件译码采用BCD码(简称B码)译码。

MAX7219工作模式包括150μA低压电源关闭模式、模拟数字亮度控制、限扫寄存器(允许用户从第1位数字显示到第8位)及测试模式(点亮所有LED)。

 

显示“0-9”、“A-Z”、“中国”

#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint  unsigned int
//定义Max7219端口
sbit Max7219_pinCLK = P2^2;
sbit Max7219_pinCS  = P2^1;
sbit Max7219_pinDIN = P2^0;
uchar code disp1[38][8]={
{0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C},//0
{0x10,0x18,0x14,0x10,0x10,0x10,0x10,0x10},//1
{0x7E,0x2,0x2,0x7E,0x40,0x40,0x40,0x7E},//2
{0x3E,0x2,0x2,0x3E,0x2,0x2,0x3E,0x0},//3
{0x8,0x18,0x28,0x48,0xFE,0x8,0x8,0x8},//4
{0x3C,0x20,0x20,0x3C,0x4,0x4,0x3C,0x0},//5
{0x3C,0x20,0x20,0x3C,0x24,0x24,0x3C,0x0},//6
{0x3E,0x22,0x4,0x8,0x8,0x8,0x8,0x8},//7
{0x0,0x3E,0x22,0x22,0x3E,0x22,0x22,0x3E},//8
{0x3E,0x22,0x22,0x3E,0x2,0x2,0x2,0x3E},//9
{0x8,0x14,0x22,0x3E,0x22,0x22,0x22,0x22},//A
{0x3C,0x22,0x22,0x3E,0x22,0x22,0x3C,0x0},//B
{0x3C,0x40,0x40,0x40,0x40,0x40,0x3C,0x0},//C
{0x7C,0x42,0x42,0x42,0x42,0x42,0x7C,0x0},//D
{0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x7C},//E
{0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x40},//F
{0x3C,0x40,0x40,0x40,0x40,0x44,0x44,0x3C},//G
{0x44,0x44,0x44,0x7C,0x44,0x44,0x44,0x44},//H
{0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x7C},//I
{0x3C,0x8,0x8,0x8,0x8,0x8,0x48,0x30},//J
{0x0,0x24,0x28,0x30,0x20,0x30,0x28,0x24},//K
{0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x7C},//L
{0x81,0xC3,0xA5,0x99,0x81,0x81,0x81,0x81},//M
{0x0,0x42,0x62,0x52,0x4A,0x46,0x42,0x0},//N
{0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C},//O
{0x3C,0x22,0x22,0x22,0x3C,0x20,0x20,0x20},//P
{0x1C,0x22,0x22,0x22,0x22,0x26,0x22,0x1D},//Q
{0x3C,0x22,0x22,0x22,0x3C,0x24,0x22,0x21},//R
{0x0,0x1E,0x20,0x20,0x3E,0x2,0x2,0x3C},//S
{0x0,0x3E,0x8,0x8,0x8,0x8,0x8,0x8},//T
{0x42,0x42,0x42,0x42,0x42,0x42,0x22,0x1C},//U
{0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18},//V
{0x0,0x49,0x49,0x49,0x49,0x2A,0x1C,0x0},//W
{0x0,0x41,0x22,0x14,0x8,0x14,0x22,0x41},//X
{0x41,0x22,0x14,0x8,0x8,0x8,0x8,0x8},//Y
{0x0,0x7F,0x2,0x4,0x8,0x10,0x20,0x7F},//Z
{0x8,0x7F,0x49,0x49,0x7F,0x8,0x8,0x8},//
{0xFE,0xBA,0x92,0xBA,0x92,0x9A,0xBA,0xFE},//
};
void Delay_xms(uint x)
{
 uint i,j;
 for(i=0;i<x;i++)
  for(j=0;j<112;j++);
}
//--------------------------------------------
//功能:向MAX7219(U3)写入字节
//入口参数:DATA 
//出口参数:无
//说明:
void Write_Max7219_byte(uchar DATA)         
{
        uchar i;    
        Max7219_pinCS=0;        
        for(i=8;i>=1;i--)
          {          
            Max7219_pinCLK=0;
            Max7219_pinDIN=DATA&0x80;
            DATA=DATA<<1;
            Max7219_pinCLK=1;
           }                                 
}
//-------------------------------------------
//功能:向MAX7219写入数据
//入口参数:address、dat
//出口参数:无
//说明:
void Write_Max7219(uchar address,uchar dat)
{ 
     Max7219_pinCS=0;
     Write_Max7219_byte(address);           //写入地址,即数码管编号
     Write_Max7219_byte(dat);               //写入数据,即数码管显示数字 
     Max7219_pinCS=1;                        
}

void Init_MAX7219(void)
{
 Write_Max7219(0x09, 0x00);       //译码方式:BCD码
 Write_Max7219(0x0a, 0x03);       //亮度 
 Write_Max7219(0x0b, 0x07);       //扫描界限;8个数码管显示
 Write_Max7219(0x0c, 0x01);       //掉电模式:0,普通模式:1
 Write_Max7219(0x0f, 0x00);       //显示测试:1;测试结束,正常显示:0
}
void main(void)
{
 uchar i,j;
 Delay_xms(50);
 Init_MAX7219();  
 while(1)
 {
  for(j=0;j<38;j++)
  {
   for(i=1;i<9;i++)
    Write_Max7219(i,disp1[j][i-1]);
   Delay_xms(1000);
  }  
 } 
}
Max7219显示字符

资料地址: 提取码:b822

 流水点阵 hello world

//Hello World数组
uchar code array[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x10,0x7E,0x00,0x7C,0x54,0x5C,0x00,
0x7E,0x40,0x00,0x7E,0x40,0x00,0x38,0x44,0x38,0x00,0x3E,0x40,0x38,0x40,0x3E,0x00,
0x38,0x44,0x38,0x00,0x7C,0x08,0x04,0x00,0x7E,0x40,0x00,0x70,0x50,0x7E,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
//hello world!
};
/*********************************************/
 while(1)
 {
  for(j=0;j<38;j++)
  {
   for(i=1;i<9;i++)
   Write_Max7219(i,array[j+i-1]);
   Delay_xms(1000);
  }
hello world

流水点阵 表白爱心

code uchar TAB[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,
              0x81,0xE7,0xE7,0xE7,0xE7,0xE7,0xE7,0x81,0xff, //"I"字
              0x99,0x00,0x00,0x00,0x00,0x81,0xC3,0xE7,0xff, //"红心"
      0x99,0x99,0x99,0x99,0x99,0x99,0xC3,0xE7,  //"U字
      0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};

/*****************************************************/
 while(1)
 {
  for(j=0;j<38;j++)
  {
   for(i=1;i<9;i++)
   Write_Max7219(i,TAB[j+i-1]);
   Delay_xms(1000);
  }  
View Code
 while(1)
     {
        for(j=0;j<38;j++)
        {
         for(i=1;i<9;i++)
                Write_Max7219_1(i,~TAB[j+i-1]);//取反 显示正字
         Delay_xms(1000);
        }  
    }
View Code

 多屏显示(只有一个屏,没测)

#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint  unsigned int
//定义Max7219端口
sbit Max7219_pinCLK = P2^2;
sbit Max7219_pinCS =P2^1;
sbit Max7219_pinDIN = P2^0;
// 首先定义模块的数量
#define MAX7219_NUMS  3  
//Hello World数组
uchar code array[]={//hello world!
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x10,0x7E,0x00,0x7C,0x54,0x5C,0x00,
0x7E,0x40,0x00,0x7E,0x40,0x00,0x38,0x44,0x38,0x00,0x3E,0x40,0x38,0x40,0x3E,0x00,
0x38,0x44,0x38,0x00,0x7C,0x08,0x04,0x00,0x7E,0x40,0x00,0x70,0x50,0x7E,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00

};

code uchar TAB[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,
              0x81,0xE7,0xE7,0xE7,0xE7,0xE7,0xE7,0x81,0xff, //"I"字
              0x99,0x00,0x00,0x00,0x00,0x81,0xC3,0xE7,0xff, //"红心"
      0x99,0x99,0x99,0x99,0x99,0x99,0xC3,0xE7,  //"U字
      0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
uchar code disp1[16][8]={
        {0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x00},
        {0x00,0x00,0x80,0xc0,0xc0,0x80,0x00,0x00},
        {0x00,0x80,0xc0,0x60,0x60,0xc0,0x80,0x00},
        {0x80,0xc0,0x60,0x30,0x30,0x60,0xc0,0x80},
        {0xc0,0x60,0x30,0x18,0x18,0x30,0x60,0xc0},
        {0x60,0x30,0x18,0x0c,0x0c,0x18,0x30,0x60},
        {0x30,0x18,0x0c,0x06,0x06,0x0c,0x18,0x30},
        {0x18,0x0c,0x06,0x03,0x03,0x06,0x0c,0x18},
        {0x0c,0x06,0x03,0x01,0x01,0x03,0x06,0x0c},
        {0x06,0x03,0x01,0x00,0x00,0x01,0x03,0x06},
        {0x03,0x01,0x00,0x00,0x00,0x00,0x01,0x03},
        {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01},
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
};//0

uchar code disp2[16][8]={
        {0x0c,0x06,0x03,0x01,0x01,0x03,0x06,0x0c},
        {0x06,0x03,0x01,0x00,0x00,0x01,0x03,0x06},
        {0x03,0x01,0x00,0x00,0x00,0x00,0x01,0x03},
        {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01},
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
        {0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x00},
        {0x00,0x00,0x80,0xc0,0xc0,0x80,0x00,0x00},
        {0x00,0x80,0xc0,0x60,0x60,0xc0,0x80,0x00},
        {0x80,0xc0,0x60,0x30,0x30,0x60,0xc0,0x80},
        {0xc0,0x60,0x30,0x18,0x18,0x30,0x60,0xc0},
        {0x60,0x30,0x18,0x0c,0x0c,0x18,0x30,0x60},
        {0x30,0x18,0x0c,0x06,0x06,0x0c,0x18,0x30},
        {0x18,0x0c,0x06,0x03,0x03,0x06,0x0c,0x18},   
};   
        


uchar code disp3[38][8]={
{0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C},//0
{0x10,0x18,0x14,0x10,0x10,0x10,0x10,0x10},//1
{0x7E,0x2,0x2,0x7E,0x40,0x40,0x40,0x7E},//2
{0x3E,0x2,0x2,0x3E,0x2,0x2,0x3E,0x0},//3
{0x8,0x18,0x28,0x48,0xFE,0x8,0x8,0x8},//4
{0x3C,0x20,0x20,0x3C,0x4,0x4,0x3C,0x0},//5
{0x3C,0x20,0x20,0x3C,0x24,0x24,0x3C,0x0},//6
{0x3E,0x22,0x4,0x8,0x8,0x8,0x8,0x8},//7
{0x0,0x3E,0x22,0x22,0x3E,0x22,0x22,0x3E},//8
{0x3E,0x22,0x22,0x3E,0x2,0x2,0x2,0x3E},//9
{0x8,0x14,0x22,0x3E,0x22,0x22,0x22,0x22},//A
{0x3C,0x22,0x22,0x3E,0x22,0x22,0x3C,0x0},//B
{0x3C,0x40,0x40,0x40,0x40,0x40,0x3C,0x0},//C
{0x7C,0x42,0x42,0x42,0x42,0x42,0x7C,0x0},//D
{0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x7C},//E
{0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x40},//F
{0x3C,0x40,0x40,0x40,0x40,0x44,0x44,0x3C},//G
{0x44,0x44,0x44,0x7C,0x44,0x44,0x44,0x44},//H
{0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x7C},//I
{0x3C,0x8,0x8,0x8,0x8,0x8,0x48,0x30},//J
{0x0,0x24,0x28,0x30,0x20,0x30,0x28,0x24},//K
{0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x7C},//L
{0x81,0xC3,0xA5,0x99,0x81,0x81,0x81,0x81},//M
{0x0,0x42,0x62,0x52,0x4A,0x46,0x42,0x0},//N
{0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C},//O
{0x3C,0x22,0x22,0x22,0x3C,0x20,0x20,0x20},//P
{0x1C,0x22,0x22,0x22,0x22,0x26,0x22,0x1D},//Q
{0x3C,0x22,0x22,0x22,0x3C,0x24,0x22,0x21},//R
{0x0,0x1E,0x20,0x20,0x3E,0x2,0x2,0x3C},//S
{0x0,0x3E,0x8,0x8,0x8,0x8,0x8,0x8},//T
{0x42,0x42,0x42,0x42,0x42,0x42,0x22,0x1C},//U
{0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18},//V
{0x0,0x49,0x49,0x49,0x49,0x2A,0x1C,0x0},//W
{0x0,0x41,0x22,0x14,0x8,0x14,0x22,0x41},//X
{0x41,0x22,0x14,0x8,0x8,0x8,0x8,0x8},//Y
{0x0,0x7F,0x2,0x4,0x8,0x10,0x20,0x7F},//Z
{0x8,0x7F,0x49,0x49,0x7F,0x8,0x8,0x8},//
{0xFE,0xBA,0x92,0xBA,0x92,0x9A,0xBA,0xFE},//
};



void Delay_xms(uint x)
{
uint i,j;
for(i=0;i<x;i++)
  for(j=0;j<112;j++);
}
void Write_byte(uchar DATA)         
{
    uchar i;   
    Max7219_pinCS=0;  //CS=0有效,CS=1锁存    
    for(i=8;i>=1;i--)
    {                  
        Max7219_pinCLK=0;
        Max7219_pinDIN=DATA&0x80;//&10000000, 编译器对位操作的理解:非0即为1        
        DATA=DATA<<1;
        Max7219_pinCLK=1;  //上升沿把数据送出去
     }                                 
}
//-------------------------------------------  
//功能:向MAX7219写入数据    
//入口参数:chip: 级联芯片编号,0~MAX7219_NUMS-1    
//    address、dat    
void Write_Max7219(uchar chip, uchar address, uchar dat) {    
    int i;    
    Max7219_pinCS=0;    
    for(i=0;i<MAX7219_NUMS;i++) {    
        if(i==chip) {    
            Write_byte(address);    
            Write_byte(dat);   
                    break;                    
        } else {    
            Write_byte(0x00);   //空操作, 
            Write_byte(0x00);   //空操作    
        }    
    }    
    Max7219_pinCS=1;                       
}
//-------------------------------------------  
//功能: 关闭点阵屏显示
//入口参数:无  
void MAX7219_Sleep(void) {  
    int i;    
    for(i=0;i<8*MAX7219_NUMS;i++)    
        Write_Max7219(i/8, i%8+1, 0);    // 黑屏    
    for(i=0;i<MAX7219_NUMS;i++) {    
        Write_Max7219(i, 0x0c, 0x00);       //掉电模式:0,普通模式:1    
    }    
}
//功能: 点阵屏初始化
//入口参数:无  
void MAX7219_Init() {  
    int i=0;    
   // for(;i<MAX7219_NUMS;i++) 
    {    
        Write_Max7219(i, 0x09, 0x00);       //译码方式:BCD码    
        Write_Max7219(i, 0x0a, 0x01);       //亮度    
        Write_Max7219(i, 0x0b, 0x07);       //扫描界限;8个数码管显示    
        Write_Max7219(i, 0x0c, 0x01);       //掉电模式:0,普通模式:1    
        Write_Max7219(i, 0x0f, 0x00);       //显示测试:1;测试结束,正常显示:0    
    }    
//    for(i=0;i<8*MAX7219_NUMS;i++)    
//        Write_Max7219(i/8, i%8+1, 0);    // 黑屏    
}

void main(void)
{
    uchar i,j;
    Delay_xms(50);//Max7219最大10MHZ,所以延迟5毫秒
  MAX7219_Init(); //初始化函数
    //m9init(); 
    while(1)
     {
        for(j=0;j<38;j++)
        {
         for(i=1;i<9;i++)
                Write_Max7219(0,i,~TAB[j+i-1]);//取反 显示正字
         Delay_xms(1000);
        }  
    }
}
多屏显示

 

 参考

 参考2

参考3

posted on 2021-02-02 19:11  荣林  阅读(413)  评论(0编辑  收藏  举报

导航