MCU---HLK-W801 parallel port driver ST7789

Publisher:码上奇迹Latest update time:2022-07-29 Source: csdnKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Purpose

I bought this parallel port screen to make a NES emulator game console. The SPI screen I used before was quite time-consuming to display the game screen because it was serial data. So I planned to try the parallel port screen and understand the driving method of the parallel port 8080.


Parallel Port Protocol

The 8080 timing is also called the Intel bus, which is usually found on LCDs in MCU (MPU) mode.

There are four Inter bus control lines:


RD: Write Enable

WR: Read Enable

DC(RS): - Data/Command

CS: Chip Select

Then there are several data lines, such as 8 or 16.

Write timing diagram

insert image description here

Reading Timing Diagram

It is important to note that the reading and writing of data are both valid on the rising edge of RD or WR. So we can write data first and then create a rising edge, or pull it low first and then pull it high after writing data. However, from the figure, the former is recommended.


ST7789 Pin Definition

There are several ways to use ST7789. Today we will only talk about the 16-bit parallel port driver.

Hardware Hookup


#define P_LEDA_PORTGPIOA

#define P_LEDA_PINGPIO_PIN_5//Backlight

#define P_RD_PORTGPIOA

#define P_RD_PINGPIO_PIN_9 //RD

#define P_WR_PORTGPIOA

#define P_WR_PINGPIO_PIN_10 //WR

#define P_CD_PORTGPIOA

#define P_CD_PINGPIO_PIN_11 //RS 0 is command 1: data


#define P_CS_PORTGPIOA

#define P_CS_PINGPIO_PIN_12 //cs 0 is selected


#define P_RESET_PORTGPIOA

#define P_RESET_PINGPIO_PIN_14 //REST


#define P_DATA_PORTGPIOB

#define P_DATA_PIN0xFFFF


in,

Backlight, some screens are called BLK, we can directly connect to the high level.

CS, we can directly connect it to low level, which is selected by default.

RD, we can directly pull the level high without the read function.

CD, some screens are called RS.


We use GPIOB 0~15 for data lines. Be careful here, or the screen will be distorted if you connect them wrong.


Then define the following control macro


#define P_CD_LOWP_CD_PORT->DATA &= ~P_CD_PIN

#define P_CD_HIGHP_CD_PORT->DATA |= P_CD_PIN


#define P_RESET_LOWP_RESET_PORT->DATA &= ~P_RESET_PIN

#define P_RESET_HIGHP_RESET_PORT->DATA |= P_RESET_PIN


#define P_WR_LOWP_WR_PORT->DATA &= ~P_WR_PIN

#define P_WR_HIGHP_WR_PORT->DATA |= P_WR_PIN


Here is how w801 is written, with the pins set high and low.


ST7789 core functions

The two most basic control functions of LCD display are writing registers and writing data.


void P_WriteReg(uint16_t reg)

{

P_CD_LOW;

WRITE_REG(P_DATA_PORT->DATA,reg);

P_WR_LOW;

P_WR_HIGH;

P_CD_HIGH;

}


void P_WriteData(uint16_t data)

{

WRITE_REG(P_DATA_PORT->DATA,data);

P_WR_LOW;

P_WR_HIGH;

}


Here we focus the modification of the control lines entirely on the write registers, because the write registers are used less frequently, so when writing data, the efficiency is higher.


Then the initialization function


void LCD_Init(void)

{

LCD_Reset_On();

HAL_Delay(120);

LCD_Reset_Off();


HAL_Delay(120);

LCD_WriteReg(0x3A);   //65k mode

LCD_WriteData8(0x05);

LCD_WriteReg(0xC5); //VCOM

LCD_WriteData8(0x1A);

LCD_WriteReg(0x36);//Screen display direction settings

LCD_WriteData8(0x00);

//-------------ST7789V Frame rate setting-----------//

LCD_WriteReg(0xb2);

LCD_WriteData8(0x05);

LCD_WriteData8(0x05);

LCD_WriteData8(0x00);

LCD_WriteData8(0x33);

LCD_WriteData8(0x33);


LCD_WriteReg(0xb7);

LCD_WriteData8(0x35);

//--------------ST7789V Power setting---------------//

LCD_WriteReg(0xBB);//VCOM

LCD_WriteData8(0x3F);


LCD_WriteReg(0xC0); //Power control

LCD_WriteData8(0x2c);


LCD_WriteReg(0xC2);

LCD_WriteData8(0x01);


LCD_WriteReg(0xC3);

LCD_WriteData8(0x0F); //0Dgvd


LCD_WriteReg(0xC4);

LCD_WriteData8(0x20);


LCD_WriteReg(0xC6);

LCD_WriteData8(0X11); //0x0F


LCD_WriteReg(0xd0);

LCD_WriteData8(0xa4);

LCD_WriteData8(0xa1);


LCD_WriteReg(0xE8);

LCD_WriteData8(0x03);


LCD_WriteReg(0xE9);

LCD_WriteData8(0x09);

LCD_WriteData8(0x09);

LCD_WriteData8(0x08);

//---------------ST7789V gamma setting-------------//

LCD_WriteReg(0xE0); //Set Gamma

LCD_WriteData8(0xD0);

LCD_WriteData8(0x05);

LCD_WriteData8(0x09);

LCD_WriteData8(0x09);

LCD_WriteData8(0x08);

LCD_WriteData8(0x14);

LCD_WriteData8(0x28);

LCD_WriteData8(0x33);

LCD_WriteData8(0x3F);

LCD_WriteData8(0x07);

LCD_WriteData8(0x13);

LCD_WriteData8(0x14);

LCD_WriteData8(0x28);

LCD_WriteData8(0x30);


LCD_WriteReg(0XE1); //Set Gamma

LCD_WriteData8(0xD0);

LCD_WriteData8(0x05);

LCD_WriteData8(0x09);

LCD_WriteData8(0x09);

LCD_WriteData8(0x08);

LCD_WriteData8(0x03);

LCD_WriteData8(0x24);

LCD_WriteData8(0x32);

LCD_WriteData8(0x32);

LCD_WriteData8(0x3B);

LCD_WriteData8(0x14);

LCD_WriteData8(0x13);

LCD_WriteData8(0x28);

LCD_WriteData8(0x2F);


LCD_WriteReg(0x11);

HAL_Delay(120);

LCD_Clear(0x0000);/*Manually clear the screen before displaying to prevent screen distortion*/

LCD_WriteReg(0x29);//Turn on display 


}


