📄 2-4tft_hx8347.txt
字号:
//---------------------------------------------------------
/*
2.4in_TFT.c
Program for writing to Newhaven Display 2.4" TFT
(c)2008 Curt Lagerstam - Newhaven Display International, LLC.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
//---------------------------------------------------------
#include <at89x51.h>
/**************** I/O Setting **********************/
/*
[DB7..DB0] = [P0_7..P0_0]
[DB15..DB8] = [P1_7..P1_0]
/CS = P3_4
RS = P3_5
/WR = P3_6
/RD = P3_7
/RESET = P3_0
*/
#define CS P3_4
#define RS P3_5
#define WR P3_6
#define RD P3_7
#define RESET P3_0
/***************************************************/
void data_out(unsigned char i,unsigned char j) //Data Output 16-bit Bus Interface
{
RS = 1;
RD = 1;
WR = 0;
P1 = i;
P0 = j;
WR = 1;
}
void comm_out(unsigned char j) //Command Output 8-bit Bus Interface
{
RS = 0;
RD = 1;
WR = 0;
P0 = j;
WR = 1;
}
void data_put(unsigned char i,unsigned char j)
{
CS = 0;
RS = 1;
RD = 1;
P1 = i;
P0 = j;
}
/****************************************************/
void delay(unsigned int n)
{
unsigned int i,j;
for (i=0;i<n;i++)
for (j=0;j<350;j++)
{;}
}
void delay1(unsigned int i)
{
while(i--);
}
/****************************************************/
void dispPic(unsigned char *picture)
{
int i,j;
CS = 0;
RS = 1;
for(i=0;i<320;i++)
{
for(j=0;j<240;j++)
{
P1 = *picture;
P0 = *(++picture);
WR = 0;
picture++;
WR = 1;
}
}
}
void Fulldisplay(unsigned char d1,unsigned char d2)
{
int i,j;
data_put(d1,d2);
for(i=0;i<320;i++)
{
for(j=0;j<240;j++)
{
WR = 0;
WR = 1;
}
}
}
/****************************************************
* Initialization For HX8347 *
*****************************************************/
void resetLCD()
{
RESET = 0;
delay(100);
RESET = 1;
delay(100);
}
void init_LCD()
{
CS = 0;
comm_out(0x46); data_out(0x00,0x94);
comm_out(0x47); data_out(0x00,0x41);
comm_out(0x48); data_out(0x00,0x00);
comm_out(0x49); data_out(0x00,0x33);
comm_out(0x4A); data_out(0x00,0x23);
comm_out(0x4B); data_out(0x00,0x45);
comm_out(0x4C); data_out(0x00,0x44);
comm_out(0x4D); data_out(0x00,0x77);
comm_out(0x4E); data_out(0x00,0x12);
comm_out(0x4F); data_out(0x00,0xCC);
comm_out(0x50); data_out(0x00,0x46);
comm_out(0x51); data_out(0x00,0x82);
comm_out(0x02); data_out(0x00,0x00);
comm_out(0x03); data_out(0x00,0x00);
comm_out(0x04); data_out(0x00,0x00);
comm_out(0x05); data_out(0x00,0xEF);
comm_out(0x06); data_out(0x00,0x00);
comm_out(0x07); data_out(0x00,0x00);
comm_out(0x08); data_out(0x00,0x01);
comm_out(0x09); data_out(0x00,0x3F);
comm_out(0x01); data_out(0x00,0x06);
comm_out(0x16); data_out(0x00,0xC8);
comm_out(0x23); data_out(0x00,0x95);
comm_out(0x24); data_out(0x00,0x95);
comm_out(0x25); data_out(0x00,0xFF);
comm_out(0x27); data_out(0x00,0x02);
comm_out(0x28); data_out(0x00,0x02);
comm_out(0x29); data_out(0x00,0x02);
comm_out(0x2A); data_out(0x00,0x02);
comm_out(0x2C); data_out(0x00,0x02);
comm_out(0x2D); data_out(0x00,0x02);
comm_out(0x3A); data_out(0x00,0x01);
comm_out(0x3B); data_out(0x00,0x01);
comm_out(0x3C); data_out(0x00,0xF0);
comm_out(0x3D); data_out(0x00,0x00);
delay(80);
comm_out(0x35); data_out(0x00,0x38);
comm_out(0x36); data_out(0x00,0x78);
comm_out(0x3E); data_out(0x00,0x38);
comm_out(0x40); data_out(0x00,0x0F);
comm_out(0x41); data_out(0x00,0xF0);
comm_out(0x19); data_out(0x00,0x2D);
comm_out(0x93); data_out(0x00,0x06);
delay(80);
comm_out(0x20); data_out(0x00,0x40);
comm_out(0x1D); data_out(0x00,0x07);
comm_out(0x1E); data_out(0x00,0x00);
comm_out(0x1F); data_out(0x00,0x04);
comm_out(0x44); data_out(0x00,0x3C);
comm_out(0x45); data_out(0x00,0x12);
delay(80);
comm_out(0x1C); data_out(0x00,0x04);
delay(80);
comm_out(0x43); data_out(0x00,0x80);
delay(80);
comm_out(0x1B); data_out(0x00,0x08);
delay(80);
comm_out(0x1B); data_out(0x00,0x10);
delay(80);
comm_out(0x90); data_out(0x00,0x7F);
comm_out(0x26); data_out(0x00,0x04);
delay(80);
comm_out(0x26); data_out(0x00,0x24);
comm_out(0x26); data_out(0x00,0x2C);
delay(80);
comm_out(0x26); data_out(0x00,0x3C);
comm_out(0x57); data_out(0x00,0x02);
comm_out(0x55); data_out(0x00,0x00);
comm_out(0x57); data_out(0x00,0x00);
comm_out(0x22);
}
/***************************************************
* Main Program *
***************************************************/
void main(void)
{
P0 = 0;
P1 = 0;
P2 = 0;
resetLCD();
init_LCD();
while(1)
{
Fulldisplay(0xF8,0x00);
delay(500);
Fulldisplay(0x07,0xE0);
delay(500);
Fulldisplay(0x00,0x1F);
delay(500);
Fulldisplay(0xFF,0xFF);
delay(500);
Fulldisplay(0x00,0x00);
delay(500);
dispPic(pic);
delay(100);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -