#include "stm32f10x_lib.h" #include "lcd.h" u16 frame[4]; /* LCD frame buffer */ u16 digit[4]; /* Digit frame buffer */ char text[2];
/* 'A' = 0x4E70 */
const u16 letter[26]={0x49F0,0x01F8,0x4118,0x08F8,0x4178,0x4170,0x41D8,0x09F0,0x600A, 0x0888,0x0534,0x0118,0x0F90,0x0B94,0x4998,0x4970,0x499C,0x4974, 0x41E8,0x6002,0x0998,0x0511,0x299A,0x0605,0x0601,0x4409};
const u16 number[10]={0x4998,0x0880,0x4878,0x48E8,0x09E0,0x41E8,0x41F8,0x4880,0x49F8,0x49E8};
const u16 arrow[2]={0x0005,0x0600}; // {Upstair,Downstair}
/******************************************************************************* * Function Name : convert * Description : converts an ascii char to the a LCD digit (previous coding) * Input1 : char * Input2 : point : flag indicating if a point has to be add in front of * displayed character (0: no, 1: yes) * Output : None * Return : None *******************************************************************************/ void convert (char* c,u8 point) { u16 car=0,tmp; u8 i; const u16 mask[4]={0xF000,0x0F00,0x00F0,0x000F}; const u8 shift[3]={0xC,0x8,0x4};
if ((*c<0x5B)&(*c>0x40)) // 'A' --- 'F' car = letter[*c-0x41]; else if ((*c<0x3A)&(*c>0x2F)) // '0' --- '9' car = number[*c-0x30]; else if (*c==0x20) car =0; // 'space' else if (*c=='+') car = arrow[0]; // upstair else if (*c=='-') car = arrow[1]; // downstair if (point==1) car|=0x8000; for (i=0;i<3;i++) { tmp = car&mask; digit = tmp>>shift; } digit[3] = (car&mask[3]); }
/******************************************************************************* * Function Name : write char * Description : This function writes a char in the LCD frame buffer * Input1 : char ascii value * Input2 : point 0: no point to add, 1 a point to add in front of char * Input2 : pos: position of the caracter to write [0:3] * Output : None * Return : None *******************************************************************************/ void write_char(char* car,u8 point,u8 pos) { int i; const u16 mask[4]={0x0F,0xF0,0xF00,0xF000};
convert(car,point); if (pos == 1) for (i=0;i<4;i++) digit=(digit<<4); if (pos == 2) for (i=0;i<4;i++) digit=(digit<<8); if (pos == 3) for (i=0;i<4;i++) digit=(digit<<12); for (i=0;i<4;i++) frame= (frame&~mask[pos])|digit; }
/******************************************************************************* * Function Name : write_string * Description : This function writes a string in the LCD * Input : string * Output : None * Return : None *******************************************************************************/ void write_string(char* str) { int i; for (i=0;i<4;i++) write_char(str+i,0,i); } /******************************************************************************* * Function Name : int2char * Description : This function convertes a 2 digit int to a char * Input : u8 value * Output : None * Return : None *******************************************************************************/ char* int2char(u8 value) { text[0] = 0x30 + (value/10); text[1] = 0x30 + (value%10); return(text); }
很不解的是:假设我要输出“A”,在convert中不是已经转化得到对应letter[]中的输出码了吗? digital[]和frame的用处在哪里? |
|