找回密码
 立即注册

QQ登录

只需一步,快速开始

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

TM4C123 GXL库+MAX7219点阵C语言驱动

[复制链接]
跳转到指定楼层
楼主

#ifndef __U_MAX7219_H__
#define __U_MAX7219_H__

/*Include==================================================================================*/
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
/*Define===================================================================================*/

/*Port----------------------------------------*/
#define Max7219_pinCS_H()        GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_1,GPIO_PIN_1)
#define Max7219_pinCS_L()        GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_1,0)

#define Max7219_pinCLK_H()        GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_2,GPIO_PIN_2)
#define Max7219_pinCLK_L()        GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_2,0)

#define Max7219_pinDIN_H()        GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_3,GPIO_PIN_3)
#define Max7219_pinDIN_L()        GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_3,0)

/*Function=================================================================================*/
void Write_Max7219_byte(uint8_t DATA);
void Write_Max7219(uint8_t address,uint8_t dat);
void Init_MAX7219(void);
void U_8X8_Lattice_Show_Byte(uint8_t addres,uint8_t byteData);
void U_8X8_Lattice_Show_Icon(uint8_t *icon);

#endif /*__U_MAX7219_H__*/


#include "U_MAX7219.h"



void Write_Max7219_byte        /*向MAX7219传输1Byte*/
(
        uint8_t DATA                /*1Byte数据*/
)         
{
        uint8_t i;   
        Max7219_pinCS_L();               
        
        for(i=8;i>=1;i--)
          {                  
                Max7219_pinCLK_L();

                if(DATA & 0x80)
                {
                        Max7219_pinDIN_H();
                }
                else
                {
                        Max7219_pinDIN_L();
                }
                DATA=DATA<<1;
                Max7219_pinCLK_H();
           }                                 
}

void Write_Max7219                                        /*向MAX7219的寄存器写入数据*/
(
        uint8_t address,                                 /*MAX7219的寄存器地址*/
        uint8_t dat                                                /*要写入的内容*/
)
{
     Max7219_pinCS_L();
         Write_Max7219_byte(address);        //写入地址,即数码管编号
     Write_Max7219_byte(dat);            //写入数据,即数码管显示数字
         Max7219_pinCS_H();                        
}


void Init_MAX7219(void)                                 /*MAX7219初始化*/
{
        uint32_t i;
        Write_Max7219(0x09, 0x00);               //译码方式:BCD码
        Write_Max7219(0x0a, 0x02);               //亮度
        Write_Max7219(0x0b, 0x07);               //扫描界限;8个数码管显示
        Write_Max7219(0x0c, 0x01);               //掉电模式:0,普通模式:1
        Write_Max7219(0x0f, 0x00);               //显示测试:1;测试结束,正常显示:0
        
        /*清空MAX7219数据寄存器*/
        for(i=1;i<9;i++)
        {
                Write_Max7219(i,0x00);
        }
}

void U_8X8_Lattice_Show_Byte(uint8_t addres,uint8_t byteData)
{

        if((byteData & 0x01) == 1)
        {
                byteData = byteData ;
                byteData |= 0x80;
        }
        else
        {
                byteData = byteData ;
        }
        Write_Max7219(addres,byteData);
}

void U_8X8_Lattice_Show_Icon(uint8_t *icon)
{
        uint32_t i;
        for(i=1;i<9;i++)
        {
                U_8X8_Lattice_Show_Byte(i,icon[i-1]);
        }
}



#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"


#include "U_MAX7219.h"

uint32_t systemClock;

uint8_t disl[14][8]=
{
{0x00,0x08,0x14,0x28,0x28,0x14,0x08,0x00},
{0x08,0x14,0x22,0x44,0x44,0x22,0x14,0x08},
{0x1E,0x3F,0x7F,0xFE,0xFE,0x7F,0x3F,0x1E},
{0x00,0x1E,0x20,0x3C,0x3C,0x20,0x1E,0x00},
{0x00,0x42,0x24,0x18,0x18,0x24,0x42,0x00},
{0x00,0x00,0x02,0x04,0x78,0x04,0x02,0x00},
{0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00},
{0x00,0x00,0x18,0x3C,0x3C,0x18,0x00,0x00},        
{0x00,0x18,0x3C,0x7C,0x7C,0x3C,0x18,0x00},
{0x0C,0x1E,0x3E,0x7C,0x7C,0x3E,0x1E,0x0C},
{0x0C,0x1E,0x3E,0x7C,0x7C,0x3E,0x1E,0x0C},
{0x00,0x00,0x3E,0x08,0x08,0x3E,0x00,0x00},
{0x00,0x00,0x12,0x22,0x3E,0x02,0x02,0x00},
{0x00,0x42,0x24,0x18,0x18,0x24,0x42,0x00},
};

//*****************************************************************************
//
//! \addtogroup example_list
//! <h1>Simple Project (project)</h1>
//!
//! A very simple example that can be used as a starting point for more complex
//! projects.  Most notably, this project is fully TI BSD licensed, so any and
//! all of the code (including the startup code) can be used as allowed by that
//! license.
//!
//! The provided code simply toggles a GPIO using the Tiva Peripheral Driver
//! Library.
//
//*****************************************************************************

//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************

//*****************************************************************************
//
// Toggle a GPIO.
//
//*****************************************************************************

void U_GPIO_Init(void)
{
           SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
     SysCtlDelay(1);
        

                GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE,GPIO_PIN_1);
                GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE,GPIO_PIN_3);
                GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE,GPIO_PIN_2);
}


int main(void)
{

        uint8_t n;
        U_GPIO_Init();

        SysCtlDelay(5000000);


        U_GPIO_Init();
        Init_MAX7219();
         U_8X8_Lattice_Show_Icon(displ[10]);
                        
    while(1)
    {

        for(n=0;n<14;n++)
         {
                             U_8X8_Lattice_Show_Icon(disl[n]);
                               SysCtlDelay(5000000);
          }
                        
      }
}



这2个C语言文件下载: TI-MAX7219.rar (3.09 KB, 下载次数: 7)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 回帖助人的奖励!

查看全部评分

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

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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