嗯嗯,我這個實際是這個樣子的,就是把光標設(shè)置一個位置,然后打開光標,再然后在這個位置輸入數(shù)字,這個數(shù)字的位數(shù)不定,F(xiàn)在的問題是在我打開光標時,還沒有輸入數(shù)字呢,這個光標就跑到位置列表的最后一個位置了。這個設(shè)置光標位置和打開光標我是通過一個按鍵執(zhí)行的。而輸入數(shù)字的方式有兩種,一種是通過數(shù)字鍵盤輸入,一種是實時讀取傳感器的數(shù)據(jù),這兩種方式我在數(shù)字按鍵的動作函數(shù)里加了判斷,來進行選擇是用哪種方式進行輸入。
程序里涉及到光標位置的有光標右移、光標位置設(shè)置、輸入數(shù)字,刪除數(shù)字這幾個函數(shù)。- /*設(shè)置光標位置,打開光標*/
- void RefreshCursorShow()
- {
- switch(setIndex)
- {
- case 1:LcdSetCursor(4,0);LcdWriteCmd(0x0F);break;
- case 2:LcdSetCursor(10,0);break;
- case 3:LcdSetCursor(2,1);break;
- case 4:LcdSetCursor(10,1);break;
- case 5:LcdWriteCmd(0x0C);setIndex = 0;break;
- default:break;
- }
- }
- /*光標移動操作函數(shù),配合按鍵0x1B動作*/
- void RightShiftSet()
- {
- if(setIndex <= 4)
- {
- setIndex++;
- RefreshCursorShow(); //設(shè)置光標位置,并打開光標
- }
- }
- /*按鍵動作函數(shù),執(zhí)行相應(yīng)的動作*/
- void KeyAction(unsigned char keycode)
- {
- if((keycode >= '0') && (keycode <= '9')) //輸入數(shù)字
- {
- NumKeyAction(keycode - '0');
- }
- else if(keycode == 0x26) //各特征值的切換
- {
- FunKeyAction();
- }
- else if(keycode == 0x1B) //光標的循環(huán)移動
- {
- RightShiftSet();
- }
- else if(keycode == 0x27) //刪除當前數(shù)據(jù)
- {
- Deldata();
- }
- else if(keycode == 0x23) //去皮清零
- {
- ClearZeroKeyAction();
- }
- else if(keycode == 0x40) //將當前A\B\C數(shù)據(jù)寫入
- {
- WriteInDATA();
- LcdAreaClear(10,0,6);
- LcdAreaClear(2,1,6);
- LcdAreaClear(10,1,6);
- }
- else if(keycode == 0x25) //讀出當前特征值的A\B\C數(shù)據(jù)
- {
- ReadOutDATA();
- }
- else if(keycode == 0x28) //校正計算
- {
- EA = 0;
- transition();
- EA = 1;
- }
- else if(keycode == 0x0D) //切換顯示(實時和功能的切換)
- {
- SwDisplayKeyAction();
- }
- else if(keycode == 0x2B) //校準值加
- {
- if(T2 < 50)
- {
- T2++;
- }
- }
- else if(keycode == 0x2C) //校準值減
- {
- if(T2 > 0)
- {
- T2--;
- }
- }
- }
- /*數(shù)字鍵動作函數(shù),n-按鍵輸入的數(shù)值*/
- void NumKeyAction(unsigned int n)
- {
- long xdata xe = 50;
-
- switch(setIndex)
- {
- case 1:
- num0 = num0 * 10 + n;
- GuigeToString(number,num0);
- LcdShowStr(4,0,number);
- num1 = 0;
- break;
- case 2:
- if(Getval < xe)
- {
- num1 = num1 * 10 + n;
- }
- else
- {
- num1 = Getval;
- }
- ValueToString(str,num1);
- LcdShowStr(10,0,str);
- num2 = 0;
- break;
- case 3:
- if(Getval < xe)
- {
- num2 = num2 * 10 + n;
- }
- else
- {
- num2 = Getval;
- num2 += num1;
- }
- ValueToString(str,num2);
- LcdShowStr(2,1,str);
- num3 = 0;
- break;
- case 4:
- if(Getval < xe)
- {
- num3 = num3 * 10 + n;
- }
- else
- {
- num3 = Getval;
- num3 += num2;
- }
- ValueToString(str,num3);
- LcdShowStr(10,1,str);
- num0 = 0;
- break;
- default:
- break;
- }
- }
- /*刪除當前數(shù)據(jù)*/
- void Deldata()
- {
- switch(setIndex)
- {
- case 1:
- LcdAreaClear(4,0,4);
- num0 = 0;
- RefreshCursorShow();
- break;
- case 2:
- LcdAreaClear(10,0,6);
- num1 = 0;
- RefreshCursorShow();
- break;
- case 3:
- LcdAreaClear(2,1,6);
- num2 = 0;
- RefreshCursorShow();
- break;
- case 4:
- LcdAreaClear(10,1,6);
- num3 = 0;
- RefreshCursorShow();
- break;
- default:
- break;
- }
- }
復制代碼 |