The screen orientation can be modified

LCD_WriteReg(0x36); //Screen display direction setting

LCD_WriteData8(0x00);


0x00 is the normal vertical screen

0xA0 is horizontal screen to the left

There are two other types, 0x60 and 0xC0, which are probably inverted and horizontal to the right. If you are interested, you can try them.


Error-prone points

The most error-prone part of the 16-bit driver is the coordinate setting. I thought the coordinates were 16 bits, so I could just write four coordinates. This is exactly wrong. It needs to be compatible with 8 bits, and each 16 bits must be written twice. Otherwise, there will be a screen distortion problem.

I spent a day to fix this bug.


void LCD_Address_Set(uint16_t xs, uint16_t ys, uint16_t xe, uint16_t ye)

{

LCD_WriteReg(0x2a);

LCD_WriteData(xs>>8);

LCD_WriteData(xs&0xff);

LCD_WriteData(xe>>8);

LCD_WriteData(xe&0xff);

LCD_WriteReg(0x2b);

LCD_WriteData(ys>>8);

LCD_WriteData(ys&0xff);

LCD_WriteData(ye>>8);

LCD_WriteData(ye&0xff);

LCD_WriteReg(0x2c);


}

Keywords:MCU Reference address:MCU---HLK-W801 parallel port driver ST7789

Previous article:MCU---HLK-W801 drives touch screen
Next article:MCU---ESP8266Wifi SmartConfig one-click configuration (Part 2)

Recommended ReadingLatest update time:2024-11-24 19:07

Single chip microcomputer speed measurement and 1602 display program and circuit
STC12C single chip microcomputer controls light sensor to measure speed PWM to control DC motor Partial code preview: #include "mytype.h" //Includes the header file #define DATA P2 //Define P0 as the data port //Define the key I/O port sbit key0=P0^6; //Forward, reverse and stop mode switching button sbit key1=
[Microcontroller]
51 MCU programmer with protection function
This simple programmer has an automatic power-off protection function. When the MCU is inserted in reverse, the protection circuit will immediately cut off the power supply (the power indicator light will flash), which not only protects the MCU, the programmer, but also protects the computer USB port to avoid unnece
[Microcontroller]
51 MCU programmer with protection function
Analysis of the Problems of Implementing RTOS on MSP430 Microcontroller Chip Using uC/OS-II
As an important application of embedded information products, the use and design of single-chip microcomputers are facing new challenges. On the one hand, people have higher and higher requirements for embedded products, and stable, reliable, feature-rich, high-quality and low-cost information products will become p
[Microcontroller]
Analysis of the Problems of Implementing RTOS on MSP430 Microcontroller Chip Using uC/OS-II
Learn these things about microcontrollers
First of all, every microcontroller programming software has a software simulation function. We can learn some functions of the microcontroller through this software simulation function. For example, the software simulation function can be used to realize the high and low level output of the microcontroller port, and
[Microcontroller]
Single chip microcomputer experiment - 4X4 matrix keyboard recognition technology
Use the parallel port P1 of AT89S51 to connect a 4×4 matrix keyboard, with P3.0-P3.3 as input lines and P3.4-P3.7 as output lines; the digital keys "0-9" are displayed on the digital tube, and the other keys display 0.   Principle analysis: Each key of the 4X4 matrix keyboard has its row value and column value. When t
[Microcontroller]
Single chip microcomputer experiment - 4X4 matrix keyboard recognition technology
Steps to burn the microcontroller
  1. Treat the MCU as a ROM chip, which is the case for early MCUs. When programming the MCU on a general programming, it is the same as writing a program in a ROM such as 28C256. It's just that different MCUs use different ports and programming timings. Treat the MCU as a ROM chip , which is the case for early MCUs.
[Microcontroller]
The two major series of microcontrollers are PK_MSP430 and AVR
  There are many types of microcontrollers, and many manufacturers have launched their own MCUs. Among the many brands of microcontrollers, I prefer the MSP430 and AVR series. The following is a PK analysis based on their respective characteristics and several aspects.   Since we are doing a PK, just like a sports c
[Microcontroller]
The two major series of microcontrollers are PK_MSP430 and AVR
A speed measurement system based on single chip microcomputer
1. Introduction In a certain type of measurement and control system developed by our laboratory, we encountered a requirement for measuring the initial velocity of a projectile-shaped object. The velocity range is 0-150m/s. The velocity measurement module is required to be low-cost and highly reliable, and the veloci
[Test Measurement]
A speed measurement system based on single chip microcomputer
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号