极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 13484|回复: 6

【新手求助】mega2560 i2c连接 lcd 2004

[复制链接]
发表于 2013-3-14 18:19:02 | 显示全部楼层 |阅读模式
我有一块lcd2004的板子用了i2c的转接芯片,连接在mega2560上的20 21口。但是刷写示例程序后无法显示任何内容,只有两行白块。之前连接i2c的lcd1602的时候也遇到了同样的问题,该如何解决?
回复

使用道具 举报

发表于 2013-3-14 19:30:26 | 显示全部楼层
代码放上来
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-3-15 13:26:50 | 显示全部楼层
Damn_intuition 发表于 2013-3-14 19:30
代码放上来
  1. //DFRobot.com
  2. //Compatible with the Arduino IDE 1.0
  3. //Library version:1.1
  4. #include <Wire.h>
  5. #include <LiquidCrystal_I2C.h>

  6. #if defined(ARDUINO) && ARDUINO >= 100
  7. #define printByte(args)  write(args);
  8. #else
  9. #define printByte(args)  print(args,BYTE);
  10. #endif

  11. uint8_t bell[8]  = {0x4,0xe,0xe,0xe,0x1f,0x0,0x4};
  12. uint8_t note[8]  = {0x2,0x3,0x2,0xe,0x1e,0xc,0x0};
  13. uint8_t clock[8] = {0x0,0xe,0x15,0x17,0x11,0xe,0x0};
  14. uint8_t heart[8] = {0x0,0xa,0x1f,0x1f,0xe,0x4,0x0};
  15. uint8_t duck[8]  = {0x0,0xc,0x1d,0xf,0xf,0x6,0x0};
  16. uint8_t check[8] = {0x0,0x1,0x3,0x16,0x1c,0x8,0x0};
  17. uint8_t cross[8] = {0x0,0x1b,0xe,0x4,0xe,0x1b,0x0};
  18. uint8_t retarrow[8] = {        0x1,0x1,0x5,0x9,0x1f,0x8,0x4};
  19.   
  20. LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 20 chars and 4 line display

  21. void setup()
  22. {
  23. //  Serial.begin(57600);
  24.   lcd.init();                      // initialize the lcd
  25.   lcd.backlight();
  26.   
  27.   lcd.createChar(0, bell);
  28.   lcd.createChar(1, note);
  29.   lcd.createChar(2, clock);
  30.   lcd.createChar(3, heart);
  31.   lcd.createChar(4, duck);
  32.   lcd.createChar(5, check);
  33.   lcd.createChar(6, cross);
  34.   lcd.createChar(7, retarrow);
  35.   lcd.home();
  36.   
  37.   lcd.setCursor(0, 0);
  38.   for(int i = 0;i < 20; i++)  lcd.printByte(6);
  39.   lcd.setCursor(0, 1);
  40.   lcd.printByte(6);
  41.   lcd.print("   Hello world    ");
  42.   lcd.printByte(6);
  43.   lcd.setCursor(0, 2);
  44.   lcd.printByte(6);
  45.   lcd.print("  i ");
  46.   lcd.printByte(3);
  47.   lcd.print(" arduinos!   ");
  48.   lcd.printByte(6);
  49.   lcd.setCursor(0, 3);
  50.   for(int i = 0;i < 20; i++)  lcd.printByte(6);
  51. //  lcd.clear();

  52. }

  53. void loop()
  54. {

  55. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2013-3-15 14:44:29 | 显示全部楼层
loop里写代码,setup的只执行一次,效果应该是一闪而过
回复 支持 反对

使用道具 举报

发表于 2013-3-15 18:02:25 | 显示全部楼层
毛毛毛毛毛 发表于 2013-3-15 13:26

试试将
lcd.init();
改为
lcd.init();
delay(200);
lcd.init();
回复 支持 反对

使用道具 举报

发表于 2013-3-17 02:33:38 | 显示全部楼层
哟~少年……试试这个库吧……有的屏的转接板走线有变化,需要特殊的库……

本帖子中包含更多资源

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

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-4-9 17:41:04 | 显示全部楼层
谢谢各位,我的问题解决了。
LiquidCrystal_I2C lcd(0x20,20,4);
才是正解
回复 支持 反对

使用道具 举报

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

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-5-8 21:32 , Processed in 0.045639 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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