完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
我刚学习单片机用1602时总是出现乱码,在网上查了半天还是没有解决问题,望高人相助!下面是我的代码#include
#define uchar unsigned char #define uint unsigned int ***it rs=P2^6; ***it rw=P2^5; ***it en=P2^7; uchar code table0[]="I LOVE YOU !"; uchar code table1[]="I LOVE YOU !"; void delay(uchar z) { uchar x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } void write_com(uchar com) { uchar gao,di; rs=0; rw=0; gao=com&0xf0; //分离高4位 di=(com<<4)&0xf0; //分离低4位 P0=gao; delay(5); en=1; delay(5); en=0; P0=di; delay(5); en=1; delay(5); en=0; } void write_data(uchar date) { uchar gao,di; rs=1; rw=0; gao=date&0xf0; //分离高4位 di=(date<<4)&0xf0; //分离低4位 P0=gao; delay(5); en=1; delay(5); en=0; P0=di; delay(5); en=1; delay(5); en=0; } void initial() { en=0; write_com(0x38); write_com(0x0c); write_com(0x06); write_com(0x01); write_com(0x80); } void main() { uchar i; initial(); for(i=0;i<12;i++) { write_data(table0[i]); delay(20); } write_com(0x80+0x40); for(i=0;i<12;i++) { write_data(table1[i]); delay(20); } } 评分 |
|
相关推荐
11个回答
|
|
4总线LCD初始化错了
void initial() { en=0; write_com(0x32); write_com(0x28); write_com(0x0c); write_com(0x06); write_com(0x01); write_com(0x80); }
最佳答案
|
|
|
|
|
|
|
|
#ifndef __LCD__ #define __LCD__ ***it rs=P3^0; ***it rw=P3^1; ***it en=P3^2; ***it key_left=P2^0; ***it key_right=P2^1 ; #define DATAPORT P0 #define BUSY 0x80 //常量定义 #define uchar unsigned char #define uint unsigned int uchar code opens[]="MACROSS"; uchar code opens1[]="FRONTIER"; uchar code hanzi[3][8]={0x1f,0x11,0x11,0x1f,0x11,0x11,0x1f,0x00, 0x0f,0x09,0x0f,0x09,0x0f,0x09,0x11,0x00, 0x08,0x0f,0x12,0x0f,0x0a,0x1f,0x02,0x02}; void open(); void ini(); void write_order(uchar order,uchar BusyC) ; void write_date(uchar date); void delay(uchar z); void writeCG(); void ini() { rw=0; en=0; P2=0xff; writeCG(); write_order(0x38,1); write_order(0x0c,1); write_order(0x06,1); write_order(0x01,1); } void lcd_wait(void) { DATAPORT=0xff; //读LCD前若单片机输出低电平,而读出LCD为高电平,则冲突,Proteus仿真会有显示逻辑黄色 en=1; rs=0; rw=1; _nop_(); _nop_(); _nop_(); while(DATAPORT&BUSY) { en=0; _nop_(); _nop_(); en=1; _nop_(); _nop_(); } en=0; } void write_order(uchar com,uchar BusyC) { /* rs=0; P2=order; delay(4); en=1; delay(4); en=0; */ if(BusyC)lcd_wait(); DATAPORT=com; rs=0; // 选中指令寄存器 rw=0; // 写模式 en=1; _nop_(); _nop_(); _nop_(); en=0; } void write_date(uchar date) { /* rs=1; P2=date; delay(4); en=1; delay(4); en=0; */ lcd_wait( ); //检测忙信号 DATAPORT=date; rs=1; // 选中数据寄存器 rw=0; // 写模式 en=1; _nop_(); _nop_(); _nop_(); en=0; } void delay(uchar z) { uchar x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } void writeCG() { uchar x,y; write_order(0x40,1); for(y=0;y<3;y++) { for(x=0;x<8;x++) { write_date(hanzi[y][x]); } } } void open() { uchar num; write_order(0x80+0x10,1); for(num=0;opens[num]!=' |