首页 > 其他分享 >18_LCD1602

18_LCD1602

时间:2023-11-30 15:12:29浏览次数:24  
标签:Column 18 void unsigned char LCD LCD1602 Line

LCD1602

介绍

image-20231124135256426

引脚及应用电路

image-20231124135613597

原理图

image-20231124140214861

image-20231124140345888

内部结构框图

image-20231124140413369

存储器结构

image-20231124140843985

时序结构

image-20231124141059029

LCD1602指令集

image-20231124141528284

LCD1602操作流程

image-20231124142529114

字符,字符串

image-20231125214207646

编写LCD1602代码

LCD1602.c

#include <REGX52.H>

sbit LCD_RS=P2^6; //1数据0指令
sbit LCD_RW=P2^5; //1读0写
sbit LCD_E=P2^7; //1数据有效,下降沿执行

#define LCD_DataPort P0

void LCD_Delay1ms(void)	//@12.000MHz
{
	unsigned char data i, j;

	i = 2;
	j = 239;
	do
	{
		while (--j);
	} while (--i);
}

void LCD_WriteCommand(unsigned char Command)
{
	LCD_RS=0;
	LCD_RW=0;
	LCD_DataPort=Command;
	LCD_E=1;
	LCD_Delay1ms();
	LCD_E=0;
	LCD_Delay1ms();
}

void LCD_WriteData(unsigned char Data)
{
	LCD_RS=1;
	LCD_RW=0;
	LCD_DataPort=Data;
	LCD_E=1;
	LCD_Delay1ms();
	LCD_E=0;
	LCD_Delay1ms();
}

void LCD_Init()
{
	LCD_WriteCommand(0x38); //八位数据接口,两行显示,5*7点阵
	LCD_WriteCommand(0x0C); //显示开,光标关,闪烁关
	LCD_WriteCommand(0x06); //数据读写操作后,光标自动加一,画面不动
	LCD_WriteCommand(0x01); //清屏
}

void LCD_SetCursor(unsigned char Line,unsigned char Column)
{
	if(Line==1)
	{
		LCD_WriteCommand(0x80|(Column-1)); //设置光标位置
	}
	else
	{
		LCD_WriteCommand(0x80|(Column-1)+0x40);
	}
}

void LCD_ShowChar(unsigned char Line,unsigned char Column,unsigned char Char)
{
	LCD_SetCursor(Line,Column);
	LCD_WriteData(Char);
}

void LCD_ShowString(unsigned char Line,unsigned char Column,unsigned char *String)
{
	unsigned char i;
	LCD_SetCursor(Line,Column);
	for(i=0;String[i]!='\0';i++)
	{
		LCD_WriteData(String[i]);
	}
}

int pow(int X,int Y)
{
	int Res=1;
	while(Y--)
	{
		Res*=X;
	}
	return Res;
}

void LCD_ShowNum(unsigned char Line,unsigned char Column,unsigned int Number,unsigned char Length)
{
	LCD_SetCursor(Line,Column);
	while(Length--)
	{
		LCD_WriteData(Number/pow(10,Length)%10+'0');
	}
}

void LCD_ShowSignedNum(unsigned char Line,unsigned char Column,int Number,unsigned char Length)
{
	unsigned int Number1;
	LCD_SetCursor(Line,Column);
	if(Number>=0)
	{
		LCD_WriteData('+');
		Number1=Number;
	}
	else
	{
		LCD_WriteData('-');
		Number1=-Number;
	}
	while(Length--)
	{
		LCD_WriteData(Number1/pow(10,Length)%10+'0');
	}
}

void LCD_ShowHexNum(unsigned char Line,unsigned char Column,unsigned int Number,unsigned char Length)
{
	unsigned char SingleNumber;
	LCD_SetCursor(Line,Column);
	while(Length--)
	{
		SingleNumber=Number/pow(16,Length)%16;
		if(SingleNumber>9)
		{
			LCD_WriteData(SingleNumber+'A'-10);
		}
		else
		{
			LCD_WriteData(SingleNumber+'0');
		}
	}
}

void LCD_ShowBinNum(unsigned char Line,unsigned char Column,unsigned int Number,unsigned char Length)
{
	unsigned char SingleNumber;
	LCD_SetCursor(Line,Column);
	while(Length--)
	{
		LCD_WriteData(Number/pow(2,Length)%2+'0');
	}
}

LCD1602.h

#ifndef __LCD1602_H__
#define __LCD1602_H__

