今晚搞了一下MAX7219.
DIN:PC13
LOAD:PC14
CLK:PC15
代码:
#include "delay.h"
#include "sys.h"
#include "led.h"
#define uchar unsigned char
#define uint unsigned int
#define CLK_0 GPIO_ResetBits(GPIOC,GPIO_Pin_15)
#define CLK_1 GPIO_SetBits(GPIOC,GPIO_Pin_15)
#define LOAD_0 GPIO_ResetBits(GPIOC,GPIO_Pin_14)
#define LOAD_1 GPIO_SetBits(GPIOC,GPIO_Pin_14)
#define DIN_0 GPIO_ResetBits(GPIOC,GPIO_Pin_13)
#define DIN_1 GPIO_SetBits(GPIOC,GPIO_Pin_13)
#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(void)
**¹¦ÄÜÃèÊö £º
**ÊäÈë²ÎÊý £ºÎÞ
**Êä³ö²ÎÊý £ºÎÞ
********************************************************************************************************/
int main(void)
{
delay_init();
LED_Init();
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) //ÎÞÏÞÑ»·
{
LED1_TOGGLE();
LED2_TOGGLE();
LED3_TOGGLE();
LED4_TOGGLE();
delay_ms(300);
}
}
效果图:
工程:
MAX7219.rar
(321.15 KB)
|