前几天搞得CCS,今天开搞KEIL。
MSP432驱动MAX7219。
DIN:P4.0;LOAD:P4.2;CLK:P4.4
代码:
#include "msp.h"
#define uchar unsigned char
#define uint unsigned int
#define CLK_0 P4->OUT &= ~BIT4
#define CLK_1 P4->OUT |= BIT4
#define LOAD_0 P4->OUT &= ~BIT2
#define LOAD_1 P4->OUT |= BIT2
#define DIN_0 P4->OUT &= ~BIT0
#define DIN_1 P4->OUT |= BIT0
#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); // ?????????
}
int main(void)
{
volatile uint32_t i;
WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD; // Stop watchdog timer
// The following code toggles P1.0 port
P4->DIR |= BIT0 | BIT2 | BIT4; // Configure P4.0 as output
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)
{
P1->OUT ^= BIT0; // Toggle P1.0
for(i=100000; i>0; i--); // Delay
}
}
效果图:
keil设置,仿真器选择:
烧写算法:
MAX7219模块是我自己做的,原理图,PCB如下:
工程:
MAX7219.rar
(957.99 KB)
|