//显示一个数字 //x,y:起点坐标 //num:数值(0~65536); void TFT_ShowNum(u8 x,u16 y,long num) { u32 res ; u8 t=0,t1=0; if(num == 0) { TFT_ShowChar(x,y,'0'); } if(num < 0) { num = -num; TFT_ShowChar(x,y,'-'); x += 6; } res = num; while(res) { res/=10; t++; } t1=t; while(t) { res = mypow(10,t-1); TFT_ShowChar(x+(t1-t)*6,y,(num/res)%10+'0'); t--; } }
void TFT_ShowFloat(u8 x,u16 y,float fnum) { float fdot = 0.0f,fdotflag = 0.0f; long num = 0; if(fnum < 0.0f) { fnum = -fnum; TFT_ShowChar(x,y,'-'); x += 6; } num = (long)fnum; fdot = fnum - (float)num; fdotflag = fdot; //显示整数部分 TFT_ShowNum(x,y,num); if(num == 0 ) x += 6; //得到数字长度 while(num) { num /= 10; x += 6; } TFT_ShowChar(x,y,'.'); x += 6; while(fdotflag < 1.0f&& fdotflag != 0.0f) { fdot *= 10; if(fdot < 1.0f) { TFT_ShowChar(x,y,'0'); x += 6; } num = (int)fdot; fdotflag = fdot - (float)num; } num = (int)fdot; TFT_ShowNum(x,y,num); }
//显示字符串 //x,y:起点坐标 //*p:字符串起始地址 void TFT_ShowString(u8 x,u16 y,const u8 *p) { while(*p!='\0') { if(x>MAX_CHAR_POSX){x=0;y+=12;} if(y>MAX_CHAR_POSY){y=x=0;TFT_Clear(0,0,240,320);} TFT_ShowChar(x,y,*p); x+=6; p++; } }
void LCD_SHOW_CN15x16_String(unsigned short x0,unsigned short y0,unsigned char *str) { unsigned short X,Y; if(x0+16>TFT_MAX_X-1||y0+16>TFT_MAX_Y-1) return;//判断是否超出TFT边界 X=x0; Y=y0; while( *str!='\0') { if(*str>=0xA1) { LCD_Show_CN_Char(X,Y,str); X+=16; if(X>TFT_MAX_X-1) { X=0; Y+=16; if(Y>TFT_MAX_Y-1) { Y=0; } } str+=2; } else { TFT_ShowChar(X,Y,*str); X+=8; if(X>TFT_MAX_X-1) { X=0; Y+=16; if(Y>TFT_MAX_Y-1) { Y=0; } } str+=1; } } }