lcd1602怎么使用?

程序?
2024-12-28 08:40:09
推荐回答(1个)
回答1:

unsigned char str1[]={"temperature: "};
unsigned char str2[]={" "};

unsigned char disdata[5];

/*************************lcd1602程序**************************/
void delay1ms(uint z)
{
uint t,y;
for(t=z;t>0;t--)
for(y=300;y>0;y--);
}

void wr_com(unsigned char com)//写指令//
{
//delay1ms(15);
RS_0;
RW_0;
// EN_0;
P4OUT=com;
delay1ms(10);
EN_1;
delay1ms(15);
EN_0;
}

void wr_dat(unsigned char dat)//写数据//
{
//delay1ms(1);;
RS_1;
RW_0;
//EN_0;
P4OUT=dat ;
delay1ms(10);
EN_1;
delay1ms(15);
EN_0;
}
/**************lcd初始化**************/
void lcd_init()//初始化设置//
{

//delay1ms(150);
wr_com(0x38);//delay1ms(50);
wr_com(0x0c);//delay1ms(50);
wr_com(0x06);//delay1ms(50);
wr_com(0x01);//delay1ms(50);
//wr_com(0x08);//delay1ms(50);
}

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

init_play()//初始化显示
{
lcd_init();
wr_com(0x80);
display(str1);
wr_com(0xc0);
display(str2);
}

部分代码。供参考。