用C51语言对1602液晶进行编译,在液晶屏幕第一行显示“yangzhou”,第二行显示“Welcome”

求高手指点
2024-12-02 14:09:44
推荐回答(1个)
回答1:

//晶振12M
#include
sbit RS=P2^6;
sbit EN=P2^7;
unsigned char code str1[]={"yangzhou "};
unsigned char code str2[]={"Welcome "};

void init_play(void)//显示初始化
{
lcd_init();
wr_com(0x80);//第一行
display(str1);

wr_com(0xc0); //第二行
display(str2);
}

/***************lcd1602程序*******************/
void delay1ms(unsigned int ms)//延时1毫秒//
{unsigned int i,j;
for(i=0;i for(j=0;j<100;j++);
}

void wr_com(unsigned char com)//写指令//
{ delay1ms(1);
RS=0;
EN=0;
P0=com;
delay1ms(1);
EN=1;
delay1ms(1);
EN=0;
}

void wr_dat(unsigned char dat)//写数据//
{ delay1ms(1);;
RS=1;
EN=0;
P0=dat;
delay1ms(1);
EN=1;
delay1ms(1);
EN=0;
}

void lcd_init()//lcd初始化设置//
{delay1ms(15);
wr_com(0x38);delay1ms(5);
wr_com(0x08);delay1ms(5);
wr_com(0x01);delay1ms(5);
wr_com(0x06);delay1ms(5);
wr_com(0x0c);delay1ms(5);
}

void display(unsigned char *p)//显示//
{
while(*p!='\0')
{
wr_dat(*p);
p++;
delay1ms(1);
}
}

/************主程序********************/
void main()
{ init_play();//初始化显示
while(1)
{

}
}