This shows you the differences between two versions of the page.
|
tutorials:arduino:lcd_display [2014/02/28 10:14] sam |
tutorials:arduino:lcd_display [2014/02/28 10:19] (current) sam |
||
|---|---|---|---|
| Line 23: | Line 23: | ||
| int DI = 12; | int DI = 12; | ||
| int RW = 11; | int RW = 11; | ||
| - | int DB[] = {3, 4, 5, 6, 7, 8, 9, 10};//使用数组来定义总线需要的管脚 | + | int DB[] = {3, 4, 5, 6, 7, 8, 9, 10}; |
| int Enable = 2; | int Enable = 2; | ||
| void LcdCommandWrite(int value) { | void LcdCommandWrite(int value) { | ||
| - | // 定义所有引脚 | + | |
| int i = 0; | int i = 0; | ||
| - | for (i=DB[0]; i <= DI; i++) //总线赋值 | + | for (i=DB[0]; i <= DI; i++){ |
| - | { | + | digitalWrite(i,value & 01); |
| - | digitalWrite(i,value & 01);//因为1602液晶信号识别是D7-D0(不是D0-D7),这里是用来反转信号。 | + | |
| value >>= 1; | value >>= 1; | ||
| } | } | ||
| Line 37: | Line 37: | ||
| delayMicroseconds(1); | delayMicroseconds(1); | ||
| digitalWrite(Enable,HIGH); | digitalWrite(Enable,HIGH); | ||
| - | delayMicroseconds(1); // 延时1ms | + | delayMicroseconds(1); |
| digitalWrite(Enable,LOW); | digitalWrite(Enable,LOW); | ||
| - | delayMicroseconds(1); // 延时1ms | + | delayMicroseconds(1); |
| } | } | ||
| void LcdDataWrite(int value) { | void LcdDataWrite(int value) { | ||
| - | // 定义所有引脚 | ||
| int i = 0; | int i = 0; | ||
| digitalWrite(DI, HIGH); | digitalWrite(DI, HIGH); | ||
| Line 56: | Line 55: | ||
| delayMicroseconds(1); | delayMicroseconds(1); | ||
| digitalWrite(Enable,LOW); | digitalWrite(Enable,LOW); | ||
| - | delayMicroseconds(1); // 延时1ms | + | delayMicroseconds(1); |
| } | } | ||
| Line 65: | Line 64: | ||
| } | } | ||
| delay(100); | delay(100); | ||
| - | // 短暂的停顿后初始化LCD | + | |
| - | // 用于LCD控制需要 | + | LcdCommandWrite(0x38); |
| - | LcdCommandWrite(0x38); // 设置为8-bit接口,2行显示,5x7文字大小 | + | |
| delay(64); | delay(64); | ||
| - | LcdCommandWrite(0x38); // 设置为8-bit接口,2行显示,5x7文字大小 | + | LcdCommandWrite(0x38); |
| delay(50); | delay(50); | ||
| - | LcdCommandWrite(0x38); // 设置为8-bit接口,2行显示,5x7文字大小 | + | LcdCommandWrite(0x38); |
| delay(20); | delay(20); | ||
| - | LcdCommandWrite(0x06); // 输入方式设定 | + | LcdCommandWrite(0x06); |
| - | // 自动增量,没有显示移位 | + | |
| delay(20); | delay(20); | ||
| - | LcdCommandWrite(0x0E); // 显示设置 | + | LcdCommandWrite(0x0E); |
| - | // 开启显示屏,光标显示,无闪烁 | + | |
| delay(20); | delay(20); | ||
| - | LcdCommandWrite(0x01); // 屏幕清空,光标位置归零 | + | LcdCommandWrite(0x01); |
| delay(100); | delay(100); | ||
| - | LcdCommandWrite(0x80); // 显示设置 | + | LcdCommandWrite(0x80); |
| - | // 开启显示屏,光标显示,无闪烁 | + | |
| delay(20); | delay(20); | ||
| } | } | ||
| void loop (void) { | void loop (void) { | ||
| - | LcdCommandWrite(0x01); // 屏幕清空,光标位置归零 | + | LcdCommandWrite(0x01); |
| delay(10); | delay(10); | ||
| LcdCommandWrite(0x80+3); | LcdCommandWrite(0x80+3); | ||
| delay(10); | delay(10); | ||
| - | // 写入欢迎信息 | + | |
| LcdDataWrite('W'); | LcdDataWrite('W'); | ||
| LcdDataWrite('e'); | LcdDataWrite('e'); | ||
| Line 103: | Line 101: | ||
| LcdDataWrite('o'); | LcdDataWrite('o'); | ||
| delay(10); | delay(10); | ||
| - | LcdCommandWrite(0xc0+1); // 定义光标位置为第二行第二个位置 | + | LcdCommandWrite(0xc0+1); |
| delay(10); | delay(10); | ||
| LcdDataWrite('g'); | LcdDataWrite('g'); | ||
| Line 119: | Line 117: | ||
| LcdDataWrite('p'); | LcdDataWrite('p'); | ||
| delay(5000); | delay(5000); | ||
| - | LcdCommandWrite(0x01); // 屏幕清空,光标位置归零 | + | LcdCommandWrite(0x01); |
| delay(10); | delay(10); | ||
| LcdDataWrite('I'); | LcdDataWrite('I'); | ||
| Line 133: | Line 131: | ||
| LcdDataWrite('i'); | LcdDataWrite('i'); | ||
| delay(3000); | delay(3000); | ||
| - | LcdCommandWrite(0x02); //设置模式为新文字替换老文字,无新文字的地方显示不变。 | + | LcdCommandWrite(0x02); |
| delay(10); | delay(10); | ||
| - | LcdCommandWrite(0x80+5); //定义光标位置为第一行第六个位置 | + | LcdCommandWrite(0x80+5); |
| delay(10); | delay(10); | ||
| LcdDataWrite('t'); | LcdDataWrite('t'); | ||