关于51单片机与12864显示问题~~拜托了~
以下程序不知道什地方出现错误,12864总是不显示字,请教高手指点~~谢谢啦#include<reg52.h>#include<string.h>#include<int...
以下程序不知道什地方出现错误,12864总是不显示字,请教高手指点~~谢谢啦
#include <reg52.h>
#include <string.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
//12864液晶控制引脚定义
sbit E=P2^5;
sbit RW=P2^6;
sbit RS=P2^7;
sbit PSB=P2^4;
#define lcd_bus P0
//开机的欢迎字
uchar code TAB[]={"青岛理工大学"};
void delay(uint t);
//void wait();
void lcd_write_order(uchar order);
void lcd_write_data(uchar lcddata);
void lcd_set_xy(uchar x,uchar y);
void init_lcd();
void lcd_write_string(uchar x,uchar y,uchar dis[]);
void main()
{
init_lcd();
delay(10000);
lcd_write_string(0,0,TAB);
while(1)
{
}
}
/**************液晶驱动程序****************************/
void delay(uint t)
{
int i, j;
for(i=t;i>0;i--)
for(j=10;j>0;j--);
}
/*bit check_busy() //判断LCD忙程序
{
bit busy;
RS=0;
RW=1; //读状态
E=1;
_nop_();
busy=(bit)(lcd_bus&0x80);//判断P2_7是否为0(液晶内部是否忙)
E=0;
return busy;
}
void wait()//等待液晶空闲
{
while(check_busy());
}
*/
void lcd_write_order(uchar order) //液晶写指令
{
// wait();
RS = 0 ; //显示指令
RW = 0 ; //写
E = 0 ;
lcd_bus =order;
E = 1 ;
delay(100);
E = 0 ;
}
void lcd_write_data(uchar lcddata) //液晶写数据
{
// wait();
RS = 1 ; //显示数据
RW = 0 ;
E = 0 ; //写
lcd_bus = lcddata;
E = 1 ;
delay(100); //下降沿触发
E = 0 ;
}
void lcd_set_xy(uchar x,uchar y)
{
uchar address;
switch(y)
{
case 0:
address = 0x80 + x;
break;
case 1:
address = 0x90 + x;
break;
case 2:
address = 0x88 + x;
break;
case 3:
address = 0x98 + x;
break;
default:address = 0x80 + x;
}
lcd_write_order(0x80|address);
}
void init_lcd()
{
PSB=1;
lcd_write_order(0x30); //基本指令集
delay(100);
lcd_write_order(0x0c); //显示打开,光标关,反白显示关
delay(100);
//lcd_write_order(0x06); //DDRAM的地址计数器(AC)加1
//delay(100);
lcd_write_order(0x01); //清除屏幕显示,将DDRAM的地址计数器归零
delay(100); //等待初始化结束
}
void lcd_write_string(uchar x,uchar y,uchar dis[])
{
uchar i;
//lcd_write_order(0x30);
lcd_set_xy(x,y);
i=0;
while (dis[i]!='\0')
{
lcd_write_data(dis[i]);
i++;
}
} 展开
#include <reg52.h>
#include <string.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
//12864液晶控制引脚定义
sbit E=P2^5;
sbit RW=P2^6;
sbit RS=P2^7;
sbit PSB=P2^4;
#define lcd_bus P0
//开机的欢迎字
uchar code TAB[]={"青岛理工大学"};
void delay(uint t);
//void wait();
void lcd_write_order(uchar order);
void lcd_write_data(uchar lcddata);
void lcd_set_xy(uchar x,uchar y);
void init_lcd();
void lcd_write_string(uchar x,uchar y,uchar dis[]);
void main()
{
init_lcd();
delay(10000);
lcd_write_string(0,0,TAB);
while(1)
{
}
}
/**************液晶驱动程序****************************/
void delay(uint t)
{
int i, j;
for(i=t;i>0;i--)
for(j=10;j>0;j--);
}
/*bit check_busy() //判断LCD忙程序
{
bit busy;
RS=0;
RW=1; //读状态
E=1;
_nop_();
busy=(bit)(lcd_bus&0x80);//判断P2_7是否为0(液晶内部是否忙)
E=0;
return busy;
}
void wait()//等待液晶空闲
{
while(check_busy());
}
*/
void lcd_write_order(uchar order) //液晶写指令
{
// wait();
RS = 0 ; //显示指令
RW = 0 ; //写
E = 0 ;
lcd_bus =order;
E = 1 ;
delay(100);
E = 0 ;
}
void lcd_write_data(uchar lcddata) //液晶写数据
{
// wait();
RS = 1 ; //显示数据
RW = 0 ;
E = 0 ; //写
lcd_bus = lcddata;
E = 1 ;
delay(100); //下降沿触发
E = 0 ;
}
void lcd_set_xy(uchar x,uchar y)
{
uchar address;
switch(y)
{
case 0:
address = 0x80 + x;
break;
case 1:
address = 0x90 + x;
break;
case 2:
address = 0x88 + x;
break;
case 3:
address = 0x98 + x;
break;
default:address = 0x80 + x;
}
lcd_write_order(0x80|address);
}
void init_lcd()
{
PSB=1;
lcd_write_order(0x30); //基本指令集
delay(100);
lcd_write_order(0x0c); //显示打开,光标关,反白显示关
delay(100);
//lcd_write_order(0x06); //DDRAM的地址计数器(AC)加1
//delay(100);
lcd_write_order(0x01); //清除屏幕显示,将DDRAM的地址计数器归零
delay(100); //等待初始化结束
}
void lcd_write_string(uchar x,uchar y,uchar dis[])
{
uchar i;
//lcd_write_order(0x30);
lcd_set_xy(x,y);
i=0;
while (dis[i]!='\0')
{
lcd_write_data(dis[i]);
i++;
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询