void LCD_WriteCommand(unsigned char Command);
void LCD_Init();
void LCD_ShowChar(unsigned char Line,unsigned char Column,unsigned char Char);
void LCD_ShowString(unsigned char Line,unsigned char Column,unsigned char *String);
void LCD_ShowNum(unsigned char Line,unsigned char Column,unsigned int Number,unsigned char Length);
void LCD_ShowSignedNum(unsigned char Line,unsigned char Column,int Number,unsigned char Length);
void LCD_ShowHexNum(unsigned char Line,unsigned char Column,unsigned int Number,unsigned char Length);
void LCD_ShowBinNum(unsigned char Line,unsigned char Column,unsigned int Number,unsigned char Length);

#endif

main.c

#include <REGX52.H>
#include "LCD1602.h"
#include "Delay.h"

void main()
{
	LCD_Init();
	LCD_ShowBinNum(1,1,0xA5,8);
	LCD_ShowString(1,16,"Welcome to China!");
	
	while(1)
	{
		Delay(200);
		LCD_WriteCommand(0x18);
		Delay(200);
	}
}

运行效果

![VID_20231126_163649 (2)](H:\通讯软件\QQSave\1607442148\FileRecv\MobileFile\VID_20231126_163649 (2).gif)

标签:Column,18,void,unsigned,char,LCD,LCD1602,Line
From: https://www.cnblogs.com/mzx233/p/17867415.html

相关文章

  • 17_DS18B20温度传感器
    DS18B20温度传感器介绍引脚及应用电路原理图内部结构框图存储器结构单总线介绍单总线电路规范单总线时序结构DS18B20操作流程DS18B20数据帧温度存储格式获取温度用LCD显示OneWire.c#include<REGX52.H>#include<intrins.h>sbitOneWire_DQ=P3^7;......
  • MIT18.06Linear Algebra 第13讲 复习一
    转载于:超详细MIT线性代数公开课笔记......
  • MIT18.06Linear Algebra 第14讲 正交向量与正交子空间
    转载于:超详细MIT线性代数公开课笔记......
  • [SUCTF2018]followme
    [SUCTF2018]followme看起来像是在做渗透测试的时候抓的包,导出所有HTTP对象大部分是类似这种的文件login%3f_=6975b9a9f7a359d322e06c0e28db112blogin.php%3freferer=http%3A%2F%2F192.168.128.145%2Fbuild%2Fadmin%2F<!DOCTYPEHTML><htmlclass="no-js"><head>......
  • CF1846E2 Rudolf and Snowflakes (hard version) 题解
    题意:\(T\)\((\)\(1\)\(\le\)\(T\)\(\le\)\(10^4\)\()\)组询问:是否存在一个满\(k\)(\(k\)\(\ge\)\(2\)\()\)叉树节点数恰好为\(n\)\((\)\(1\)\(\le\)\(n\)\(\le\)\(10^{18}\)\()\),且深度\(depth\)至少为\(2\)。思路:满$k$......
  • CF1827C Palindrome Partition 题解
    题目链接点击打开链接题目解法首先考虑一个朴素的\(dp\)令\(f_i\)表示以\(i\)结尾的合法子串的个数为了不重不漏,我们令\(le_i\)表示以\(i\)为右端点,离\(i\)最近的偶回文串的左端点,然后不难得到转移为\(f_i=f_{le_i-1}+1\)为什么不会漏?考虑以\(i\)为右端点,且比......
  • 国标GB28181视频监控平台LiteCVR偶发不能播放的问题排查
    随着互联网技术的发展,运用先进的AI、物联网、大数据、云计算等技术手段,可以不断提高安防监控技术的进步与应用。通过视频采集、网络传输、分析计算、视频存储、关联应用等核心能力,对视频内容、视频结构化信息的智能分析,从而实现各种场景下的视频可视化智能监管。成都来特科技-li......
  • 视频智能分析国标GB28181云平台EasyCVR加密机授权异常是什么原因?
    国标GB28181视频汇聚/视频云存储/集中存储/视频监控管理平台EasyCVR能在复杂的网络环境中,将分散的各类视频资源进行统一汇聚、整合、集中管理,实现视频资源的鉴权管理、按需调阅、全网分发、云存储、智能分析等。近期有用户选择使用加密机进行EasyCVR授权,但平台显示到期,于是联系......
  • CF1886B Fear of the Dark
    这道题只有两种情况:\(O\)点和\(P\)点都在同一个圆圈里;或者\(O\)点在一个圆圈里,\(P\)点在另外一个圆圈里。让我们用\(d(P,Q)\)来表示\(P\)点到\(Q\)点之间的距离,\(R\)记为半径。我们先来看第一种情况:\(O\)点和\(P\)点都在同一个圆圈\(A\)里。这种情况下,应满足......
  • P5318 【深基18.例3】查找文献
    P5318【深基18.例3】查找文献基本思路邻接表实现,结果得为了边有序再专门开一个vector预处理完再存边。而且一开始忘记vis[1]=true了!#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<queue>#include<vector>constintN=1e6......