TFT line drawing program

Publisher:WanderlustGlowLatest update time:2015-10-16 Source: eefocusKeywords:TFT Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
When I first came into contact with the TFT video screen, I was indeed afraid of it, but Han Shi insisted on learning it; in the end, when I used it to mark points, all problems were solved TFT line drawing program! ! Because if you know how to mark points, you can also draw lines, and if you know how to draw lines, you can also draw your own coordinate system! ! TFT line drawing programIt’s the same as before, the more advanced the peripheral equipment is, it will have its own set of drivers when it leaves the factory! As long as you master it, you can operate it without having to write a program! !

   So in a sense, it is easier to play with TFT than with four-digit digital tubes! ! It is true! You can only experience the fun of it by doing it yourself! 

#include
#define   uint unsigned int
#define uchar unsigned char
#define   TYPE_LCD_DATA   1
#define   TYPE_LCD_COMMAND  0
#define   LCD_SIZE_X   128
#define   LCD_SIZE_Y   160
#define   DATA    P0

sbit LCD_RST   = P2^7;     //RST pin definition
sbit LCD_RD    = P3^2;   //RD   pin definition
sbit LCD_WR    = P3^3;   //WR   pin definition
sbit LCD_RS    = P2^5;   //RS   pin definition
sbit LCD_CS    = P2^6;   //CS   pin definition

// TFT line drawing programIf you want to play with any peripheral device, you must first understand the function of its pins, so that you can transplant the code at will and operate it according to your own requirements! !

//Most of the following functions are TFT driving functions, and they all have their own functional annotations. You can use them after understanding the functions! !
uint colors[]=
{
  0xf800,0x07e0,0x001f,0xffe0,0x0000,0x07ff,0xf81f,0xffff
};


void delay_ms(uint ms)
{
  unsigned char k;

  while (ms--)
  {
    for (k = 0; k < 228; k++)
      ;
  }
}


void LCD_Write(uchar type, uint value) 
{
 LCD_CS = 0;
 LCD_RS   = type;       // 0: command     1: data
 
 LCD_WR   = 0;
 DATA   = (uchar)value;;
 LCD_WR   = 1;
 LCD_CS = 1;
}

 



void LCD_Wirte_Data16(uint value)     // color data
{
 LCD_CS = 0;
    LCD_RS   = 1;
 LCD_WR   = 0;
 DATA   = (uchar)value;
 LCD_WR   = 1;
 LCD_WR   = 0;
 DATA   = (uchar)(value>>8)  ;
 LCD_WR   = 1;
 LCD_CS = 1;
}


void Reg_Write(uint reg,uint value)
{
   LCD_Write(TYPE_LCD_COMMAND,reg);
   LCD_Write(TYPE_LCD_DATA,value);
}



void LCD_SetRamAddr(uint xStart, uint xEnd, uint yStart, uint yEnd)
{
    Reg_Write(0x09, xStart);
    Reg_Write(0x10, yStart);
    Reg_Write(0x11, xEnd);
    Reg_Write(0x12, yEnd);
    Reg_Write(0x18, xStart) ;
 Reg_Write(0x19, yStart);
    LCD_Write(TYPE_LCD_COMMAND,0x22);   // 0x22
}



void LCD_init(void)

 uint num;
 Reg_Write(0x0001,0x0002);   //MODE_SEL1
 Reg_Write(0x0002,0x0012);    //MODE_SEL2
 Reg_Write(0x0003,0x0000);    //MODE_SEL3
 Reg_Write(0x0004,0x0010);  //MODE_SEL3
 LCD_SetRamAddr (0,127, 0,159);
 for(num=20480;num>0;num--)
    LCD_Wirte_Data16(0xffff);
  
 Reg_Write(0x0005,0x0008);    //VCO_MODE 
 Reg_Write(0x0007,0x007f);  //VCOMHT_CTRL
 Reg_Write(0x0008,0x0017 );    //VCOMLT_CTRL      
 Reg_Write(0x0009,0x0000);    //write SRAM window start X point
 Reg_Write(0x0010,0x0000);    //write SRAM window start y point Reg_Write
 (0x0011,0x0083);    //write SRAM window end
 0x0012,0x009f);    //write SRAM window end y point
 Reg_Write(0x0017,0x0000);    //SRAM contrl
 Reg_Write(0x0018,0x0000);    //SRAM x position
 Reg_Write(0x0019,0x0000);    //SRAM y position
 Reg_Write( 0x0006,0x00c5);    //DAC_OP_CTRL2
 delay_ms(10); //Delay

}



