📄 key.c~rfa96fda.tmp
字号:
#include "msp430X16x.h"
#include "KEY.h"
#include "LCDdriver.h"
#include "PCF8563.h"
#include "stdbool.h"
unsigned char flagA,flagB,flagC,flagD;
bool K2_Value,K3_Value;
static unsigned int K1_Count=0;
bool K4_Value;
static unsigned char Count;
/*
static unsigned char PCF_time[6]={ //将数据暂存于PCF_time
0x18,//秒(vl、00~59BCD码)
0x28,//分(-、00~59BCD码)
0x22,//时(-、-、00~23BCD码)
0x26,//日(-、-、01~31BCD码)
0x06,//世纪月(c、-、-、01~12BCD码)
0x08,//年(00~99BCD码)
};
*/
//延时子程序
void Delay_Interrupt_MS(char ms){
uint i;
while(ms--){
for(i=0; i<800;i++);
}
}
/*
void Interrupt_Key_Port()
{
// P2SEL=0x00;//P2口所有引脚设置为一般的IO口
// P5SEL=0x00;//P5口所有引脚设置为一般的IO口
// P2DIR=0xFF;//P2口所有引脚设置为输出方向
// P5DIR=0x7F;//P5口所有引脚设置为输出方向
// P4DIR=0XFF;
// P4SEL=0X00;
P1DIR=0x00;
P1SEL=0X00; // 所有引脚为一般引脚
//P1OUT=0X00; //所有引脚为输入引脚
P1IE|=0xf0;
P1IES|=0xf0;
}
*/
void Lcd_Fill_Area_AllWhite()
{
Fill_Area(16,16,2,16,0);
Fill_Area(16,48,2,16,0);
Fill_Area(16,80,2,16,0);
Fill_Area(32,16,2,16,0);
Fill_Area(32,48,2,16,0);
Fill_Area(32,80,2,16,0);
}
void Lcd_Fill_Area_AllBlack()
{
Fill_Area(16,16,2,16,1);
Fill_Area(16,48,2,16,1);
Fill_Area(16,80,2,16,1);
Fill_Area(32,16,2,16,1);
Fill_Area(32,48,2,16,1);
Fill_Area(32,80,2,16,1);
}
void Intrrupt_Key_Pro()
{
Count=K1_Count%6;
if(flagA&0x01)
{
// 得到K1_Count 的值将之放到相应用的LCD12864的显示位置.
// Count=K1_Count%6; //是总数年的和才会显示正确
flagA=0x00;
switch(Count)
{
case 0: //直接先将所有清0 再将选定的区域画面
{
Lcd_Fill_Area_AllWhite();
Fill_Area(16,16,2,16,1);
} break;//黑背景
case 1:
{
Lcd_Fill_Area_AllWhite();
Fill_Area(16,48,2,16,1);
} break;
case 2:
{
Lcd_Fill_Area_AllWhite();
Fill_Area(16,80,2,16,1);
} break;
case 3:
{
Lcd_Fill_Area_AllWhite();
Fill_Area(32,16,2,16,1);
} break;
case 4:
{
Lcd_Fill_Area_AllWhite();
Fill_Area(32,48,2,16,1);
} break;
case 5:
{
Lcd_Fill_Area_AllWhite();
Fill_Area(32,80,2,16,1);
} break;
default:
{
for(unsigned char i=0;i<0x10;i++);
// Lcd_Fill_Area_AllWhite();
// Fill_Area(16,16,2,16,1); //默认为'年'字背景为黑
} // break;
}
//flagA=0x00;
}
GetTime();
if(flagB&0x02)
{
flagB=0x00;
//得到K2_Value的真值.
if(K2_Value)
{
K2_Value=false;
//GetTime();
switch(Count)
{
case 0: //将值加工1后再写入到PCF8563
{
PCF_time[5]=PCF_time[5]+1; //如果大于9,为10 如>19 则为20 .>29 则为30. >39 则为40 . >49 为50 >59 则为 00
//SetTime();
//Time_Add_Chk(*PCF_time);
if(PCF_time[5]==0x0A)
{
PCF_time[5]=0x10;
}
else if(PCF_time[5]==0x1A)
{
PCF_time[5]=0x20;
}
else if(PCF_time[5]==0x2A)
{
PCF_time[5]=0x30;
}
else if(PCF_time[5]==0x3a)
{
PCF_time[5]=0x40;
}
else if(PCF_time[5]==0x4A)
{
PCF_time[5]=0x50;
}
else if(PCF_time[5]==0x5A)
{
PCF_time[5]=0x60;
}
else if(PCF_time[5]==0x6A)
{
PCF_time[5]=0x70;
}
else if(PCF_time[5]==0x7A)
{
PCF_time[5]=0x80;
}
else if(PCF_time[5]==0x8A)
{
PCF_time[5]=0x90;
}
else if(PCF_time[5]==0x9A)
{
PCF_time[5]=0x00;
}
SetTime();
} break;
case 1: // 月
{
PCF_time[4]=PCF_time[4]+1;
if(PCF_time[4]==0x0A)
{
PCF_time[4]=0x10;
}
else if(PCF_time[4]==0x1A)
{
PCF_time[4]=0x20;
}
else if(PCF_time[4]==0x2A)
{
PCF_time[4]=0x30;
}
else if(PCF_time[4]==0x3a)
{
PCF_time[4]=0x00;
}
SetTime();
} break;
case 2: // 日
{
PCF_time[3]=PCF_time[3]+1;
if(PCF_time[4]==0x0A)
{
PCF_time[4]=0x10;
}
else if(PCF_time[4]==0x1A)
{
PCF_time[4]=0x20;
}
else if(PCF_time[4]==0x2A)
{
PCF_time[4]=0x30;
}
else if(PCF_time[4]==0x3a)
{
PCF_time[4]=0x00;
}
SetTime();
} break;
case 3:
{
PCF_time[2]=PCF_time[2]+1;
SetTime();
} break;
case 4:
{
PCF_time[1]=PCF_time[1]+1;
SetTime();
} break;
case 5:
{
PCF_time[0]=PCF_time[0]+1;
SetTime();
} break;
default:
{
for(unsigned char i=0;i<0x10;i++);
} // break;
}
// K2_Value=false;
}
//flagB=0x00;
}
if(flagC&0x04)
{
flagC=0x00;
//得到K3_Value的真值
if(K3_Value)
{
K3_Value=false;
switch(Count) //值减1后再从新设置
{
case 0:
{
PCF_time[5]=PCF_time[5]-1; //年月日的显示是倒的 如果是Count+5的话刚永远写的是"年"
//PCF_time[Count+5]=PCF_time[Count+5]-1; //年月日的显示是倒的
SetTime();
} break;
case 1:
{
PCF_time[4]=PCF_time[4]-1;
SetTime();
} break;
case 2:
{
PCF_time[3]=PCF_time[3]-1;
SetTime();
} break;
case 3:
{
PCF_time[2]=PCF_time[2]-1;
SetTime();
} break;
case 4:
{
PCF_time[1]=PCF_time[1]-1;
SetTime();
} break;
case 5:
{
PCF_time[0]=PCF_time[0]-1;
SetTime();
} break;
default :
{
for(unsigned char t=0;t<0x10;t--);
} // break;
}
// K3_Value=false; // 直接从default 跳出从而没有将K3_Value赋值
}
//flagC=0x00;
}
if(flagD&0x08)
{
//WriteCommand(0x90);
//for(i=0;i<16;i++) WriteData(Data4[i]);
//得到K4_Value的真值 确认后将所有黑幕 清除
if(K4_Value)
{
Lcd_Fill_Area_AllWhite();
//将所有的整数值及布尔值 清0及
K1_Count=0;
K2_Value=false;
K3_Value=false;
K4_Value=false;
}
flagD=0x00;
}
}
#pragma vector=PORT1_VECTOR
__interrupt void PORT1_ISR(void)
{
Delay_Interrupt_MS(200); // 值太少会产生跳变.使得值不能确定.
if((P1IFG&BIT4)) //向下
{
flagA=0x01;
//flagC=0x00;
K1_Count++;
P1IFG&=~BIT4;
}
else if((P1IFG&BIT5)) //增大
{
flagB=0x02;
//flagD=0x00;
K2_Value=true;
P1IFG&=~BIT5;
}
else if(P1IFG&BIT6) //减少
{
flagC=0x04;
//flagA=0x00;
K3_Value=true;
P1IFG&=~BIT6;
}
else if(P1IFG&BIT7) // 确认.
{
flagD=0x08;
//flagB=0x00;
K4_Value=true;
P1IFG&=~BIT7;
}
else
{
P4OUT &=~BIT1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -