The 3.5-inch screens popular in the market are basically built-in drivers without controllers, which makes it difficult for users to use them. Basically, many friends choose ARM7 or ARM9 with LCD controllers to develop color screens. For friends who don’t know how to develop ARM, they only use ordinary MCUs, so it is difficult to find 3.5-inch TFT modules that can be selected.
This article is written based on a 3.5-inch TFT module that is commonly used on the market. Users only need to use the TFT module as a common monochrome LCD development idea, and they can program it easily.
1. Hardware Selection
1. MCU: AT89S51
2. Development and compilation environment: Keil C51
3. 3.5-inch TFT module model: MzT35C1
2. Basic performance of TFT module:
1. Basic parameters
Module structure: built-in controller
Screen size: 3.5 inches
Screen resolution: 320*240
Screen colors: 65536 colors (16-bit true color)
Working voltage : 3.3V/5V optional
Bus architecture: Intel8080
Bus width: 8Bit
Backlight type: LED ; command control, 0-127 adjustable
Connection method: Pin header socket
Touch screen: standard configuration without touch screen; the module has touch screen chip pads and touch screen interface
2. Interface pin description
Interface Pinout | illustrate |
VCC | Module power supply input (generally 5V without special requirements) |
D0~D7 | 8-bit data bus |
CS | Chip select ( active low) |
RST | Reset (low level reset) |
A0 | Control register/data register selection (low level selects control register) |
WE | Write signal (Low level is valid) |
RD | Read signal (Low level is valid) |
GND | Grounding |
S_CS | ADS7846 chip select is reserved |
S_ SCK | ADS7846 SPI clock input is reserved |
S_SDO | ADS7846 SPI data output is reserved |
S_SDI | ADS7846 SPI data input is reserved |
S_INT | ADS7846 INT signal is reserved |
S_BUSY | ADS7846 BUSY signal is reserved |
3. Operation timing (8-bit parallel Intel 8080 bus)
The MzT35C1 module supports the Intel 8080 bus, and the maximum bus speed can reach 20 MHz (of course, whether the bus speed can reach the maximum interface speed is also related to the user's bus wiring, line length, etc.). In other words, if the control MCU speed is fast enough, it can support video display.
Note: The bus interface of the MzT35C1 module is 8-bit, which means that when operating the data of the video memory, two operations are required to complete it, first transmit the high byte and then the low byte; but for the operation of the register (writing the register address, that is, the write operation when A0 is low), only 8-bit operations are required.
3. MzT35C1 and 51 hardware interface connection diagram
This example uses GPIO to simulate bus timing. The module in the figure above is powered by 5V, and the port level of the module is 3.3V, so a 100-ohm resistor is connected in series between all 51 ports and the module . Other circuits related to MCS51 are not drawn in the figure. Please refer to other development board documents for details. The relevant pins of the MzT35C1 module in the figure shall be subject to the actual object. The figure only shows the ports with corresponding names. Please pay attention when using it for reference.
3. Low-level driver code writing method
1. Port configuration
#include "REG52.h"
#include "intrins.h" //Include this header file to directly operate the kernel registers and some defined macros
#define LCD_ CTR l_GPIO() //Undefined
#define LCD_Ctrl_Out() LCD_CS_SET();LCD_RD_SET();LCD_RW_SET();
#define LCD_Ctrl_Set(n) //Undefined
#define LCD_Ctrl_Clr(n) //Undefined
sbit LCD_CS = P2^6;
#define LCD_CS_SET() LCD_CS = 1
#define LCD_CS_CLR() LCD_CS = 0
sbit LCD_RE = P3^5;
#define LCD_RE_SET() LCD_RE = 1
#define LCD_RE_CLR() LCD_RE = 0
sbit LCD_A0 = P2^5;
#define LCD_A0_SET() LCD_A0 = 1
#define LCD_A0_CLR() LCD_A0 = 0
sbit LCD_RW = P3^6;
#define LCD_RW_SET() LCD_RW = 1
#define LCD_RW_CLR() LCD_RW = 0
sbit LCD_RD = P3^7;
#define LCD_RD_SET() LCD_RD = 1
#define LCD_RD_CLR() LCD_RD = 0
#define LCD_Data_GPIO() //51's port is bidirectional, so there is no need to specify the direction, so there is no definition
#define LCD_Data_Out() //51's port is bidirectional, so there is no need to specify the direction, so there is no definition
#define LCD_Data_In() P0 = 0xff //Port 51 needs to output 0xff before reading data
#define LCD_Data_BUS_Clr() //Undefined
#define LCD_Data_BUS_Set(n) P0 = n
#define LCD_Data_Read() P0
2. Write data and instruction operations
//==============================================
// Function: void LCD_DataWrite(unsigned int Data)
// Description: Write a word (16 bits) of display data to the display buffer RAM in the LCD
// Parameter: Data The data to be written
//==============================================
#defineLCD_DataWrite(n) LCD_A0_SET();LCD_CS_CLR();LCD_Data_BUS_Clr();LCD_Data_BUS_Set((unsigned char)(n>>8));\
LCD_RW_CLR();LCD_RW_SET();LCD_Data_BUS_Clr();LCD_Data_BUS_Set((unsigned char)n);LCD_RW_CLR();\ LCD_RW_SET();LCD_CS_SET()
//================================================ =====
// Function: void LCD_RegWrite(unsigned char Addr, unsigned int Command)
// Description: Write one byte of data to the control register in the LCD
// Parameter: Addr The address of the register to be written, the lower eight bits are valid (byte)
// Command write data
//================================================ =====
#define LCD_RegWrite(n)
LCD_A0_CLR();LCD_CS_CLR();LCD_Data_BUS_Clr();LCD_Data_BUS_Set(n);\
LCD_RW_CLR();LCD_RW_SET();LCD_CS_SET()
2. Read data operation
//==============================================
// Function: LCDBYTE LCD_DataRead(void)
// Description: Read one byte of display data from the display buffer RAM in the LCD
// Parameters: None
// Return: the read data,
// Note: Mz general version LCD driver standard sub function
//============================================
LCDBYTE LCD_DataRead(void)
{
LCDBYTE Read_Data;
LCD_Data_In();
LCD_A0_SET();
LCD_CS_CLR();
LCD_RD_CLR();
LCD_RD_SET();
LCD_RD_CLR();
LCD_RD_SET(); //The previous operation requires a complete empty read operation before data can be read
//If the user needs to read the video memory continuously, only one operation is required for the first read.
// Second empty read operation
LCD_RD_CLR();
Read_Data = LCD_Data_Read();
Read_Data = Read_Data<<8;
LCD_RD_SET();
LCD_RD_CLR();
Read_Data |= LCD_Data_Read();
LCD_RD_SET();
LCD_CS_SET();
LCD_Data_Out();
return Read_Data;
}
3. Initialize TFT operation
void LCD_Init(void)
{
// FLASH *Init_String;
//Initialization of the port used by the LCD driver
LCD_PortInit();
//According to the LCD display configuration, set the LCD data address pointer to automatically increase the feature
//end
LCD_RE_CLR();
TimeDelay(5);
LCD_RE_SET();
LCD_RegWrite(0x03);
LCD_DataWrite((1<<7)| (0x60<<0)); //Set backlight control to enable and backlight brightness level to 60 (0~127)
LCD_RegWrite(0x04); //Write system register
// LCD_DataWrite((0<<7)| //Current display page
// (0<<6) | //Current read-write page settings
// (1<<0)); //Display switch
LCD_DataWrite(MzT35_Ctrl_Reg);
/* Init_String = Initial_Tab;
while(Init_String!=0xffff)
{
LCD_RegWrite(0x05);LCD_DataWrite(*Init_String++);
LCD_RegWrite(0x06);LCD_DataWrite(*Init_String++);
}*/
LCD_Fill(LCD_INITIAL_COLOR);
}
Previous article:Using high-efficiency oscillators to implement high-speed serial communication clock configuration for microcontrollers
Next article:One button can realize the delay control of three LEDs
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- MSP430F5529 Getting Started with Small Examples
- Qorvo's point-of-care diagnostic platform seems pretty good.
- Today's live broadcast: New requirements for connectors in 5G multi-scenario terminal applications and Molex's 5G connection solutions
- What will the elevators of the future look like?
- Award-winning live broadcast: Internet of Everything - Shijian Company joins hands with Microchip experts to discuss IoT solutions
- MS8211 to lithium battery
- In order to kill mosquitoes, the doctor DIYed a laser gun using Raspberry Pi!
- Thoughts on the development of single-chip microcomputers
- FPGA_100 Days Journey_Breathing Light
- The Chinese community is down?