void   LCD_clear(uchar n)
{
   uint num;
  
   LCD_SetRamAddr(0,127, 0,159);

   for(num=20480;num>0;num--)           //160*128=20480
   {
     LCD_Wirte_Data16(colors[n]);
   }
}
//====================================================================
//Set the current display coordinates
//Entry parameters: x, y are the current display coordinates.
//Exit parameters: None
//Description: This function is actually a special case of LCD_setwindow function. The display window is the smallest, only one pixel.
void LCD_setxy(unsigned char x,unsigned int y)
{
 LCD_SetRamAddr(x,y,x,y); 
}

void GUI_Point(uchar x, uint y, uint n)

 LCD_setxy(x,y);
  LCD_Wirte_Data16(colors[n]);
}
void main()
{
  uint num;
  P2 = 0xff;
     P0 = 0xff;
 LCD_init();
  while(1)
  {    
    LCD_SetRamAddr(50,100, 50,50);
       for(num=2500;num>0;num--)           //160*128=20480
       {
       LCD_Wirte_Data16(colors[2]);//For example, this function only needs to know that it is used to set the color of the point, and its parameter is colors[]
       }
  }
}

Keywords:TFT Reference address:TFT line drawing program

Previous article:TFT display image driving function
Next article:Timing application methods and techniques

Recommended ReadingLatest update time:2024-11-16 14:44

51 MCU Proteus simulation 320x240TFT color screen
The following is the assembly source code of Proteus simulation 320x240TFT color screen: ;Proteus7.5SP3, LCD driver: ---, LCD: 320x240 65K color, 8bit interface ;RGB(565) order (this simulated TFT sends low bits first and then high bits). ;Modified by HeFanghua, 2012-4-20 ;Function: Read the BIN data file in AT25F
[Microcontroller]
51 MCU Proteus simulation 320x240TFT color screen
Leybold Hi-Tech: Mass production and supply of TFT-Array driver backplane for black and white electronic paper displays
On January 10, Laibao Hi-Tech stated on the investor interaction platform that the company has mass-produced and supplied dual-screen vehicle touch screens and a small amount of triple-screen vehicle touch screens to Tier 1 automobile assembly customers. The final applications include cars of most well-known domestic
[Mobile phone portable]
Leybold Hi-Tech: Mass production and supply of TFT-Array driver backplane for black and white electronic paper displays
基于Cortex-M3内核的TFT触摸屏在环境监控系统中的应用
0 引言 触摸屏是一种新型的电子输入设备,是目前最简单、方便、自然的一种人机交互方式,它赋予了多媒体以崭新的面貌,是极富吸引力的全新多媒体交互设备。将ARMCortex-M3内核和TFT触摸屏结合在一起,以环境监控系统为应用,对ARM公司的Cortex-M3内核进行了分析,并研究了Cortex-M3内核驱动TFT液晶屏幕的可行性。 1 系统工作原理 无线环境监控系统总体的设计框图如图1所示。以基于第二代Cortex-M3内核的LPC1758为核心,以TFT触摸屏为显示和控制单元,以2.4 GHz无线模块为通信单元,合理移植μCOS-II系统,对环境参数进行监测和控制。 2 硬件电路设计与实现 2.1 电源方案 硬件电路降压
[Microcontroller]
基于Cortex-M3内核的TFT触摸屏在环境监控系统中的应用
Comparison between TFT LCD and CRT monitors
There are significant differences between LCD monitors and CRT monitors in terms of circuit composition, working principles, performance parameters, etc. The following is a brief analysis. 1. Differences in circuit composition The circuit block diagram of LCD is shown in Figure 1, which is mainly composed
[Power Management]
Comparison between TFT LCD and CRT monitors
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号