四个按键对常用数值调整代码
扫描二维码
随时随地手机看文章
/*************************************************************
**四个按键数值调整,一个移位,两个加减,一个确定
**针对0~65536数值区间,任意数值
**light
**2012-3-28
*************************************************************/
//数值调整结构
typedefstruct_num_cal
{
unsignedintnum_temp;//变量值
unsignedintbit;//位
unsignedintbit_max;//位数
unsignedinttmp_bit[5];//存放各个位值
}num_cal;
num_calnum_cal_tmp;//数值调整结构全局变量
/*************************************************************
**number_calc
**temp_value:要调整的值
**bit_max:数据位数
**2012-3-28
*************************************************************/
voidnumber_calc(unsignedinttemp_value,unsignedintbit_max)
{
num_cal_tmp.num_temp=temp_value;
num_cal_tmp.tmp_bit[0]=num_cal_tmp.num_temp%10;
num_cal_tmp.tmp_bit[1]=(num_cal_tmp.num_temp%100)/10;
num_cal_tmp.tmp_bit[2]=(num_cal_tmp.num_temp%1000)/100;
num_cal_tmp.tmp_bit[3]=(num_cal_tmp.num_temp%10000)/1000;
num_cal_tmp.tmp_bit[4]=num_cal_tmp.num_temp/10000;
num_cal_tmp.bit_max=bit_max-1;
}
switch(key_value):
{
casekey_back://移动光标,由低位向高位移动
num_cal_tmp.bit++;
if(num_cal_tmp.bit>num_cal_tmp.bit_max)
{
num_cal_tmp.bit=0;
}
break;
casekey_up://加
num_cal_tmp.tmp_bit[num_cal_tmp.bit]++;
if(num_cal_tmp.tmp_bit[num_cal_tmp.bit]>9)
{
num_cal_tmp.tmp_bit[num_cal_tmp.bit]=0;
}
break;
casekey_down://减
if(num_cal_tmp.tmp_bit[num_cal_tmp.bit]==0)
{
num_cal_tmp.tmp_bit[num_cal_tmp.bit]=9;
}
else
{
num_cal_tmp.tmp_bit[num_cal_tmp.bit]--;
}
break;
casekey_enter://确定键
temp_value=num_cal_tmp.tmp_bit[4]*10000+num_cal_tmp.tmp_bit[3]*1000+num_cal_tmp.tmp_bit[2]*100+num_cal_tmp.tmp_bit[1]*10+num_cal_tmp.tmp_bit[0];
break;
}