|
- //*************************************************************************************************
- //*************************************************************************************************
- //**<程序名>:LED動(dòng)態(tài)掃描子函數(shù)。 **
- //**<功能>: unsigned char * pucLedNum(unsigned long ulNumber); **
- //** 計(jì)算一個(gè)在000000到999999之間的數(shù)的每位數(shù)字并存儲(chǔ)在數(shù)組中.并返回?cái)?shù)組的首地址 **
- //** void vShowOneNum(unsigned char ucOneNum,unsigned char ucOrder); **
- //** 輸入一個(gè)數(shù)字以及所要顯示的位置,在LED相應(yīng)位置上顯示相應(yīng)數(shù)字. **
- //*************************************************************************************************
- //*************************************************************************************************
- //*************************************************************************************************
- //* *
- //* ******************************頭文件及宏定義************************** *
- //* *
- //*************************************************************************************************
- #include "LED6Show.h"
- //*************************************************************************************************
- //* *
- //* ********************************全局變量****************************** *
- //* *
- //*************************************************************************************************
- unsigned char code uca_LEDCode[]=
- {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xFF};
- //0,1,2,3,4,5,6,7,8,9,空白。
- unsigned char code uca_LEDSelect[]=
- {0x01,0x02,0x04,0x08,0x10,0x20};
- //分別點(diǎn)亮第6,5,4,3,2,1號(hào)燈。
- unsigned char uca_LedNum[6];
- //存放數(shù)字的各個(gè)位。
- unsigned char uc_NumberFront=1; //只是數(shù)字的首位。
- extern unsigned char uca_ShowCustom[]; //在自定義模式下,LCD實(shí)時(shí)顯示該字符。main.c
- //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<自定義報(bào)告顯示字符>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- unsigned char uca_ReportChar1[]={0xBF,0x86,0xC0,0x88,0xBF,0xF9};
- //被除數(shù)等于0。 -EOR-1
- unsigned char uca_ReportChar2[]={0xBF,0x86,0xC0,0x88,0xBF,0xA4};
- //被減數(shù)小于減數(shù)。 -EOR-2
- unsigned char uca_ReportChar3[]={0xC6,0x89,0x88,0xC2,0xBF,0xF9};
- //表明從計(jì)算器模式切換到計(jì)時(shí)模式。 CHAG-1
- unsigned char uca_ReportChar4[]={0xC6,0x89,0x88,0xC2,0xBF,0xC0};
- //表明從計(jì)時(shí)器模式切換到計(jì)算器模式。 CHAG-0
- unsigned char uca_ReportChar5[]={0xBF,0x8C,0x88,0xC1,0x92,0x86};
- //暫停 -PAUSE
- //unsigned char uca_ReportChar6[]={0xBF,0x92,0x87,0x88,0x88,0x87};
- //開(kāi)始 -START
- unsigned char uca_ReportChar7[]={0xBF,0x92,0x87,0xC0,0x8C,0xBF};
- //停止 -StoP-
- unsigned char uca_ReportChar8[]={0xC0,0x8C,0x8C,0xC0,0x92,0x86};
- //切換到倒計(jì)時(shí)模式 OPPPOSE
- unsigned char uca_ReportChar9[]={0xBF,0x86,0xC0,0x88,0xBF,0x90};
- //超出可顯示的最大值。 -EOR-9
- //*************************************************************************************************
- //* *
- //* ********************************函數(shù)實(shí)現(xiàn)****************************** *
- //* *
- //*************************************************************************************************
- unsigned char * pucLedNum(unsigned long ulNumber) //將一個(gè)數(shù)的各個(gè)位分別存到數(shù)組里。
- { //并返回首地址。
- if(ulNumber>999999)
- ulNumber=999999;
- if(ulNumber<0)
- ulNumber=0;
- uca_LedNum[5] = ulNumber/100000; //最高位存在數(shù)組【5】中。
- uca_LedNum[4] = (ulNumber-100000*(long)uca_LedNum[5])/10000;
- uca_LedNum[3] = (ulNumber-100000*(long)uca_LedNum[5]-10000*(long)uca_LedNum[4])/1000;
- uca_LedNum[2] = (ulNumber-100000*(long)uca_LedNum[5]-10000*(long)uca_LedNum[4]
- -1000*(long)uca_LedNum[3])/100;
- uca_LedNum[1] = (ulNumber-100000*(long)uca_LedNum[5]-10000*(long)uca_LedNum[4]
- -1000*(long)uca_LedNum[3]-100*(long)uca_LedNum[2])/10;
- uca_LedNum[0] = (ulNumber-100000*(long)uca_LedNum[5]-10000*(long)uca_LedNum[4]
- -1000*(long)uca_LedNum[3]-100*(long)uca_LedNum[2]-10*(long)uca_LedNum[1]);
-
- //最低位存在數(shù)組【0】中。
- for(uc_NumberFront=1;uc_NumberFront<6;uc_NumberFront++)
- {
- if(uca_LedNum[6-uc_NumberFront]!=0) //判斷數(shù)據(jù)的首位不為零數(shù)字在第幾位。
- break; //例如:8502的uc_NumberFront為3;
- } // 0的uc_NumberFront為6;
- // 450530的uc_NumberFront為1。
- return uca_LedNum;
- }
- //*********************************************************************************************************
- //* *
- //* *****************************將1個(gè)1位數(shù)按順序顯示**************************** *
- //* *
- //*********************************************************************************************************
- void vShowOneNum(unsigned char ucOneNum,unsigned char ucOrder)
- {
- if(ucOneNum!=0) //如果數(shù)字不為0則正常輸出。
- {
- LEDSELECT=0;
- LEDCHAR=uca_LEDCode[ucOneNum]; //ucOrder:1~6
- LEDSELECT=uca_LEDSelect[ucOrder-1];
- }
- else
- {
- if(ucOrder<uc_NumberFront) //如果為0則判斷是不是在數(shù)字首位之前。
- LEDSELECT=0; //如果在則輸出空,不顯示數(shù)據(jù)。
- else
- {
- LEDSELECT=0; //如果在首位之后則正常輸出。
- LEDCHAR=uca_LEDCode[ucOneNum];
- LEDSELECT=uca_LEDSelect[ucOrder-1];
- }
- }
- }
- //*********************************************************************************************************
- //* *
- //* ***************************將1個(gè)自定義字符按順序顯示************************* *
- //* *
- //*********************************************************************************************************
- void vShowCustom(unsigned char ucOneCostom,unsigned ucOrder)
- {
- LEDSELECT=0;
- LEDCHAR=ucOneCostom;
- LEDSELECT=uca_LEDSelect[ucOrder]; //ucOrder:0~5
- }
- //*********************************************************************************************************
- //* *
- //* ***********************將字符數(shù)組復(fù)制到字符顯示數(shù)組中************************* *
- //* *
- //*********************************************************************************************************
- void vCharCopy(unsigned char ucaArray[])
- {
- unsigned char ucCount;
- for(ucCount=0;ucCount<6;ucCount++)
- {
- uca_ShowCustom[ucCount]=ucaArray[ucCount];
- }
- }
- //*********************************************************************************************************
- //* *
- //* ***********************根據(jù)報(bào)告代號(hào),顯示不同的報(bào)告字符************************* *
- //* *
- //*********************************************************************************************************
- void vShowReport(unsigned char ucSymbol)
- {
- switch(ucSymbol)
- {
- case 1:vCharCopy(uca_ReportChar1);break; //顯示:-EOR-1--被除數(shù)等于0;
- case 2:vCharCopy(uca_ReportChar2);break; //顯示:-EOR-2--被減數(shù)小于減數(shù);
- case 3:vCharCopy(uca_ReportChar3);break; //顯示:CHAG-1--表明從計(jì)算器模式切換到計(jì)時(shí)模式;
- case 4:vCharCopy(uca_ReportChar4);break; //顯示:CHAG-0--表明從計(jì)時(shí)器模式切換到計(jì)算器模式;
- case 5:vCharCopy(uca_ReportChar5);break; //顯示:-PAUSE--暫停;
- // case 6:vCharCopy(uca_ReportChar6);break; //顯示:-StART--開(kāi)始;
- case 7:vCharCopy(uca_ReportChar7);break; //顯示:-StoP---停止;
- case 8:vCharCopy(uca_ReportChar8);break; //顯示:OPPOSE--切換到倒計(jì)時(shí)模式;
- case 9:vCharCopy(uca_ReportChar9);break; //顯示:-EOR-9--超出可顯示的最大值。
- default:break;
- }
- }
復(fù)制代碼 |
|