#include "HT66F0185.h"
#define uint8 unsigned char
#define uint16 unsigned int
#define CLK_0 _pd1=0
#define CLK_1 _pd1=1
#define LOAD_0 _pd0=0
#define LOAD_1 _pd0=1
#define DIN_0 _pa1=0
#define DIN_1 _pa1=1
#define NoOp 0x00 //??2ù×÷??'??÷
#define Digit0 0x01 // êy??1ü1??'??÷
#define Digit1 0x02 // êy??1ü2??'??÷
#define Digit2 0x03 // êy??1ü3??'??÷
#define Digit3 0x04 // êy??1ü4??'??÷
#define Digit4 0x05 // êy??1ü5??'??÷
#define Digit5 0x06 // êy??1ü6??'??÷
#define Digit6 0x07 // êy??1ü7??'??÷
#define Digit7 0x08 // êy??1ü8??'??÷
#define DecodeMode 0x09 // ò?????ê???'??÷
#define Intensity 0x0a // áá?è??'??÷
#define ScanLimit 0x0b // é¨?è??êy??'??÷
#define ShutDown 0x0c // μí1|o???ê???'??÷
#define DisplayTest 0x0f // ??ê?2aê???'??÷
#define ShutdownMode 0x00 // μí1|o?·?ê?
#define NormalOperation 0x01 // ?y3?2ù×÷·?ê?
#define ScanDigit 0x07 // é¨?è??êyéè??????ê?8??êy??1ü
#define DecodeDigit 0xff // ò???éè????8???ù?aBCD??
#define IntensityGrade 0x0a // áá?è??±eéè??
#define TestMode 0x01 // ??ê?2aê???ê?
#define TextEnd 0x00 // ??ê?2aê??áê??????'?y3?1¤×÷??ê?
/*****************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
uint8 DisBuffer[8]={0,0,0,0,0,0,0,0}; // ??ê??o'???
//******************?óê±toá??**************************************
void delay(uint16 t)
{
uint16 i;
while(t--)
{
/* ??óú12Mê±?ó?????óê±1ms */
for (i=0;i<36;i++)
{}
}
}
//*************?òMAX7219D'è?×??ú?¨8????********************
void SendChar (uint8 ch)
{
uint8 i,temp;
delay(1);
for (i=0;i<8;i++)
{
temp=ch&0x80;
ch=ch<<1;
if(temp)
{
DIN_1;
delay(1);
CLK_0;
delay(1);
CLK_1;
delay(1);
}
else
{
DIN_0;
delay(1);
CLK_0;
delay(1);
CLK_1;
delay(1);
}
}
}
//**************?òMAX7219D'è?×??¨16????*****************************
void WriteWord (uint8 addr,uint8 num)
{
LOAD_0;
delay(1);
SendChar(addr);
delay(1);
SendChar(num);
delay(1);
LOAD_1; // ??'????àó|??'??÷
}
//*********************** MAX72193?ê??¯ ******************
void InitDisplay (void)
{
WriteWord (ScanLimit,ScanDigit);// éè??é¨?è???T
WriteWord (DecodeMode,DecodeDigit);// éè??ò?????ê?
WriteWord (Intensity,IntensityGrade); // éè??áá?è
WriteWord (ShutDown,NormalOperation); // éè???a?y3?1¤×÷??ê?
}
void delay_ms(uint16 ms)
{
//1ms
GCC_DELAY(2000);
}
void main()
{
_wdtc=0xa8;
_pdc=0;
_pac=0;
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)
{
WriteWord(DisplayTest,TestMode);// ??????,????LED
delay(150); // ???1.5s
WriteWord (DisplayTest,TextEnd);// ????????
WriteWord (Digit0,0);
WriteWord (Digit1,1);
WriteWord (Digit2,2);
WriteWord (Digit3,3);
}
}
效果图
不知道怎么回事,仿真调试可以,去掉仿真器,给板子通电就不行了。
|