#include
#include
//#include
/*--------------------------------------------------*/
sbitdis_DIN=P1^0;/*顯示串行數(shù)據(jù)輸入端*/
sbitdis_LOAD=P1^1;/*顯示數(shù)據(jù)鎖存端*/
sbitdis_CLK=P1^2;/*顯示時(shí)鐘輸入端*/
#defineNoOp0x00/*空操作*/
#defineDigit00x01/*數(shù)碼管1*/
#defineDigit10x02/*數(shù)碼管2*/
#defineDigit20x03/*數(shù)碼管3*/
#defineDigit30x04/*數(shù)碼管4*/
#defineDigit40x05/*數(shù)碼管5*/
#defineDigit50x06/*數(shù)碼管6*/
#defineDigit60x07/*數(shù)碼管7*/
#defineDigit70x08/*數(shù)碼管8*/
#defineDecodeMode0x09/*譯碼模式*/
#defineIntensity0x0a/*亮度*/
#defineScanLimit0x0b/*掃描界限*/
#defineShutDown0x0c/*掉電模式*/
#defineDisplayTest0x0f/*顯示測試*/
#defineShutdownMode0x00/*掉電方式工作*/
#defineNormalOperation0x01/*正常操作方式*/
#defineDecodeDigit0xff/*譯碼位數(shù)設(shè)置*/
#defineIntensityGrade0x0a/*顯示亮度級(jí)別設(shè)置*/
#defineScanDigit0x07/*掃描位數(shù)設(shè)置*/
#defineTestMode0x01/*顯示測試方式*/
#defineTextEnd0x00/*顯示測試結(jié)束,正常工作*/
unsignedchardataDisBuffer[8]={0,0,0,0,0,0,0,0};/*顯示緩存區(qū)*/
unsignedcharcodedispaly_list[]=
{
0x7e,0x30,0x6d,0x79,0x33,0x5b,0x5f,0x70,0x7f,0x7b,/*0,1,2,3,4,5,6,7,8,9*/
0x77,0x1f,0x4e,0x3d,0x4f,0x47,0x67,0x3e,0xff,0x00};/*A,B,C,D,E,F,P,U,全
亮,全滅*/
/*--------------------------------------------------------
10ms延時(shí)子程序
---------------------------------------------------------*/
voiddelayX10ms(unsignedcharcount)
{
unsignedcharj,k;
while(count--!=0)
{
for(j=0;j<43;j++)
for(k=0;k<73;k++)
;
}
}
/*-------------------------------------------------
向MAX7219寫入字節(jié)(8位)
--------------------------------------------------*/
voidSendChar(unsignedcharch)
{
unsignedchari,temp;
_nop_();
for(i=0;i<8;i++)
{
temp=ch&0x80;
ch=ch<<1;
if(temp)
{
dis_DIN=1;
dis_CLK=0;
dis_CLK=1;
}
else
{
dis_DIN=0;
dis_CLK=0;
dis_CLK=1;
}
}
}
/*-------------------------------------------------
向MAX7219寫入字(16位)
-------------------------------------------------*/
voidWriteWord(unsignedcharaddr,unsignedcharnum)
{
dis_LOAD=0;
_nop_();
SendChar(addr);
_nop_();
SendChar(num);
_nop_();
dis_LOAD=1;
}
/*-------------------------------------------------
MAX7219初始化
-------------------------------------------------*/
voidInitDis(void)
{
WriteWord(ScanLimit,ScanDigit);/*設(shè)置掃描界限*/
WriteWord(DecodeMode,DecodeDigit);/*設(shè)置譯碼模式*/
WriteWord(Intensity,IntensityGrade);/*設(shè)置亮度*/
WriteWord(ShutDown,NormalOperation);/*設(shè)置電源工作模式*/
}
/*-------------------------------------------------
系統(tǒng)上電初始化
-------------------------------------------------*/
voidInitMain(void)
{
IE=0x00;/*設(shè)置中斷允許寄存器*/
IP=0x00;/*設(shè)置中斷優(yōu)先級(jí)管理寄存器*/
TH0=0xd8;/*設(shè)定時(shí)器初值,10ms*/
TL0=0xf0;
TMOD=0x01;/*T1定時(shí)器模式2,波特率發(fā)生器,T0定時(shí)器模式1*/
TCON=0x11;/*設(shè)置定時(shí)器控制寄存器,INT0設(shè)置為邊沿觸發(fā)方式*/
PSW=0x00;
}
/*-------------------------------------------------
主函數(shù)
-------------------------------------------------*/
voidmain(void)
{
InitMain();
InitDis();
WriteWord(DisplayTest,TestMode);
delayX10ms(0x64);
delayX10ms(0x64);
WriteWord(DisplayTest,TextEnd);
while(1)
{
unsignedchari;
for(i=0;i<=9;i++)
{
delayX10ms(0x64);
delayX10ms(0x64);
InitDis();
DisBuffer[0]=i;
DisBuffer[1]=i;
DisBuffer[2]=i;
DisBuffer[3]=i;
DisBuffer[4]=i;
DisBuffer[5]=i;
DisBuffer[6]=i;
DisBuffer[7]=i;
WriteWord(Digit0,DisBuffer[0]);
WriteWord(Digit1,DisBuffer[1]);
WriteWord(Digit2,DisBuffer[2]);
WriteWord(Digit3,DisBuffer[3]);
WriteWord(Digit4,DisBuffer[4]);
WriteWord(Digit5,DisBuffer[5]);
WriteWord(Digit6,DisBuffer[6]);
WriteWord(Digit7,DisBuffer[7]);
}
}
}