收到板子了,首先搞一个MAX7219的驱动程序。
代码:
#include "ac78xx_gpio.h"
#include "ac78xx_debugout.h"
#include "ac78xx.h"
#define uchar unsigned char
#define uint unsigned int
/* makesure n < 16 */
#define PAout(n) BIT_ADDR(GPIOA_ODR_ADDR, n)
#define PAin(n) BIT_ADDR(GPIOA_IDR_ADDR, n)
#define PBout(n) BIT_ADDR(GPIOB_ODR_ADDR, n)
#define PBin(n) BIT_ADDR(GPIOB_IDR_ADDR, n)
#define PCout(n) BIT_ADDR(GPIOC_ODR_ADDR, n)
#define PCin(n) BIT_ADDR(GPIOC_IDR_ADDR, n)
#define PDout(n) BIT_ADDR(GPIOD_ODR_ADDR, n)
#define PDin(n) BIT_ADDR(GPIOD_IDR_ADDR, n)
#define PEout(n) BIT_ADDR(GPIOE_ODR_ADDR, n)
#define PEin(n) BIT_ADDR(GPIOE_IDR_ADDR, n)
/* gpio bit-band control */
#define LED PAout(0)
#define CLK_0 PAout(4)=0
#define CLK_1 PAout(4)=1
#define LOAD_0 PAout(2)=0
#define LOAD_1 PAout(2)=1
#define DIN_0 PAout(0)=0
#define DIN_1 PAout(0)=1
#define NoOp 0x00 //??????
#define Digit0 0x01 // ???1???
#define Digit1 0x02 // ???2???
#define Digit2 0x03 // ???3???
#define Digit3 0x04 // ???4???
#define Digit4 0x05 // ???5???
#define Digit5 0x06 // ???6???
#define Digit6 0x07 // ???7???
#define Digit7 0x08 // ???8???
#define DecodeMode 0x09 // ???????
#define Intensity 0x0a // ?????
#define ScanLimit 0x0b // ???????
#define ShutDown 0x0c // ????????
#define DisplayTest 0x0f // ???????
#define ShutdownMode 0x00 // ?????
#define NormalOperation 0x01 // ??????
#define ScanDigit 0x07 // ??????,??8????
#define DecodeDigit 0xff // ????,8???BCD?
#define IntensityGrade 0x0a // ??????
#define TestMode 0x01 // ??????
#define TextEnd 0x00 // ??????,????????
/*****************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
uchar DisBuffer[8]={0,0,0,0,0,0,0,0}; // ?????
//******************??t??**************************************
void delay(uint t)
{
uint i;
while(t--)
{
/* ??12M??,???1ms */
for (i=0;i<125;i++)
{}
}
}
//*************?MAX7219????(8?)********************
void SendChar (uchar ch)
{
uchar i,temp;
delay(1);
for (i=0;i<8;i++)
{
temp=ch&0x80;
ch=ch<<1;
if(temp)
{
DIN_1;
CLK_0;
CLK_1;
}
else
{
DIN_0;
CLK_0;
CLK_1;
}
}
}
//**************?MAX7219???(16?)*****************************
void WriteWord (uchar addr,uchar num)
{
LOAD_0;
delay(1);
SendChar(addr);
delay(1);
SendChar(num);
delay(1);
LOAD_1; // ????????
}
//*********************** MAX7219??? ******************
void InitDisplay (void)
{
WriteWord (ScanLimit,ScanDigit); // ??????
WriteWord (DecodeMode,DecodeDigit); // ??????
WriteWord (Intensity,IntensityGrade); // ????
WriteWord (ShutDown,NormalOperation); // ?????????
}
/**
* main
*
* @param[in] none
* @return none
*
* @brief entry
*
*/
int main(void)
{
InitDebug(); //´òÓ¡³õʼ»¯
InitDelay(); //ÑÓʱº¯Êý³õʼ»¯
GPIO_SetDir(GPIO_PA0, 1);
GPIO_SetDir(GPIO_PA2, 1);
GPIO_SetDir(GPIO_PA4, 1);
InitDisplay (); // MAX7219???
WriteWord(DisplayTest,TestMode); // ??????,????LED
delay(1500); // ???1.5s
WriteWord (DisplayTest,TextEnd); // ????????
WriteWord (Digit0,0);
WriteWord (Digit1,1);
WriteWord (Digit2,2);
WriteWord (Digit3,3);
while (1)
{
// LED = !LED;
// mdelay(500);
}
}
效果图:
|