标题: 单片机+LCD1602在想显示65535时会显示65135? [打印本页]

作者: lxh0587    时间: 2022-5-6 20:04
标题: 单片机+LCD1602在想显示65535时会显示65135?
我的LCD1602在想显示65535时会显示65135,
                                65435时会显示65035
不知道为啥,下面是程序
/**
* @brief  显示无符号数字
* @param  x 显示的行数 范围为1~2;
* @param  y 显示的列数 范围为1~40;但初始只显示前16列。
* @param  num 显示的数字 范围 0~65535
* @param  length 显示的数字长度  0~40 但初始只显示前16
* @retval 无
*/
void lcd1602_show_num(unsigned char x,y, unsigned int num, unsigned char length)
{
        unsigned char i=length;
        show_location(x,y);
        while(i)
        {
                lcd1602_w_data((num/(int)(pow(10,i-1)))%10+0x30);
                i--;
        }
}


/**
* @brief  写数据函数
* @param  dat 要写的数据
* @retval 无
*/
void lcd1602_w_data(unsigned char dat)
{
//        while(!check_busy());
        RS=1;
        RW=0;
        P0=dat;
        EN=1;
        _nop_ ();
        EN=0;        
        Delay(1);
}



作者: xuyaqi    时间: 2022-5-7 10:45
程序有问题,给的信息不全不好判断。
作者: Hephaestus    时间: 2022-5-7 10:48
pow是浮点类型啊!你必须忍受误差。
作者: hy47566398    时间: 2022-5-8 16:40
把函数参数 “unsigned int num" 改成 unsigned long num
作者: yaoyao2022    时间: 2022-5-15 22:20
void lcd1602_show_num(unsigned char x,y, unsigned int num, unsigned char length) 中y 缺少类型




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1