📄 1-8tft_16-bit.txt
字号:
//---------------------------------------------------------
/*
TFT.c
Program for writing to Newhaven Display 1.8" 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>
#include "picture.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_0
#define RS P3_4
#define WR P3_5
#define RD P3_6
#define RESET P3_7
/***************************************************/
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;
P1 = 0;
P0 = j;
WR = 1;
}
void data_put(unsigned char i,unsigned char j) //just put the data on the bus
{
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 *lcd_string)
{
int i,j;
CS = 0;
RS = 1;
for(i=0;i<160;i++)
{
for(j=0;j<128;j++)
{
P1 = *lcd_string;
P0 = *(++lcd_string);
WR = 0;
lcd_string++;
WR = 1;
}
}
}
void Fulldisplay(unsigned char d1,unsigned char d2)
{
int i,j;
comm_out(0x44); data_out(0x80,0x00);
comm_out(0x45); data_out(0xA0,0x00);
comm_out(0x21); data_out(0x00,0x80);
comm_out(0x22);
data_put(d1,d2);
for(i=0;i<160;i++)
{
for(j=0;j<128;j++)
{
WR = 0;
WR = 1;
}
}
}
/****************************************************
* Initialization For S6D0144 *
*****************************************************/
void resetLCD()
{
RESET = 0;
delay(100);
RESET = 1;
delay(100);
}
void init_LCD()
{
CS = 0;
comm_out(0x00); data_out(0x00,0x01);
delay(300);
comm_out(0xB4); data_out(0x00,0x00);
comm_out(0xB3); data_out(0x00,0x00);
comm_out(0x07); data_out(0x00,0x00);
comm_out(0x12); data_out(0x00,0xB3);
comm_out(0x13); data_out(0x08,0x08);
comm_out(0x14); data_out(0x7D,0xE5);
comm_out(0x10); data_out(0x1A,0x6C);
delay(900);
comm_out(0x13); data_out(0x08,0x1E);
delay(300);
comm_out(0x01); data_out(0x01,0x14);
comm_out(0x02); data_out(0x01,0x00);
comm_out(0x03); data_out(0x00,0x20);
comm_out(0x08); data_out(0x02,0x02);
comm_out(0x0B); data_out(0x00,0x04);
comm_out(0x0C); data_out(0x00,0x01);
comm_out(0x30); data_out(0x03,0x03);
comm_out(0x31); data_out(0x03,0x03);
comm_out(0x32); data_out(0x03,0x03);
comm_out(0x33); data_out(0x00,0x00);
comm_out(0x34); data_out(0x04,0x04);
comm_out(0x35); data_out(0x04,0x04);
comm_out(0x36); data_out(0x04,0x04);
comm_out(0x37); data_out(0x00,0x00);
comm_out(0x38); data_out(0x07,0x07);
comm_out(0x40); data_out(0x00,0x00);
comm_out(0x42); data_out(0x9F,0x00);
comm_out(0x43); data_out(0x00,0x00);
comm_out(0x44); data_out(0x7F,0x00);
comm_out(0x45); data_out(0x9F,0x00);
comm_out(0x61); data_out(0x00,0x18);
comm_out(0x69); data_out(0x00,0x00);
comm_out(0x70); data_out(0x00,0x00);
comm_out(0x71); data_out(0x00,0x00);
delay(500);
comm_out(0x07); data_out(0x00,0x05);
comm_out(0x07); data_out(0x00,0x21);
comm_out(0x07); data_out(0x00,0x23);
delay(500);
comm_out(0x07); data_out(0x00,0x37);
comm_out(0x21); data_out(0x00,0x7F);
comm_out(0x22); data_out(0x00,0x00);
}
/***************************************************
* Main Program *
***************************************************/
void main(void)
{
P0 = 0;
P1 = 0;
P2 = 0;
resetLCD();
while(1)
{
init_LCD();
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(picture);
delay(500);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -