int LCD_Position(unsigned int X, unsigned int Y) { int Pos; if (X==1) X=0x80; else if (X==2) X=0x90; else if (X==3) X=0x88; else if (X==4) X=0x98; Pos = X+Y ; write_cmd(Pos); //显示地址 }if(LCD_Position(0,10))
时间: 2024-04-12 14:34:16 浏览: 11
根据给出的代码,`LCD_Position()`函数在设置LCD显示位置的基础上,并没有返回任何值。因此,`if(LCD_Position(0,10))`中的条件表达式实际上是在调用`LCD_Position()`函数,但并不能判断函数的返回结果。
在这种情况下,条件表达式`if(LCD_Position(0,10))`将无法进行正确的判断,因为函数没有返回值。你需要修改`LCD_Position()`函数的定义和实现,使其能够返回一个表示条件真假的布尔值,然后再在条件语句中使用该返回值进行判断。例如,可以将函数的返回类型更改为`bool`,并在函数的最后使用`return true;`或`return false;`来返回条件的结果。这样,你就可以在`if`语句中进行条件判断了。
相关问题
int LCD_Position(unsigned int X, unsigned int Y) { int Pos; if (X==1) X=0x80; else if (X==2) X=0x90; else if (X==3) X=0x88; else if (X==4) X=0x98; Pos = X+Y ; write_cmd(Pos); //显示地址 }和void LCD_Position(unsigned int X, unsigned int Y) { int Pos; if (X==1) X=0x80; else if (X==2) X=0x90; else if (X==3) X=0x88; else if (X==4) X=0x98; Pos = X+Y ; write_cmd(Pos); //显示地址 }区别
这两个代码片段的区别在于函数的返回类型。
第一个代码片段中的函数定义为`int LCD_Position(unsigned int X, unsigned int Y)`,表示`LCD_Position()`函数返回一个`int`类型的值。然而,在函数的实现中,并没有返回任何值(没有返回语句),因此这个返回类型在实际上是没有意义的。
第二个代码片段中的函数定义为`void LCD_Position(unsigned int X, unsigned int Y)`,表示`LCD_Position()`函数不返回任何值(即void类型)。这也是比较合适的,因为函数内部没有任何地方将返回值赋给任何变量或表达式。
总之,这两个代码片段在函数的返回类型上有所区别,但在函数实现及功能上是相同的,它们都会根据`X`和`Y`的值计算出`Pos`并调用`write_cmd()`函数来显示地址。
int LCD_Position(unsigned int X, unsigned int Y) { int Pos; if (X==1) X=0x80; else if (X==2) X=0x90; else if (X==3) X=0x88; else if (X==4) X=0x98; Pos = X+Y ; write_cmd(Pos); //显示地址 }和
根据给出的代码,`LCD_Position()`函数接受两个参数 `X` 和 `Y`,用于设置LCD显示的位置。根据 `X` 的不同值,函数会设置不同的位置。
具体来说,如果 `X` 的值为 `1`,则将其转换为十六进制 `0x80`;如果 `X` 的值为 `2`,则转换为 `0x90`;如果 `X` 的值为 `3`,则转换为 `0x88`;如果 `X` 的值为 `4`,则转换为 `0x98`。
然后,将 `Pos` 设置为 `X + Y` 的值。最后,调用一个名为 `write_cmd()` 的函数,并将 `Pos` 作为参数传递给它。这个函数可能用于将显示地址发送给LCD。
请注意,根据代码中的实现,`LCD_Position()`函数没有返回任何值(没有返回类型声明)。如果你希望该函数返回某个值,并在条件语句中进行判断,你需要修改函数的定义并添加一个合适的返回语句。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)