找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1876|回复: 2
打印 上一主题 下一主题
收起左侧

用MPS显示MAX7219矩阵灯 求大神帮忙 改错

[复制链接]
跳转到指定楼层
楼主
2黑币
单片机小白求组大神
我的VCC连接5V; GND连接GND; DIN连接P22;CS连接P21;CLk连接P20
我用下面的程序考入到板子中 ,灯就是单纯的全量,而不是按照我的程序变换;
有我的连接图片
想知道我出错出在了哪里, 程序的问题还是什么问题, 如何解决?

#include "io430.h"
//定义Max7219端口
#define CLK_0 P2OUT |= BIT0;
#define CLK_1 P2OUT &= ~BIT0;
#define CS_0 P2OUT |= BIT1;
#define CS_1 P2OUT &= ~BIT1;
#define DIN_0 P2OUT |= BIT2;
#define DIN_1 P2OUT &= ~BIT2;

#define CPU_F ((double)8000000)   //外部高频晶振8MHZ
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))

//自定义数据结构,方便使用
#define uchar unsigned char
#define uint  unsigned int
#define ulong unsigned long

void close_dog()
{
   WDTCTL = WDTPW + WDTHOLD;       //关闭看门狗
}

uchar const 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},//国
};  

//--------------------------------------------
//功能:向MAX7219(U3)写入字节
//入口参数:DATA
//出口参数:无
//说明:
void Write_Max7219_byte(uchar DATA)         
{
   

IMG_20180411_235024.jpg (2.73 MB, 下载次数: 69)

IMG_20180411_235024.jpg
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:304841 发表于 2018-4-12 00:00 | 只看该作者
#include "io430.h"
//定义Max7219端口
#define CLK_0 P2OUT |= BIT0;
#define CLK_1 P2OUT &= ~BIT0;
#define CS_0 P2OUT |= BIT1;
#define CS_1 P2OUT &= ~BIT1;
#define DIN_0 P2OUT |= BIT2;
#define DIN_1 P2OUT &= ~BIT2;

#define CPU_F ((double)8000000)   //外部高频晶振8MHZ
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))

//自定义数据结构,方便使用
#define uchar unsigned char
#define uint  unsigned int
#define ulong unsigned long

void close_dog()
{
   WDTCTL = WDTPW + WDTHOLD;       //关闭看门狗
}

uchar const 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},//国
};  

//--------------------------------------------
//功能:向MAX7219(U3)写入字节
//入口参数:DATA
//出口参数:无
//说明:
void Write_Max7219_byte(uchar DATA)         
{
            uchar i,temp;                   
            for(i=8;i>=1;i--)
          {                  
            temp=DATA&0x80;
            DATA=DATA<<1;
            if(temp)
              DIN_1;
            if(!temp)
              DIN_0;
            CLK_0;
            delay_ms(500);
            CLK_1;
           }                                 
}
//-------------------------------------------
//功能:向MAX7219写入数据
//入口参数:address、dat
//出口参数:无
//说明:
void Write_Max7219(uchar address,uchar dat)
{
     CS_0;
     delay_ms(500);
     Write_Max7219_byte(address);           //写入地址,即数码管编号
     delay_ms(500);
     Write_Max7219_byte(dat);               //写入数据,即数码管显示数字
     delay_ms(500);
     CS_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)
{
close_dog();
P2SEL&=~(BIT0+BIT1+BIT2);
P2DIR |=BIT0+BIT1+BIT2;
uchar i,j;
delay_ms(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_ms(1000);
  }  
}
}
回复

使用道具 举报

板凳
ID:304841 发表于 2018-4-12 00:02 | 只看该作者
/--------------------------------------------
//功能:向MAX7219(U3)写入字节
//入口参数:DATA
//出口参数:无
//说明:
void Write_Max7219_byte(uchar DATA)         
{
            uchar i,temp;                   
            for(i=8;i>=1;i--)
          {                  
            temp=DATA&0x80;
            DATA=DATA<<1;
            if(temp)
              DIN_1;
            if(!temp)
              DIN_0;
            CLK_0;
            delay_ms(500);
            CLK_1;
           }                                 
}
//-------------------------------------------
//功能:向MAX7219写入数据
//入口参数:address、dat
//出口参数:无
//说明:
void Write_Max7219(uchar address,uchar dat)
{
     CS_0;
     delay_ms(500);
     Write_Max7219_byte(address);           //写入地址,即数码管编号
     delay_ms(500);
     Write_Max7219_byte(dat);               //写入数据,即数码管显示数字
     delay_ms(500);
     CS_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)
{
close_dog();
P2SEL&=~(BIT0+BIT1+BIT2);
P2DIR |=BIT0+BIT1+BIT2;
uchar i,j;
delay_ms(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_ms(1000);
  }  
}
}

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表