我想做的是两行字体都是从最右边一起移入;
可是为什么第一行字体从最右边移入,而第二行不是;
仿真图片:
这是代码:
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define out P0
sbit RS=P2^0;
sbit RW=P2^1;
sbit E=P2^2;
void LCD_initial(void); //LCD初始化函数
void check_busy(void); //检查忙标志函数
void write_command(uchar com); //写命令函数
void write_data(uchar dat); //写数据函数
void string(uchar ad,uchar * s);
void lcd_test(void);
void delay(uint);
void main (void)
{
LCD_initial();
while(1)
{
string(0x8f,"welcome");
string(0xcf,"Harbin china");
delay(100);
write_command(0x01);
delay(100);
}
}
void delay(uint j)
{
uchar i=250;
for(;j>0;j--)
{
while(--i);
i=249;
while(--i);
i=250;
}
}
void check_busy(void)
{
uchar dt;
do
{
dt=0xff;
E=0;
RS=0;
RW=1;
E=1;
dt=out;
}while(dt&0x80);
E=0;
}
void write_command(uchar com)
{
check_busy();
E=0;
RS=0;
RW=0;
out=com;
E=1;
_nop_();
E=0;
delay(1);
}
void write_data(uchar dat)
{
check_busy();
E=0;
RS=1;
RW=0;
out=dat;
E=1;
_nop_();
E=0 ;
delay(1);
}
void LCD_initial(void)
{
write_command(0x38); //8位两行显示,5X7点阵字符
write_command(0x0c); //开整体显示,光标关,无黑块
write_command(0x07); //光标右移
write_command(0x01); //清屏
delay(1);
}
void string(uchar ad,uchar *s)
{
write_command(ad);
while(* s > 0)
{
write_data(*s++); //输出字符串,且指针增1
delay(100);
}
}
非常感谢你的回答
|