|
花了半天時(shí)間調(diào)試完成了一個(gè)變量顯示函數(shù),可以任意指定顯示數(shù)字的位數(shù)(通常不超過10位),還可以設(shè)定是否顯示前導(dǎo)‘0’,并可在任意位置插入小數(shù)點(diǎn)(當(dāng)然這個(gè)小數(shù)點(diǎn)是人為確定的,不是數(shù)據(jù)中計(jì)算出來(lái)的,因?yàn)閿?shù)據(jù)是無(wú)符號(hào)類型)。這個(gè)函數(shù)很容易移植到其他應(yīng)用中的,只要修改一下相關(guān)顯示的代碼就行。
STM32單片機(jī)源程序:
- /****************************************************************
- * 顯示變量函數(shù)display_value()
- * 輸入?yún)?shù):開始顯示(左上角)坐標(biāo):x,y,(uint16_t)
- * 前景色,背景色,(White,Black,Red,Green,Blue,Yellow)
- * 變量,(uint32_t)
- * 顯示長(zhǎng)度(不含小數(shù)點(diǎn)),小數(shù)位數(shù),(uint8_t)
- * 前導(dǎo)0(0=顯示,1=空格)
- *****************************************************************/
- void display_value(uint16_t x,uint16_t y,uint16_t fc,uint16_t bc,uint32_t v,uint8_t l,uint8_t b,uint8_t z)
- {
- unsigned char i,j,m;
- unsigned short k,x0;
- uint32_t u,n;
-
- x0 = x;
- u = v;
- z = z > 0 ? 0: 16; //前導(dǎo)0:z=16;前空格:z=0
- n = 1;
- for(j = 1; j < l; j++) //計(jì)算倍數(shù)
- n = n * 10;
-
- LCD_CS_CLR; //選擇LCD
- for(m = l;m > 0;m --) //開始分拆變量
- {
- k = u / n; //當(dāng)前位數(shù)字
- u = u - (k * n); //剩余數(shù)字
- if(k > 0) z = 16; //只要有一位數(shù)字>0,之后不能顯示空格
- if(m == 1) z = 16; //小數(shù)點(diǎn)之前的'0'顯示
- n = m < 2 ? 1: n / 10; //計(jì)算當(dāng)前的倍數(shù)
-
- if((m == b) & (m > 0)) //顯示小數(shù)點(diǎn)
- {
- for(i = 0;i < 16;i ++){
- for(j = 0;j < 8;j ++){
- if(asc16[14 * 16 + i] & (0x80 >> j))//從asc16[]數(shù)組中取字符.數(shù)據(jù)
- /* draw a point on the lcd */
- lcd_draw_point(x + j,y + i,fc);
- else{
- if(fc != bc)
- /* draw a point on the lcd */
- lcd_draw_point(x + j,y + i,bc);
- }
- }
- }
- x += 8;
- }
-
- for(i = 0;i < 16;i ++){ //顯示字符(k=字符序號(hào))
- for(j = 0;j < 8;j ++){
- if(asc16[(k+z) * 16 + i] & (0x80 >> j))//從asc16[]數(shù)組中取字符數(shù)據(jù)
- /* draw a point on the lcd */
- lcd_draw_point(x + j,y + i,fc);
- else{
- if(fc != bc)
- /* draw a point on the lcd */
- lcd_draw_point(x + j,y + i,bc);
- }
- }
- }
- x += 8;
- }
- LCD_CS_SET;
- }
復(fù)制代碼
|
評(píng)分
-
查看全部評(píng)分
|