LCD1602小程序

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;    
    }
}

 

posted @ 2015-01-16 11:25  瘋耔  阅读(929)  评论(0编辑  收藏  举报
跳至侧栏