找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2935|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

TM4C123 GXL庫+MAX7219點(diǎn)陣C語言驅(qū)動

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主

#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數(shù)據(jù)*/
)         
{
        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的寄存器寫入數(shù)據(jù)*/
(
        uint8_t address,                                 /*MAX7219的寄存器地址*/
        uint8_t dat                                                /*要寫入的內(nèi)容*/
)
{
     Max7219_pinCS_L();
         Write_Max7219_byte(address);        //寫入地址,即數(shù)碼管編號
     Write_Max7219_byte(dat);            //寫入數(shù)據(jù),即數(shù)碼管顯示數(shù)字
         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個數(shù)碼管顯示
        Write_Max7219(0x0c, 0x01);               //掉電模式:0,普通模式:1
        Write_Max7219(0x0f, 0x00);               //顯示測試:1;測試結(jié)束,正常顯示:0
        
        /*清空MAX7219數(shù)據(jù)寄存器*/
        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, 下載次數(shù): 7)

評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 回帖助人的獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表