//#include <reg52.h>
//#include<fruit.h>
#include <stdio.h>
#include "Mini58Series.h"
#include "key.h"
#include "time.h"
#include "ILI9341_lcd .h"
#include "lcd_zk.h"
void delay(uint16_t count);
void LCD_WriteCommand(uint32_t c);
void LCD_WriteData(uint32_t dat);
void LCD_Write_Data(uint32_t dat16);
void DISPLAY_COLOR(uint32_t color);
void DISP_WINDOWS(void);
void ILI9341_INITIAL(void);
void Frame(void);
void DISPLAY_RGB(void);
uint16_t BACK_COLOR=BLUE;
uint16_t POINT_COLOR=WHITE; //背景色,画笔色
#define LCD_W 240
#define LCD_H 320
//========================================================
void HOLD_DISP ()
{
uint32_t i;
for(i=0;i<9000;i++);
// while(1); //!Step
}
//========================================================
//========================================================
void delay(uint16_t count) /* X10ms */
{
uint8_t jd;
while(count--)
{
for(jd=0;jd<50;jd++)
{;}
}
}
void LCD_WriteCommand(uint32_t c)
{
uint8_t ic;
TFT_A0=0;
// TFT_CS=0;
for(ic=0;ic<8;ic++)
{
if((c &0x80)==0x80)
{
TFT_SDA=1;
}
else TFT_SDA=0;
TFT_SCL=0;
TFT_SCL=1;
c <<=1;
}
// TFT_CS=1;
}
//========================================================
void LCD_WriteData(uint32_t dat)
{
uint8_t ia;
TFT_A0=1;
// TFT_CS=0;
for(ia=0;ia<8;ia++)
{
if((dat&0x80)==0x80)
{
TFT_SDA=1;
}
else TFT_SDA=0;
TFT_SCL=0;
TFT_SCL=1;
dat<<=1;
}
// TFT_CS=1;
}
//========================================================
void LCD_Write_Data(uint32_t dat16)
{
LCD_WriteData(dat16>>8);
LCD_WriteData(dat16);
}
void LCD_SetCursor(uint16_t stx,uint16_t sty)
{
LCD_WriteCommand(0x2A);
LCD_Write_Data(stx);
LCD_WriteCommand(0x2B);
LCD_Write_Data(sty);
LCD_WriteCommand(0x2C);
}
//========================================================
void DISPLAY_COLOR(uint32_t color)
{
uint16_t i,j;
DISP_WINDOWS();
for(i=0;i<240;i++)
{
for (j=0;j<320;j++)
{
LCD_Write_Data(color);
}
}
}
//========================================================
void DISP_WINDOWS(void)
{
LCD_WriteCommand(0x2A);
LCD_WriteData(0x00);
LCD_WriteData(0x00);
LCD_WriteData(0x00);
LCD_WriteData(0xEF);
LCD_WriteCommand(0x2B);
LCD_WriteData(0x00);
LCD_WriteData(0x00);
LCD_WriteData(0x01);
LCD_WriteData(0x3f);
LCD_WriteCommand(0x2C);
}
//========================================================
void ILI9341_INITIAL(void)
{
TFT_RST =1;
delay(50); //Delay 1ms
TFT_RST =0;
delay(200); //Delay 1ms
TFT_RST =1;
delay(200); //Delay 120ms
//************* Start Initial Sequence **********//
LCD_WriteCommand(0xCF);
LCD_WriteData(0x00);
LCD_WriteData(0xD9);
LCD_WriteData(0X30);
LCD_WriteCommand(0xED);
LCD_WriteData(0x64);
LCD_WriteData(0x03);
LCD_WriteData(0X12);
LCD_WriteData(0X81);
LCD_WriteCommand(0xE8);
LCD_WriteData(0x85);
LCD_WriteData(0x10);
LCD_WriteData(0x78);
LCD_WriteCommand(0xCB);
LCD_WriteData(0x39);
LCD_WriteData(0x2C);
LCD_WriteData(0x00);
LCD_WriteData(0x34);
LCD_WriteData(0x02);
LCD_WriteCommand(0xF7);
LCD_WriteData(0x20);
LCD_WriteCommand(0xEA);
LCD_WriteData(0x00);
LCD_WriteData(0x00);
LCD_WriteCommand(0xC0); //Power control
LCD_WriteData(0x21); //VRH[5:0]
LCD_WriteCommand(0xC1); //Power control
LCD_WriteData(0x12); //SAP[2:0];BT[3:0]
LCD_WriteCommand(0xC5); //VCM control
LCD_WriteData(0x32);
LCD_WriteData(0x3C);
LCD_WriteCommand(0xC7); //VCM control2
LCD_WriteData(0XC1);
LCD_WriteCommand(0x36); // Memory Access Control
LCD_WriteData(0x08); //0x08
LCD_WriteCommand(0x3A);
LCD_WriteData(0x55);
LCD_WriteCommand(0xB1);
LCD_WriteData(0x00);
LCD_WriteData(0x18);
LCD_WriteCommand(0xB6); // Display Function Control
LCD_WriteData(0x0A);
LCD_WriteData(0xA2);
LCD_WriteCommand(0xF2); // 3Gamma Function Disable
LCD_WriteData(0x00);
LCD_WriteCommand(0x26); //Gamma curve selected
LCD_WriteData(0x01);
LCD_WriteCommand(0xE0); //Set Gamma
LCD_WriteData(0x0F);
LCD_WriteData(0x20);
LCD_WriteData(0x1E);
LCD_WriteData(0x09);
LCD_WriteData(0x12);
LCD_WriteData(0x0B);
LCD_WriteData(0x50);
LCD_WriteData(0XBA);
LCD_WriteData(0x44);
LCD_WriteData(0x09);
LCD_WriteData(0x14);
LCD_WriteData(0x05);
LCD_WriteData(0x23);
LCD_WriteData(0x21);
LCD_WriteData(0x00);
LCD_WriteCommand(0XE1); //Set Gamma
LCD_WriteData(0x00);
LCD_WriteData(0x19);
LCD_WriteData(0x19);
LCD_WriteData(0x00);
LCD_WriteData(0x12);
LCD_WriteData(0x07);
LCD_WriteData(0x2D);
LCD_WriteData(0x28);
LCD_WriteData(0x3F);
LCD_WriteData(0x02);
LCD_WriteData(0x0A);
LCD_WriteData(0x08);
LCD_WriteData(0x25);
LCD_WriteData(0x2D);
LCD_WriteData(0x0F);
LCD_WriteCommand(0x11); //Exit Sleep
delay(200);
LCD_WriteCommand(0x29); //Display on
DISP_WINDOWS();
}
void LCD_DrawPoint(uint16_t x,uint16_t y,uint16_t color)
{
LCD_WriteCommand(0x2A);
LCD_WriteData(x>>8);
LCD_WriteData(x&0xFF);
LCD_WriteData(x>>8);
LCD_WriteData(x&0xFF);
LCD_WriteCommand(0x2B);
LCD_WriteData(y>>8);
LCD_WriteData(y&0xFF);
LCD_WriteData(y>>8);
LCD_WriteData(y&0xFF);
LCD_WriteCommand(0x2C);
LCD_WriteData(color>>8);
LCD_WriteData(color);
}
//画线
//x1,y1:起点坐标
//x2,y2:终点坐标
void LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
{
uint16_t t;
int xerr=0,yerr=0,delta_x,delta_y,distance;
int incx,incy,uRow,uCol;
delta_x=x2-x1; //计算坐标增量
delta_y=y2-y1;
uRow=x1;
uCol=y1;
if(delta_x>0)incx=1; //设置单步方向
else if(delta_x==0)incx=0;//垂直线
else {incx=-1;delta_x=-delta_x;}
if(delta_y>0)incy=1;
else if(delta_y==0)incy=0;//水平线
else{incy=-1;delta_y=-delta_y;}
if( delta_x>delta_y)distance=delta_x; //选取基本增量坐标轴
else distance=delta_y;
for(t=0;t<=distance+1;t++ )//画线输出
{
LCD_DrawPoint(uRow,uCol,color);//画点
xerr+=delta_x ;
yerr+=delta_y ;
if(xerr>distance)
{
xerr-=distance;
uRow+=incx;
}
if(yerr>distance)
{
yerr-=distance;
uCol+=incy;
}
}
}
////在指定位置显示一个字符
////num:要显示的字符:" "--->"~"
////mode:叠加方式(1)还是非叠加方式(0)
////void LCD_ShowChar(uint16_t x,uint16_t y,uint8_t num,uint8_t dismode)
////{
//// uint8_t temp;
//// uint8_t pos,t;
//// uint16_t colortemp=POINT_COLOR;
////
//// if(x>LCD_H-16||y>LCD_W-16)
//// return;
////
//// //设置窗口
//// num=num-' ';//得到偏移后的值
////
//// if(!dismode) //非叠加方式
//// {
//// for(pos=0;pos<16;pos++)
//// {
//// temp=asc2_1608[(uint16_t)num*16+pos]; //调用1608字体
//// for(t=0;t<8;t++)
//// {
//// if(temp&0x01)
//// colortemp = POINT_COLOR;
//// else
//// colortemp = BACK_COLOR;
//// LCD_DrawPoint(x+t,y+pos,colortemp);//画一个点
//// temp>>=1;
//// }
//// }
//// }
//// else//叠加方式
//// {
//// for(pos=0;pos<16;pos++)
//// {
//// temp=asc2_1608[(uint16_t)num*16+pos]; //调用1608字体
//// for(t=0;t<8;t++)
//// {
//// if(temp&0x01)
//// LCD_DrawPoint(x+t,y+pos,colortemp);//画一个点
////
//// temp>>=1;
//// }
//// }
//// }
////
//// //POINT_COLOR=colortemp;
////}
////void LCD_ShowAsciiChar(uint16_t x,uint16_t y,uint8_t num,u
评论0