极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 12045|回复: 4

液晶屏1602在官方例子的一个错误探讨

[复制链接]
发表于 2013-6-6 20:57:33 | 显示全部楼层 |阅读模式
本帖最后由 糯米基 于 2013-6-6 21:01 编辑

最近我想系统学学1602的操作,于是按着Arduino 1.02里的LiquidCrystal下的例子一个一个看下来,里面有一个自定义字符的例子,代码如下
  1. /*
  2.   LiquidCrystal Library - Custom Characters

  3. Demonstrates how to add custom characters on an LCD  display.  
  4. The LiquidCrystal library works with all LCD displays that are
  5. compatible with the  Hitachi HD44780 driver. There are many of
  6. them out there, and you can usually tell them by the 16-pin interface.

  7. This sketch prints "I <heart> Arduino!" and a little dancing man
  8. to the LCD.

  9.   The circuit:
  10. * LCD RS pin to digital pin 12
  11. * LCD Enable pin to digital pin 11
  12. * LCD D4 pin to digital pin 5
  13. * LCD D5 pin to digital pin 4
  14. * LCD D6 pin to digital pin 3
  15. * LCD D7 pin to digital pin 2
  16. * LCD R/W pin to ground
  17. * 10K potentiometer:
  18. * ends to +5V and ground
  19. * wiper to LCD VO pin (pin 3)
  20. * 10K poterntiometer on pin A0

  21. created21 Mar 2011
  22. by Tom Igoe
  23. Based on Adafruit's example at
  24. https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde

  25. This example code is in the public domain.
  26. http://www.arduino.cc/en/Tutorial/LiquidCrystal

  27. Also useful:
  28. http://icontexto.com/charactercreator/

  29. */

  30. // include the library code:
  31. #include <LiquidCrystal.h>

  32. // initialize the library with the numbers of the interface pins
  33. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

  34. // make some custom characters:
  35. byte heart[8] = {
  36.   0b00000,
  37.   0b01010,
  38.   0b11111,
  39.   0b11111,
  40.   0b11111,
  41.   0b01110,
  42.   0b00100,
  43.   0b00000
  44. };

  45. byte smiley[8] = {
  46.   0b00000,
  47.   0b00000,
  48.   0b01010,
  49.   0b00000,
  50.   0b00000,
  51.   0b10001,
  52.   0b01110,
  53.   0b00000
  54. };

  55. byte frownie[8] = {
  56.   0b00000,
  57.   0b00000,
  58.   0b01010,
  59.   0b00000,
  60.   0b00000,
  61.   0b00000,
  62.   0b01110,
  63.   0b10001
  64. };

  65. byte armsDown[8] = {
  66.   0b00100,
  67.   0b01010,
  68.   0b00100,
  69.   0b00100,
  70.   0b01110,
  71.   0b10101,
  72.   0b00100,
  73.   0b01010
  74. };

  75. byte armsUp[8] = {
  76.   0b00100,
  77.   0b01010,
  78.   0b00100,
  79.   0b10101,
  80.   0b01110,
  81.   0b00100,
  82.   0b00100,
  83.   0b01010
  84. };
  85. void setup() {
  86.   // create a new character
  87.   lcd.createChar(0, heart);
  88.   // create a new character
  89.   lcd.createChar(1, smiley);
  90.   // create a new character
  91.   lcd.createChar(2, frownie);
  92.   // create a new character
  93.   lcd.createChar(3, armsDown);  
  94.   // create a new character
  95.   lcd.createChar(4, armsUp);  

  96.   // set up the lcd's number of columns and rows:
  97.   lcd.begin(16, 2);
  98.   // Print a message to the lcd.
  99.   lcd.print("I ");
  100.   lcd.write(1);
  101.   lcd.print(" Arduino! ");
  102.   lcd.write(1);

  103. }

  104. void loop() {
  105.   // read the potentiometer on A0:
  106.   int sensorReading = analogRead(A0);
  107.   // map the result to 200 - 1000:
  108.   int delayTime = map(sensorReading, 0, 1023, 200, 1000);
  109.   // set the cursor to the bottom row, 5th position:
  110.   lcd.setCursor(4, 1);
  111.   // draw the little man, arms down:
  112.   lcd.write(3);
  113.   delay(delayTime);
  114.   lcd.setCursor(4, 1);
  115.   // draw him arms up:
  116.   lcd.write(4);
  117.   delay(delayTime);
  118. }
复制代码

其中我直接编译后提示错误
一路看下来,这里应该是想写一个爱心,总共就是I 心 Arduino!r然后第二排一个动画小人。出现那个错误后,我把lcd.write(0)改为lcdwrite(1),这里的0和1是自定义的图案代码,0是爱心,1是笑脸,改后的图案如下

希望大家帮我解释一下,那个错误的原因

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

 楼主| 发表于 2013-6-6 20:59:40 | 显示全部楼层
是用电脑摄像头拍的图,有点模糊,不过问题还是说的清楚的,先谢谢了
回复 支持 反对

使用道具 举报

发表于 2013-6-7 13:06:31 | 显示全部楼层
  1. int heartPos = 0;
  2.   // set up the lcd's number of columns and rows:
  3.   lcd.begin(16, 2);
  4.   // Print a message to the lcd.
  5.   lcd.print("I ");
  6.   //lcd.write(0);
  7.   lcd.write(heartPos);
  8.   lcd.print(" Arduino! ");
  9.   lcd.write(1);
复制代码
加一个变量=0 可以编过。 应该还是和unit8_t的定义有关。
回复 支持 反对

使用道具 举报

发表于 2013-6-7 15:38:49 | 显示全部楼层
本帖最后由 伯德 于 2013-6-7 16:55 编辑

在群里和大家讨论了一下。
可以确定这是一个Bug。
最愛猜問題(1251488074)提供了两个方法;
1) lcd.write(0.0); 或者
2)修改LiquidCrystal.h 行85,注释掉 using Print::write;;或者
3)lcd.write((uint_8)0); 或 lcd.write((unsigned char)0); 或lcd.write((byte)0);
据说官方已经更新了,不过我的1.04版也有这个问题,1.05版没试过。
如果没有改LZ可以试着给官方写封email反馈一下。

来看报错信息:
  1. CustomCharacter:117: error: call of overloaded 'write(int)' is ambiguous
  2. E:\arduino-1.0.4-windows\arduino-1.0.4\libraries\LiquidCrystal/LiquidCrystal.h:82: note: candidates are: virtual size_t LiquidCrystal::write(uint8_t)
  3. E:\arduino-1.0.4-windows\arduino-1.0.4\hardware\arduino\cores\arduino/Print.h:49: note:                 size_t Print::write(const char*)
复制代码
error: call of overloaded 'write(int)' is ambiguous
翻译:write的重载是不明确的。//明显是由于参数判断不清楚导致的错误。
后面的意思是问题在LiquidCrystal::write(uint8_t)和size_t Print::write(const char*)两个方法之间。

具体原因涉及到一些C++的知识,如果有兴趣,可以继续交流。
回复 支持 反对

使用道具 举报

发表于 2013-6-8 12:25:28 | 显示全部楼层
哈哈,这个问题搞得我从来都是从1开始写的。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-8 13:13 , Processed in 0.036714 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表