1顯示數據
typedef struct { unsigned long int mL_data; unsigned long int L_data; unsigned long int M3_data; }water_date; extern water_date water_data1;
2數據處理函數
/**--------------------------------------------------------------------------------- * @brief 數據處理函數 * @param 無 * @arg 需處理數據結構體起始地址 * @retval 數據起始地址 ---------------------------------------------------------------------------------*/ unsigned char* DATA_DEAL(water_date t) { unsigned char DIS_DATA[] = {"000mL;000L;000M3"}; if(t.mL_data || t.L_data || t.M3_data) { DIS_DATA[0] = (t.mL_data * 1000/450)%1000/100 + 0x30; DIS_DATA[1] = (t.mL_data * 1000/450)%100/10 + 0x30; DIS_DATA[2] = (t.mL_data * 1000/450)%10 + 0x30; DIS_DATA[6] = t.L_data%1000/100 + 0x30; DIS_DATA[7] = t.L_data%100/10 + 0x30; DIS_DATA[8] = t.L_data%10 + 0x30; DIS_DATA[11] = t.M3_data%1000/100 + 0x30; DIS_DATA[12] = t.M3_data%100/10 + 0x30; DIS_DATA[13] = t.M3_data%10 + 0x30; return DIS_DATA; } else return 0; }
3顯示函數
/**--------------------------------------------------------------------------------- * @brief 對應位置顯示函數 * @param y:1,2(從第幾行開始寫) x:0-15(從改行的第幾位開始寫) * @arg NULL * @retval null ---------------------------------------------------------------------------------*/ unsigned char LCD1602_WRITE(unsigned char y,unsigned char x,unsigned char *write_data) { unsigned char i; lcd_wcmd(0x06); //向右移動光標 if(y == 1) { lcd_pos(x); //設置顯示位置為第一行的第1個字符 i = 0; while(*(write_data + i) != '\0') { //顯示字符"WLCOME TO" lcd_wdat(*(write_data + i)); i++; // delay(200); //控制兩字之間顯示速度 if(i > 15) { LCE1602_STATUS = WRITE_NO; return LCE1602_STATUS; } } LCE1602_STATUS = WRITE_OK; return LCE1602_STATUS; } else { lcd_pos(0x40 + x); //設置顯示位置為第一行的第1個字符 i = 0; while(*(write_data + i) != '\0') { //顯示字符"WLCOME TO" lcd_wdat(*(write_data + i)); i++; // delay(200); //控制兩字之間顯示速度 if(i > 15) { LCE1602_STATUS = WRITE_NO; return LCE1602_STATUS; } } LCE1602_STATUS = WRITE_OK; return LCE1602_STATUS; } }