|
- #include "HT66F70A.h"
- #include <stdlib.h> //隨機(jī)函數(shù)
- #include <time.h>
- #define LED_Port _pc
- #define LED_PortC _pcc
- #define LED_PortBSC _pdc
- #define LED_PortBS _pd
- #define LED1_Port _pg
- #define LED_Portc _pgc
- #define KEY_PORTC _pec
- #define KEY_PORT _pe
- #define KeyPortPU _pepu
- //下面是函數(shù)聲明部分
- void openLedLight(unsigned char Lbit, unsigned char LNum);
- void dynamicLed(unsigned char Counter,unsigned char Ligh);
- unsigned char const ledTab[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71,0x76,0x73,0x38,0x3e};//存放LED的點(diǎn)陣碼 對(duì)應(yīng)0~15,HPLV
- unsigned char const tabIndex[]={0x01,0x02,0x04,0x08};//存放顯示位對(duì)應(yīng)的碼對(duì)應(yīng)1~4位
- unsigned char Num[4]={0x05,0x09,0x05,0x05};//存放顯示位對(duì)應(yīng)的碼對(duì)應(yīng)1~4位
- unsigned int counter =0;
- unsigned int time=60;
- unsigned int time1=55;
- const unsigned short pili_TAB[] = {0x21,0x0C,0x12,0x28,0x05,0x3F};
- unsigned short ScanKey();
- unsigned char keyNum=0;//最大數(shù)只能是255
- unsigned char mode=0;//0
- void InitPort()
- {
- _wdtc=0xaf;
- LED_Portc = 0x00;//設(shè)置為L(zhǎng)ED口為輸出; //關(guān)閉看門狗
- _pec = 0x00;//設(shè)置E口輸出
- _pepu0 = 1;//開(kāi)啟上拉模式
- _pe0 = 0;//輸出0
- }
- void main()
- {
- unsigned short int i;
- LED_PortC =0x00;//設(shè)置為L(zhǎng)ED口為輸出
- LED_PortBSC=0x00;//設(shè)置LED位選口為輸出
- unsigned char temp=0x01;
- InitPort();
- LED_Portc = 0x00;//設(shè)置為L(zhǎng)ED口為輸出;
- LED_Port = temp;//按位取反,關(guān)閉燈顯示;
- openLedLight(0,5);
- while(1)
- {
- keyNum=ScanKey();
- if(keyNum==0)
- {
- mode=1;
-
- }
-
- else if(keyNum==1)
- {
- mode=2;
- }
- else if(keyNum==2)
- {
- mode=3;
- }
- else if(keyNum==3)
- {
- mode=4;
- }
- else if(keyNum==4)
- {
- mode=5;
- }
- if(mode==1)
- {
- counter++;
- if(counter>=6000)
- { time--;
- Num[0]=time/10;
- Num[1]=time%10;
- time1--;
- Num[2]=time1/10;
- Num[3]=time1%10;
-
- if(time>30){LED1_Port = pili_TAB[0];}
- if(time<=30){LED1_Port = pili_TAB[1];}
- for(i=0;i<80;i++)
- {
- _clrwdt();
- GCC_DELAY(5000);
- }
-
- if(time==0)
- {
- time=60;
- }
- if(time1==0)
- {
- time1=55;
- }
- counter=0;
- }
- }
-
- if(mode==2)
- {
- LED1_Port = pili_TAB[2];
- }
-
- if(mode==3)
- {
- LED1_Port = pili_TAB[3];
- }
- if(mode==4)
- {
- LED1_Port = pili_TAB[4];
- }
- if(mode==5)
- {
- LED1_Port = pili_TAB[5];
- }
-
- _clrwdt();//喂狗
- dynamicLed(4,255);
- }
- }
- /********************************************************************
- 函數(shù)名稱:Delay_us
- 函數(shù)功能:us秒級(jí)別演示
- 輸入?yún)?shù):要延時(shí)的時(shí)間參數(shù)
- 輸出參數(shù):無(wú)
- *********************************************************************/
- void Delay_us(unsigned int time)
- {
- while(time--);
- }
- /********************************************************************
- 函數(shù)名稱:openLedLight
- 函數(shù)功能:實(shí)現(xiàn)單個(gè)LED燈的點(diǎn)亮
- 輸入?yún)?shù):Lbit 表示要顯示的是4個(gè)位里面的哪個(gè)位,取值為0~7的數(shù)值
- LNum表示要顯示的數(shù)字的數(shù)值,取值為0~15的的數(shù)值
- 輸出參數(shù):無(wú)
- *********************************************************************/
- void openLedLight(unsigned char Lbit, unsigned char LNum)
- {
- LED_Port = 0x00;//關(guān)閉端口,停止輸出,避免出現(xiàn)重影
- LED_PortBS = tabIndex[Lbit];
- LED_Port =ledTab[LNum];
- }
- /********************************************************************
- 函數(shù)名稱:dynamicLed
- 函數(shù)功能:實(shí)現(xiàn)LED的循環(huán)動(dòng)態(tài)顯示
- 輸入?yún)?shù):Counter 表示要點(diǎn)亮的LED的個(gè)數(shù)取值1~8
- Light 燈的亮度的控制,數(shù)值越大燈越亮,取值范圍0~255
- 輸出參數(shù):無(wú)
- *********************************************************************/
- void dynamicLed(unsigned char Counter,unsigned char Ligh)
- {
- unsigned char i;
- for(i=0;i<Counter;i++)
- {
- Delay_us(Ligh);//實(shí)現(xiàn)燈亮度的調(diào)整
- openLedLight(i,Num[i]);
- }
- }
- unsigned short ScanKey()
- { unsigned char i,key=0;
- KEY_PORTC=0x0f;
- KeyPortPU=0x0f; //I/O Mode Config & Pull-up Enable
- KEY_PORT=0b11101111; //Initial Scancode
- for(i=0;i<=3;i++)
- { if(!(KEY_PORT & 1)) break; //Check Column 0
- key++;
- if(!(KEY_PORT & 1<<1)) break; //Check Column 1
- key++;
- if(!(KEY_PORT & 1<<2)) break; //Check Column 2
- key++;
- if(!(KEY_PORT & 1<<3)) break; //Check Column 3
- key++;
- KEY_PORT<<=1; KEY_PORT|=0b0000001; //Scancode for Next Row
- }
- return key;
- }
復(fù)制代碼
|
|