/*! * @brief 显示数字 * @param site 左上角坐标 * @param num 数字 * @param Color 字体颜色 * @param bkColor 背景颜色 * @since v5.0 * Sample usage: Site_t site = {10,20}; //x = 10 ,y = 20 LCD_num(site,123, BLUE,RED); */ void LCD_num(Site_t site, uint32 num, uint16 Color, uint16 bkColor) { uint32 res = num; uint8 t = 0; Site_t sitetemp; sitetemp.y = site.y; if( num == 0 ) { LCD_char(site, '0', Color, bkColor); return; } while( res ) /*得到数字长度t*/ { res /= 10; t++; } while(num) { sitetemp.x = site.x + (8 * (t--) - 8); LCD_char(sitetemp, (num % 10) + '0', Color, bkColor); num /= 10 ; } }
int xmitTest(void){ // initialize strings char* myname; myname = "Ashley Towne"; serial_init(9600); // initialize LCD LCD_init(); LCD_display_on(); set_output_device(2); // select LCD as output // output to LCD LCD_clear(); LCD_setpos(0,0); printf("%s",myname); LCD_setpos(1,0); // output to terminal set_output_device(1); // select UART as output device printf("This goes to terminal\n"); // write to the screen printf("%s\n", myname); // loop int foo = 0; unsigned char mystr; int ctr = 0; while(ctr<10) { ctr = ctr + 1; if (foo==0){mystr='0';} else if(foo==1){mystr = '1';} else if(foo==2){mystr = '2';} else if(foo==3){mystr = '3';} else if(foo==4){mystr = '4';} else if(foo==5){mystr = '5';} else if(foo==6){mystr = '6';} else if(foo==7){mystr = '7';} else if(foo==8){mystr = '8';} else if(foo==9){ mystr = '9'; foo = -1; } set_output_device(2); putu((char)(100+foo)); set_output_device(1); LCD_char((char)(100+foo)); foo = foo + 1; } putu('z'); LCD_char('z'); putu(EOF); return 1; }
void main () { init(); LCD_print("Welcome !", 0); // top line delay_ms(1000); LCD_print("BIATCH!!!", 1); // bottom line LED = 1; delay_ms(500); int last_key = 0; int key = 0; LCD_reset(); LCD_print("NO KEY", 0); while (1) { //getNum(15); LED = 0; delay_ms(10); //LED = 1; delay_ms(10); key = Keypad_get_key(); if (key != last_key) { if (key == 0) { LCD_print("NO KEY", 0); } else { LCD_print("Pressed ", 0); LCD_char(Keypad_char_for_key(key)); } last_key = key; } }; }
/*! * @brief 显示字符串 * @param site 左上角坐标 * @param Str 字符串地址 * @param Color 字体颜色 * @param bkColor 背景颜色 * @since v5.0 * Sample usage: Site_t site = {10,20}; //x = 10 ,y = 20 LCD_str(site,"www.chuxue123.com", BLUE,RED); */ void LCD_str(Site_t site, uint8 *Str, uint16 Color, uint16 bkColor) { #define MAX_CHAR_POSX (LCD_W-8) #define MAX_CHAR_POSY (LCD_H-16) while(*Str != '\0') { if(site.x > MAX_CHAR_POSX ) { //换行 site.x = 0; site.y += 16; } if(site.y > MAX_CHAR_POSY ) { //一屏 site.y = 0; site.x = 0; } LCD_char(site, *Str, Color, bkColor); site.x += 8; Str ++ ; } #undef MAX_CHAR_POSX #undef MAX_CHAR_POSY }
/*! * @brief 显示数字(清空多余的位) * @param site 左上角坐标 * @param num 数字 * @param max_num_bit 最大的位数 * @param Color 字体颜色 * @param bkColor 背景颜色 * @since v5.0 * Sample usage: Site_t site = {10,20}; //x = 10 ,y = 20 LCD_num_BC(site,123,5, BLUE,RED); */ void LCD_num_BC(Site_t site, uint32 num, uint8 max_num_bit, uint16 Color, uint16 bkColor) { uint32 res = num; uint8 t = 0; Site_t sitetemp; Size_t size; sitetemp.y = site.y; if( num == 0 ) { LCD_char(site, '0', Color, bkColor); site.x += 8; size.H = 16; size.W = 8 * (max_num_bit - 1); LCD_rectangle(site, size, bkColor); return; } while( res ) /*得到数字长度t*/ { res /= 10; t++; } if(t >= max_num_bit ) //限制最大长度 { t = max_num_bit; } res = t; while( t != 0 ) { sitetemp.x = site.x + (8 * (t--) - 8); LCD_char(sitetemp, (num % 10) + '0', Color, bkColor); num /= 10 ; } if(res != max_num_bit ) { size.W = 8 * (max_num_bit - res); site.x += (8 * res); size.H = 16; LCD_rectangle(site, size, bkColor); } }