查看: 934|回复: 0

为你的pcDuino开发板安装一块LCD扩展模块

[复制链接]
  • TA的每日心情
    奋斗
    2016-4-25 13:46
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]初来乍到

    发表于 2013-3-8 19:29:54 | 显示全部楼层 |阅读模式
    分享到:
    我们从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);}
    回复

    使用道具 举报

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

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-11-18 08:43 , Processed in 0.121251 second(s), 17 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.