#include<reg52.h> #include<intrins.h> #define uchar unsigned char #define uint unsigned int sbit RS=P2^0; sbit RW=P2^1; sbit E=P2^2; sbit BF=P0^7; uchar code string[]={"HELLO.WORLD"}; /***************************************************** 函数功能:延时若干毫秒 入口参数:n ***************************************************/ void delay1ms(uchar i) { uchar j; while(i--) { for(j=0;j<115;j++); } } /***************************************************** 函数功能:判断液晶模块的忙碌状态 返回值:result。result=1,忙碌;result=0,不忙 ***************************************************/ bit busy_lcd() { bit result; E=1; /*大大问题??????????*/ RS=0; RW=1; /*E=1;大大问题*/ _nop_(); _nop_(); _nop_(); _nop_(); result=BF; E=0; return result; } /***************************************************** 函数功能:将模式设置指令或显示地址写入液晶模块 入口参数:dictate ***************************************************/ void com_lcd(uchar com) { while(busy_lcd()==1); RS=0; RW=0; E=0; _nop_(); _nop_(); _nop_(); P0=com; _nop_(); _nop_(); _nop_(); _nop_(); E=1; _nop_(); _nop_(); _nop_(); _nop_(); E=0; } /***************************************************** 函数功能:指定字符显示的实际地址 入口参数:x ***************************************************/ void addrrom_lcd(uchar add) { com_lcd(0x80|add); delay1ms(10); } /***************************************************** 函数功能:将数据(字符的标准ASCII码)写入液晶模块 入口参数:y(为字符常量) ***************************************************/ void writer_lcd(uchar dat) { while(busy_lcd()==1); RS=1; RW=0; E=0; P0=dat; _nop_(); _nop_(); _nop_(); _nop_(); E=1; _nop_(); _nop_(); _nop_(); _nop_(); E=0; } /***************************************************** 函数功能:对LCD的显示模式进行初始化设置 ***************************************************/ void init_lcd() { delay1ms(15); com_lcd(0x38); delay1ms(5); com_lcd(0x38); delay1ms(5); com_lcd(0x38); delay1ms(5); com_lcd(0x01); delay1ms(5); com_lcd(0x06); delay1ms(5); com_lcd(0x0f); delay1ms(5); } void main() { uchar i; init_lcd(); delay1ms(10); while(1) { i=0; com_lcd(0x01); delay1ms(2); addrrom_lcd(0x00); delay1ms(2); while(string[i]!='\0') { writer_lcd(string[i]); delay1ms(100); i++; } while(1); } }
收藏0 举报
本版积分规则 发表回复 回帖并转播 回帖后跳转到最后一页
人才类勋章
时间类勋章
发帖类勋章
等级类勋章
3
6
0
扫码关注 21ic 官方微信
扫码关注嵌入式微处理器
扫码关注电源系统设计
扫码关注21ic项目外包
扫码浏览21ic手机版
本站介绍 | 申请友情链接 | 欢迎投稿 | 隐私声明 | 广告业务 | 网站地图 | 联系我们 | 诚聘英才
京公网安备 11010802024343号