- #include "HT66F70A.h"
- #include <stdlib.h> //随机函数
- #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
- //下面是函数声明部分
- 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的点阵码 对应0~15,HPLV
- unsigned char const tabIndex[]={0x01,0x02,0x04,0x08};//存放显示位对应的码对应1~4位
- unsigned char Num[4]={0x05,0x09,0x05,0x05};//存放显示位对应的码对应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;//最大数只能是255
- unsigned char mode=0;//0
- void InitPort()
- {
- _wdtc=0xaf;
- LED_Portc = 0x00;//设置为LED口为输出; //关闭看门狗
- _pec = 0x00;//设置E口输出
- _pepu0 = 1;//开启上拉模式
- _pe0 = 0;//输出0
- }
- void main()
- {
- unsigned short int i;
- LED_PortC =0x00;//设置为LED口为输出
- LED_PortBSC=0x00;//设置LED位选口为输出
- unsigned char temp=0x01;
- InitPort();
- LED_Portc = 0x00;//设置为LED口为输出;
- LED_Port = temp;//按位取反,关闭灯显示;
- 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);
- }
- }
- /********************************************************************
- 函数名称:Delay_us
- 函数功能:us秒级别演示
- 输入参数:要延时的时间参数
- 输出参数:无
- *********************************************************************/
- void Delay_us(unsigned int time)
- {
- while(time--);
- }
- /********************************************************************
- 函数名称:openLedLight
- 函数功能:实现单个LED灯的点亮
- 输入参数:Lbit 表示要显示的是4个位里面的哪个位,取值为0~7的数值
- LNum表示要显示的数字的数值,取值为0~15的的数值
- 输出参数:无
- *********************************************************************/
- void openLedLight(unsigned char Lbit, unsigned char LNum)
- {
- LED_Port = 0x00;//关闭端口,停止输出,避免出现重影
- LED_PortBS = tabIndex[Lbit];
- LED_Port =ledTab[LNum];
- }
- /********************************************************************
- 函数名称:dynamicLed
- 函数功能:实现LED的循环动态显示
- 输入参数:Counter 表示要点亮的LED的个数取值1~8
- Light 灯的亮度的控制,数值越大灯越亮,取值范围0~255
- 输出参数:无
- *********************************************************************/
- void dynamicLed(unsigned char Counter,unsigned char Ligh)
- {
- unsigned char i;
- for(i=0;i<Counter;i++)
- {
- Delay_us(Ligh);//实现灯亮度的调整
- 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;
- }
复制代码
|