Application examples and source code of ordinary 51 microcontroller driving 3.5-inch TFT!

Publisher:innovator8Latest update time:2017-12-29 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

  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);

  }


Reference address:Application examples and source code of ordinary 51 microcontroller driving 3.5-inch TFT!

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

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号