LCD1602的简单应用

此程序主要功能是液晶屏缓慢依次显示ABCD4个字母

#include
#define uint unsigned int
#define uchar unsigned char 

sbit LCD_RW=P2^5;
sbit LCD_RS=P2^6;
sbit LCD_EN=P2^7;
uchar num[]={"ABCD"};

void delay1ms(uint c);
void writecom(uchar com);//写指令
void LCD_Init();//液晶屏初始化
void writedata(uchar Data);
void main()
{
	uint i;
	LCD_Init();
	for (i=0;i<4;i++)
		{
			writedata(num[i]);
			delay1ms(500);
		}
	while(1);
}
void delay1ms(uint c)   
{
    uchar a,b;
	for (; c>0; c--)
	{
		 for (b=199;b>0;b--)
		 {
		  	for(a=1;a>0;a--);
		 }      
	}
    	
}
/*对液晶屏进行写操作*/
void writecom(uchar com)
{
	LCD_RW=0;
	LCD_RS=0;
	LCD_EN=0;
	
	LCD_EN=1;
	delay1ms(1);
	P0=com;
	delay1ms(5);
	LCD_EN=0;
}
/*对液晶屏进行初始化设置*/
void LCD_Init()
{
	writecom(0x38);//开显示
	writecom(0x0c);//设置是否显示光标
	writecom(0x06);  //写一个指针加1
	writecom(0x01);  //清屏
	writecom(0x80);  //设置数据指针起点
}
/*进行写数据*/
void writedata(uchar Data)
{
	LCD_RW=0;
	LCD_RS=1;
	LCD_EN=0;
	
	LCD_EN=1;
	delay1ms(1);
	P0=Data;
	delay1ms(5);
	LCD_EN=0;
}

你可能感兴趣的:(51单片机)