当前位置:网站首页>LCD1602 string display (STM32F103)
LCD1602 string display (STM32F103)
2022-06-24 19:23:00 【Me-Space】
One 、 summary
1602 Liquid crystal is 5V Voltage driven , With backlight , Two lines can be displayed , Each row 16 Characters , Chinese characters cannot be displayed , built-in 1128 A character ASCII Character set , Parallel communication mode . This test is passed STM32F103C8T6 The minimum system drives the LCD to display a string of characters .
Two 、 Experimental materials
1、STM32F103C8T6 Minimum system
2、LCD1602 liquid crystal
3、 There are several DuPont lines
3、 ... and 、 Basic operation sequence
state | Input | Output |
---|---|---|
Read status | RS=L,RW=H,E=H | D0-D7= state |
Write instructions | RS=L,RW=L,D0-D7= Instruction code ,E= High pulse | nothing |
Reading data | RS=H,RW=H,E=H | D0-D7= data |
Writing data | RS=H,RE=L,D0-D7= data ,E= High pulse | nothing |
Four 、 Hardware connection
5、 ... and 、 Program code
1、GPIO initialization
void Lcd1602_Pin_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_8 |
GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 |
GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStruct);
}
2、LCD1602 initialization
void Lcd1602_Init(void)
{
Lcd1602_Pin_Init();
delay_ms(15);
Lcd1602_Write_Cmd(0X38);
Lcd1602_Write_Cmd(0X0C);// On display does not display the cursor
Lcd1602_Write_Cmd(0X06);// Write a pointer plus 1
Lcd1602_Write_Cmd(0X01);// Clear the screen
Lcd1602_Write_Cmd(0X80);// Set data pointer start point
}
3、 Detect busy state
void Lcd1602_Check_Busy(void)
{
u8 signal;
LCD_RS = 0;
LCD_RW = 1;
do
{
LCD_EN = 1;
signal = LCD_BUSY;
LCD_EN = 0;
}while(signal);
}
4、 Write instructions
void Lcd1602_Write_Cmd(int cmd)
{
Lcd1602_Check_Busy();// Detect busy state
LCD_RS = 0;
LCD_RW = 0;
LCD_EN = 0;
cmd=cmd<<8;
GPIOB->ODR=((GPIOB->ODR & 0x00FF)|(cmd&0xFF00));//PB15-8 It's data bits ,PB0-7 The data can't change
delay_us(2);
LCD_EN = 1;
delay_us(2);
LCD_EN = 0;
delay_ms(15);
}
5、 Writing data
void Lcd1602_Write_Data(int data)
{
Lcd1602_Check_Busy();// Detect busy state
LCD_RS = 1;
LCD_RW = 0;
LCD_EN = 0;
data<<= 8;
GPIOB->ODR = ((GPIOB->ODR & 0X00FF) | (data& 0XFF00));
delay_us(2);
LCD_EN = 1;
delay_us(2);
LCD_EN = 0;
delay_ms(15);
}
6、 Show characters
// @u8 row: That's ok
// @u8 col: Column
// @int ch: character
void Lcd1602_DisplayChar(u8 row,u8 col,int ch)
{
// Display position
int add = 0;
// Judgment is that line
if(row == 2)
{
// The first address on the second line 0x40
add += 0x40;
}
// The first address on the first line 0x80
add += 0x80 + col - 1;
Lcd1602_Write_Cmd(add);
// According to the content
Lcd1602_Write_Data(ch);
}
7、 display string
// @u8 row: That's ok
// @u8 col: Column
// @u8 *str: String first address
void Lcd1602_DisplayString(u8 row,u8 col,u8 *str)
{
while(*str != '\0')
{
Lcd1602_DisplayChar(row,col,*str);
col += 1;
str++;
}
}
8、 The main program
int main(void)
{
u8 buf[] = {
"I Love You!"};
u8 date[] = {
"2021/2/7"};
u8 author[] = {
"Qing"};
Sys_Delay_Init();
Lcd1602_Init();
// Single character
// Lcd1602_DisplayChar(2,2,'A');
// character string
Lcd1602_DisplayString(1,1,buf);
Lcd1602_DisplayString(2,1,date);
Lcd1602_DisplayString(2,13,author);
while(1)
{
}
}
6、 ... and 、 Experimental results
Complete procedure and LCD1602 LCD related information :
link :https://pan.baidu.com/s/1Ok-P7IACpib_vLQX57ikVg
Extraction code :hcyp
If there is any mistake, please point out , thank you !
边栏推荐
- Source code analysis of ArrayList
- 怎么使用R包ggtreeExtra绘制进化树
- Would you like to ask whether the same multiple tasks of the PgSQL CDC account will have an impact? I now have only one of the three tasks
- At present, only CDC monitors Mysql to get the data of new columns. Sqlserver can't, can it
- Sr-gnn shift robot gnns: overlapping the limitations of localized graph training data
- 目前是不是只cdc 监控mysql 可以拿到新增列的数据 sqlserver不行是吧
- 工作6年,月薪3W,1名PM的奋斗史
- The sharp sword of API management -- eolink
- Generate the last login user account report of the computer through SCCM SQL
- The group offsets of the Kafka of the Flink SQL. If the specified groupid is not mentioned
猜你喜欢
Example analysis of corrplot related heat map beautification in R language
How to customize cursor position in wechat applet rotation chart
Sr-gnn shift robot gnns: overlapping the limitations of localized graph training data
为什么生命科学企业都在陆续上云?
R语言corrplot相关热图美化实例分析
应用实践 | 海量数据,秒级分析!Flink+Doris 构建实时数仓方案
Make track map
A detailed explanation of the implementation principle of go Distributed Link Tracking
System design idea of time traceability
Introduction and download of nine npp\gpp datasets
随机推荐
Ask a question. Adbhi supports the retention of 100 databases with the latest IDs. Is this an operation like this
对国产数据库厂商提几个关于SQL引擎的小需求
At present, only CDC monitors Mysql to get the data of new columns. Sqlserver can't, can it
Source code analysis of ArrayList
The efficiency of okcc call center data operation
How to deal with the problem that the Flink CDC reads MySQL in full and always reports this error
The group offsets of the Kafka of the Flink SQL. If the specified groupid is not mentioned
60 个神级 VS Code 插件!!
How to customize cursor position in wechat applet rotation chart
Sr-gnn shift robot gnns: overlapping the limitations of localized graph training data
网络安全审查办公室对知网启动网络安全审查
Unity mobile game performance optimization spectrum CPU time-consuming optimization divided by engine modules
程序员大部分时间不是写代码,而是。。。
TKDE2022:基于知识增强采样的对话推荐系统
cdc sql表里面的datetime要用什么类型替换
优维低代码:构件渲染子构件
Would you like to ask whether the same multiple tasks of the PgSQL CDC account will have an impact? I now have only one of the three tasks
NOKOV动作捕捉系统使多场协同无人机自主建造成为可能
Introduction and download tutorial of administrative division vector data
Php OSS file read and write file, workerman Generate Temporary file and Output Browser Download