1800 views|4 replies

478

Posts

0

Resources
The OP
 

How do I convert 51 code to STM32 driver code? [Copy link]

From: Embedded from 0 to 1 Author: Programmer Xiaoha

Origin of the problem

User Q&A

NOKIA 5110 Screen

The Nokia5110 screen is a very classic LCD display module. When Xiaoha was playing with microcontrollers, there were not many LCD modules to choose from, generally speaking, they were LCD1602 and LCD12864. In my opinion at the time, the Nokia5110 screen was a very advanced LCD screen.

Nokia 5110 screen is a liquid crystal display module used in 5110, 6150, 6100 and other series of mobile phones. Domestic manufacturers also produce similar compatible products.

In addition to mobile phones, this product can also be widely used in display systems of various portable devices, single-chip microcomputer control display, human-computer interaction interface display, data acquisition display and other electronic design occasions.

Nokia 5110 mobile phone

Specifications

Working voltage: DC3.3-5.0V

Screen color: monochrome

Resolution: 84*48, Characters: 6*8 characters, 6 lines of characters can be displayed, 14 characters per line

Communication mode: serial SPI interface

LCD module: LPH7366

Application: Single chip microcomputer detection information display, human-computer interaction interface development and other electronic designs

Dimensions: 45x43x1.6mm

Pin Definition

name meaning
CLK Serial clock line
DIN Serial Data Line
DC Data/Instruction Select
CE Chip Select
RST Reset
VCC Power input (3.3V and 5V are both available)
BL Backlight control terminal
GND Ground

Module Schematic

A module schematic found on the Internet

Actual hardware connection

Nokia 5110 STM32 side
CLK PC3
DIN PC2
DC PC1
CE PC0
RST PC5
VCC 3.3V
BL 3.3V
GND GND

Module size

Program transplantation

Xiao Ha Ge has used a 51 single-chip microcomputer to drive this LCD screen before. In actual use, only five IO pins are needed to drive it.

Let's see today, if you can't find the routines for the chip you are using on the Internet, and there are only routines for other chips, how do you refer to them? Let's transplant them.

Copy driver files

Copy the driver file of the LCD screen to the HARDWARE directory under the STM32 project, and add the file to the STM32 project.

Add GPIO initialization function

voidlcd_gpio_init(void)
{
GPIO_InitTypeDefGPIO_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStructure);
}

Modify the macro definition of GPIO operation

//51单片机
//sbitLCD_RST=P0^0;
//sbitLCD_CE=P0^1;
//sbitLCD_DC=P0^2;
//sbitLCD_DIN=P0^3;
//sbitLCD_CLK=P0^4;

//STM32单片机
#defineLCD_RSTPCout(5)
#defineLCD_CEPCout(0)
#defineLCD_DCPCout(1)
#defineLCD_DINPCout(2)
#defineLCD_CLKPCout(3)

Modify the 1us delay

#defineWait1usdelay_us(1)

Function Call

//Nokia5110初始化
lcd_gpio_init();
lcd_init();
lcd_clear();//清屏幕

lcd_string(0,0,"Time:");

Compile the program, there is no error, download the program, and find that the preset content can be displayed normally on the screen, proving that the driver has been successfully transplanted.

Source code acquisition/material acquisition

Test the Demo source code.

5110测试工程 网文版本 20211212.zip (428.02 KB, downloads: 2)

Summarize

This test used Dupont cables. Although Dupont cables are convenient, once they are touched, the screen display output disappears. I can only plug and unplug them again and reset the microcontroller. I am speechless.

Also, please note that sometimes, the contact of the DuPont wire is not very good. When testing the program, you must first ensure that the contact of the DuPont wire is good. If you are not sure, you can use the buzzer mode of the multimeter to test whether the two ends of each pin are conductive.

How is it? It is quite simple, right? If you have STM32 code, you can convert it to 51 MCU code in the same way.

This post is from stm32/stm8

Latest reply

I have learned a lot... This really broadens my horizons~······   Details Published on 2022-8-7 15:25
 

6818

Posts

11

Resources
2
 

Those who are still using this display are also big names in microcontrollers. I remember using this screen 6 years ago.

This post is from stm32/stm8
 
 

5998

Posts

6

Resources
3
 

In fact, the main problem is the adaptation of C language code between various microcontrollers, high portability, this would be fun if it were assembled

This post is from stm32/stm8
 
Personal signature

在爱好的道路上不断前进,在生活的迷雾中播撒光引

 

4764

Posts

12

Resources
4
 

I've learned a lot. This is really informative.

This post is from stm32/stm8
 
 
 

68

Posts

0

Resources
5
 

I have learned a lot... This really broadens my horizons~······

This post is from stm32/stm8
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list