使用LCD1602显示“武汉大学”

#include "reg52.h"
#include "intrins.h"

#define databuffer P0

sbit RS= P1^0;
sbit RW= P1^1;
sbit E = P1^4;


void Delay15ms()		//@11.0592MHz
{
	unsigned char i, j;

	i = 27;
	j = 226;
	do
	{
		while (--j);
	} while (--i);
}

void Delay5ms()		//@11.0592MHz
{
	unsigned char i, j;

	i = 9;
	j = 244;
	do
	{
		while (--j);
	} while (--i);
}

void check_busy()
{
  char tmp   = 0x80;
	databuffer = 0x80;
	while(tmp & 0x80)
	{
	RS = 0;
	RW = 1;
	E  = 0;
	_nop_();
	E  = 1;
	_nop_();
	tmp=databuffer;
	E  = 0;
	_nop_();
	}
	
}

void Write_cmd_func(char cmd)
{
	check_busy();
	RS = 0;
	RW = 0;
	E  = 0;
	_nop_();
	databuffer = cmd;
	_nop_();
	E  = 1;
	_nop_();
	E  = 0;
	_nop_();
}

void Write_data_func(char datashow)
{
	check_busy();
	RS = 1;
	RW = 0;
	E  = 0;
	_nop_();
	databuffer = datashow;
	_nop_();
	E  = 1;
	_nop_();
	E  = 0;
	_nop_();
	
}

void LCD1602_INIT()
{
	Delay15ms();
	Write_cmd_func(0x38);
	Delay5ms();
	Write_cmd_func(0x38);
	Write_cmd_func(0x08);
	Write_cmd_func(0x01);
	Write_cmd_func(0x06);
	Write_cmd_func(0x0c);
	
}

void LCD1602_line(int row,int line,char* string)
{
	switch(row)
	{
		case 1:
			Write_cmd_func(0x80+line);
		while(*string)
		{
			Write_data_func(*string);
			string++;
		}
		break;
		case 2:
			Write_cmd_func(0x80+0x40+line);
		while(*string)
		{
			Write_data_func(*string);
			string++;
		}
		break;
		
	}
}

void main()
{


	LCD1602_INIT();
	
	LCD1602_line(1,5,"WU HAN");
	LCD1602_line(2,3,"UNIVERSITY");
  
	
	
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值