本帖最后由 xinxincaijq 于 2013-3-14 11:19 编辑
我们从LinkSprite买了一块16×2 LCD扩展板,并为pcDuino安装上 。你只需要花半个小时进行Arduino代码转码,转码完成后我们就可以在16×2 LCD屏幕上显示文本啦。
代码如下: #include <core.h> #define RS 8 #define EN 9 #define backlight 10 #define RS_L digitalWrite(RS,LOW) #define RS_H digitalWrite(RS,HIGH) #define EN_L digitalWrite(EN,LOW) #define EN_H digitalWrite(EN,HIGH) int DB[] = {7,6,5,4}; /********************************************************************/ void write_command(int command) { int i,temp; RS_L; EN_L; temp=command & 0xf0; for (i=0; i < 4; i++) { if(temp&0×80) digitalWrite(DB,HIGH); else digitalWrite(DB,LOW); temp <<= 1; } EN_H; delayMicroseconds(1); EN_L; temp=(command & 0x0f)<<4; for (i=0; i < 4; i++) { if(temp&0×80) digitalWrite(DB,HIGH); else digitalWrite(DB,LOW); temp <<= 1; } EN_H; delayMicroseconds(1); EN_L; } /********************************************************************/ void write_data(int dat) { int i=0,temp; RS_H; EN_L; temp=dat & 0xf0; for (i=0; i < 4; i++) { if(temp&0×80) digitalWrite(DB,HIGH); else digitalWrite(DB,LOW); temp <<= 1; } EN_H; delayMicroseconds(1); EN_L; temp=(dat & 0x0f)<<4; for (i=0; i < 4; i++) { if(temp&0×80) digitalWrite(DB,HIGH); else digitalWrite(DB,LOW); temp <<= 1; } EN_H; delayMicroseconds(1); EN_L; } /********************************************************************/ void LCD_write_char( int x,int y,int dat) { int address; if (x ==0) address = 0×80 + y; else address = 0xC0 + y; write_command(address); write_data(dat); delayMicroseconds(10); } /********************************************************************/ void lcd1602_init() { int i = 0; pinMode(RS,OUTPUT); pinMode(EN,OUTPUT); pinMode(backlight,OUTPUT); digitalWrite(backlight,HIGH); for (i=0; i < 4; i++) { pinMode(DB,OUTPUT); } delay(100); write_command(0×28); delay(50); write_command(0×06); delay(50); write_command(0x0c); delay(50); write_command(0×80); delay(50); write_command(0×01); delay(100); } /********************************************************************/ void setup (void) { lcd1602_init(); } /********************************************************************/ void loop (void) { write_command(0×02); delay(10); LCD_write_char(0,2,’W'); LCD_write_char(0,3,’e'); LCD_write_char(0,4,’l'); LCD_write_char(0,5,’c'); LCD_write_char(0,6,’o'); LCD_write_char(0,7,’m'); LCD_write_char(0,8,’e'); LCD_write_char(0,10,’t'); LCD_write_char(0,11,’o'); LCD_write_char(1,4,’p'); LCD_write_char(1,5,’c'); LCD_write_char(1,6,’D'); LCD_write_char(1,7,’u'); LCD_write_char(1,8,’i'); LCD_write_char(1,9,’n'); LCD_write_char(1,10,’o'); while(1); }
爱板商城购买链接:
猛戳 https://www.cirmall.com/shop/?c=products&a=view&id=221
|