OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 5732|回复: 2

max7219 求教

[复制链接]

1

主题

1

帖子

0

精华

新手入门

积分
25
金钱
25
注册时间
2013-5-16
在线时间
0 小时
发表于 2014-1-23 21:30:45 | 显示全部楼层 |阅读模式

這是針對max7219寫的code,但無法顯示0-9,可以給些建議嗎?

#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
//pin define
#define   Max7219_pinDIN  GPIO_Pin_0   //Max7219_pinCLK=PD0
#define   Max7219_pinCS   GPIO_Pin_1  //Max7219_pinCS=PD1
#define   Max7219_pinCLK   GPIO_Pin_2 //Max7219_pinDIN=PD2

#define   Max7219_pinCLK_0    GPIO_ResetBits(GPIOD,Max7219_pinCLK);
#define   Max7219_pinCLK_1    GPIO_SetBits(GPIOD,Max7219_pinCLK);

#define   Max7219_pinCS_0       GPIO_ResetBits(GPIOD, Max7219_pinCS);
#define   Max7219_pinCS_1       GPIO_SetBits(GPIOD, Max7219_pinCS);

#define   Max7219_pinDIN_0     GPIO_ResetBits(GPIOD, Max7219_pinDIN);
#define   Max7219_pinDIN_1     GPIO_SetBits(GPIOD, Max7219_pinDIN);


#define uchar unsigned char
#define uint unsigned  int

GPIO_InitTypeDef  GPIO_InitStructure;

uchar disp1[2][8]={
{0x003C,0x0042,0x0042,0x0042,0x0042,0x0042,0x0042,0x003C}, //0
{0x0010,0x0018,0x0014,0x0010,0x0010,0x0010,0x0010,0x0010}, //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
};

void Delay_xms(uint x)
{
 uint i,j;
 for(i=0;i<x;i++)
  for(j=0;j<112;j++);
}
void Write_Max7219_byte(uchar DATA)
{
     uchar i;
  Max7219_pinCS_0;
     for(i=8;i>=1;i--)
          {
            Max7219_pinCLK_0;
            //Max7219_pinDIN=DATA&0x80;
            if(DATA&0x80)
            {
                Max7219_pinDIN_1;
            }
            else
            {
                Max7219_pinDIN_0;
        DATA=DATA<<1;
        Max7219_pinCLK_1;
            }
         }
}

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
}

 


int main(void)
{
 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);

   /* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */
   GPIO_InitStructure.GPIO_Pin = Max7219_pinCLK|Max7219_pinCS|Max7219_pinDIN;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
   GPIO_Init(GPIOD, &GPIO_InitStructure);
    while(1)
    {
     uchar i,j;
     Delay_xms(50);
      Init_MAX7219();
   Delay_xms(50);
      for(j=0;j<10;j++)
       {
        for(i=1;i<9;i++)
         Write_Max7219(i,disp1[j][i-1]);
        Delay_xms(200);
       }
    Write_Max7219(0x0f, 0x01);
   Delay_xms(500);
   Write_Max7219(0x0f, 0x00);
      }
    }

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165536
金钱
165536
注册时间
2010-12-1
在线时间
2117 小时
发表于 2014-1-24 09:25:44 | 显示全部楼层
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复 支持 反对

使用道具 举报

57

主题

195

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
446
金钱
446
注册时间
2013-2-20
在线时间
1 小时
发表于 2014-1-24 22:37:35 | 显示全部楼层
用TM1638
回复 支持 反对

使用道具 举报

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

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-9 23:49

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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