四個(gè)按鍵對常用數(shù)值調(diào)整代碼
/*************************************************************
**四個(gè)按鍵數(shù)值調(diào)整,一個(gè)移位,兩個(gè)加減,一個(gè)確定
**針對0~65536數(shù)值區(qū)間,任意數(shù)值
**light
**2012-3-28
*************************************************************/
//數(shù)值調(diào)整結(jié)構(gòu)
typedefstruct_num_cal
{
unsignedintnum_temp;//變量值
unsignedintbit;//位
unsignedintbit_max;//位數(shù)
unsignedinttmp_bit[5];//存放各個(gè)位值
}num_cal;
num_calnum_cal_tmp;//數(shù)值調(diào)整結(jié)構(gòu)全局變量
/*************************************************************
**number_calc
**temp_value:要調(diào)整的值
**bit_max:數(shù)據(jù)位數(shù)
**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://移動光標(biāo),由低位向高位移動
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;
}