《单片机实践项目》《电子DIY》基于51单片机的串行LCD1602显示详细讲解,Proteus仿真

程序:

//B站搜索:逗比小憨憨
#include 

#define uint unsigned int
#define uchar unsigned char

uchar code prompts[]=" Serial LCD DEMO ";

void delay_ms(uint ms)
{
 	uchar i;
	while(ms--)
	{
	 	for(i=0;i<118;i++);
	}
}
void putc_to_LCD(uchar c)
{
 	SBUF = c;
	while(TI == 0);
	TI = 0;
}

uchar getc_from_terminal(void)
{
 	while(RI == 0);
	RI = 0;
	return SBUF;
}

void wrcmd(uchar comm)
{
 	putc_to_LCD(0xfe);
	putc_to_LCD(comm);
}

int main(void)
{
 	uchar i=0,c;

	TMOD |= 0x20;//T1溢出率
	TH1 = 0xfd;	//9600
	TL1 = 0xfd;
	SCON = 0x50; //串口方式1  REN=1:允许串口接收


	RI = 0;
	TI = 0;
	TR1 = 1;
	delay_ms(200);
	while(prompts[i] != '\0')
	{
	 	putc_to_LCD(prompts[i+1]);
		delay_ms(5);
	}
	wrcmd(0xc0);
	wrcmd(0x0d);
	delay_ms(200);
	while(1)
	{
	 	c = getc_from_terminal();
		if(c==0x0d)
		{
		 	wrcmd(0x01);
			continue;
		}
		if(c==0x08)
		{
		 	wrcmd(0x10);
			continue;
		}
		putc_to_LCD(c);
		delay_ms(500);
	}
	return 0;
}

你可能感兴趣的:(电子DIY,串行LCD1602,51单片机实践,Proteus仿真,串口讲解,程序源码)