1. for Duemilanove board, use NG with ATmega168 instead of Diecimila in Arduino IDE 0012
![](file:///C:/DOCUME%7E1/BTYEUN%7E1/LOCALS%7E1/Temp/moz-screenshot.jpg)
2. Arduino------LCD------LCD pin
----------2--------enable---- 6
----------7--------DB4-------11
----------8--------DB5-------12
----------9--------DB6-------13
----------10------DB7-------14
----------12------DI (RS)----4
---------GND----RW---------5
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieJN7YPL5PRoj_0OsvqRFtSrqzm7wvhCa9JYoGpzP60L9s1eXIa4aQytvbj-Nc5SAvHDevo2QLqSwuhepXHUjrOjwjgS_mOMAAy16eoC3qwdhwP6n59XWsOtUxYeg7uueP7p64nqk5M-sd/s320/wiring.jpg)
3. Need to modify LCD4bit.cpp (\arduino-0012\hardware\libaries\LCD4Bit\LCD4bit.cpp) as follows and delete LCD4bit.o before compile/ verify the sketch.
I changed the origenal 4bit library code myself to let it work with my 4x20LCD, KS0066u Based.
I got it working perfectly.
Below the code for those of you who have the same LCD.
LCD4Bit.cpp:
changes I made
just replace the origenal ones with this ones.
The new constructor:
LCD4Bit::LCD4Bit (int num_lines) {
g_num_lines = num_lines;
if (g_num_lines < g_num_lines =" 1;"> 4)
{
g_num_lines = 4;
}
}
function cursorTo
void LCD4Bit::cursorTo(int line_num, int x){
//first, put cursor home
commandWrite(CMD_HOME);
if (x>19)
{
x=19;
}
switch (line_num)
{
case 1:
x+=0x00 ; break;
case 2:
x+= 0x40 ; break;
case 3:
x+= 0x14 ; break; // In fact, line 3 is an extension of the line 1 (beyond the 20 first characters)
case 4:
x+= 0x54 ; break; // Line 4 is an extension of line 2
}
//
commandWrite(0x80+x);
}
Test program:
#include
LCD4Bit lcd = LCD4Bit(4);
void setup() {
pinMode(13, OUTPUT); //we'll use the debug LED to output a heartbeat
lcd.init();
}
void loop() {
digitalWrite(13, HIGH); //light the debug LED
lcd.cursorTo(1,0);
lcd.printIn("Line 1");
lcd.cursorTo(2,0);
lcd.printIn("Line 2");
lcd.cursorTo(3,0);
lcd.printIn("Line 3");
lcd.cursorTo(4,0);
lcd.printIn("Line 4");
delay(1000);
digitalWrite(13, LOW); //clear the debug LED
Hope it works for you to!
check www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1170601618/0
沒有留言:
張貼留言