標(biāo)題:
51單片機(jī)驅(qū)動(dòng)ILI9325TP TFT2.4彩屏顯示漢字程序(有詳細(xì)注釋)
[打印本頁]
作者:
51hei學(xué)習(xí)技術(shù)中
時(shí)間:
2017-3-9 02:07
標(biāo)題:
51單片機(jī)驅(qū)動(dòng)ILI9325TP TFT2.4彩屏顯示漢字程序(有詳細(xì)注釋)
分享一個(gè)用8051單片機(jī)驅(qū)動(dòng)ILI9325TP芯片的 TFT2.4寸彩屏讓他顯示漢字的程序(帶有詳細(xì)注釋)
0.png
(75.47 KB, 下載次數(shù): 139)
下載附件
2017-3-9 01:58 上傳
完整代碼下載:
tft基本的顯示程序帶注釋.rar
(66.28 KB, 下載次數(shù): 260)
2017-3-9 02:06 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
LCD點(diǎn)陣提取工具zimo221.rar
(256.32 KB, 下載次數(shù): 108)
2017-3-9 02:06 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
部分源碼預(yù)覽:
#include"reg52.h"
#define WINDOW_XADDR_START 0x0050 // Horizontal Start Address Set
#define WINDOW_XADDR_END 0x0051 // Horizontal End Address Set
#define WINDOW_YADDR_START 0x0052 // Vertical Start Address Set
#define WINDOW_YADDR_END 0x0053 // Vertical End Address Set
#define GRAM_XADDR 0x0020 // GRAM Horizontal Address Set
#define GRAM_YADDR 0x0021 // GRAM Vertical Address Set
#define GRAMWR 0x0022 // memory write
/* LCD color */
#define White 0xFFFF
#define Black 0x0000
#define Blue 0x001F
#define Blue2 0x051F
#define Red 0xF800
#define Magenta 0xF81F
#define Green 0x07E0
#define Cyan 0x7FFF
#define Yellow 0xFFE0
sbit CS=P2^7; //片選 //要改
sbit RES=P2^5; //復(fù)位
sbit RS=P2^4; //數(shù)據(jù)/命令選擇
sbit RW=P2^3;
//數(shù)據(jù)口使用P1 //要改
//====================================================//
void main (void);
void ILI9325_Initial(void);
void show_colour_bar (void);
void Init_data(unsigned char x, unsigned int y);
void Write_Cmd(unsigned char DH,unsigned char DL);
void Write_Data(unsigned char DH,unsigned char DL);
void delayms(unsigned int tt);
void show_photo(void);
void Show_RGB (unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1,unsigned int Color);
unsigned char code pic[];
void Write_Data_U16(unsigned int y);
static void LCD_SetPos(unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1);
void ClearScreen(unsigned int bColor);
void LCD_PutChar8x16(unsigned short x, unsigned short y, char c, unsigned int fColor, unsigned int bColor);
void LCD_PutChar(unsigned short x, unsigned short y, char c, unsigned int fColor, unsigned int bColor);
void LCD_PutString(unsigned short x, unsigned short y, char *s, unsigned int fColor, unsigned int bColor);
void LCD_PutChar8x8(unsigned short x, unsigned short y, char c, unsigned int fColor, unsigned int bColor);
void PutGB1616(unsigned short x, unsigned short y, unsigned char c[2], unsigned int fColor,unsigned int bColor);
void PutGB3232(unsigned short x, unsigned short y, unsigned char c[2], unsigned int fColor,unsigned int bColor);
//================================================//
void main(void)
{
CS=1;
delayms(25);
RES=0;
delayms(150);
RES=1;
delayms(25);
ILI9325_Initial();
while(1)
{
ClearScreen(0x0);
//show_colour_bar();
LCD_PutString(2,40,"http://shop58797699.taobao.com/",Red,Blue); ///前景顏色和背景顏色,可以直接預(yù)定義,也可以直接填入16進(jìn)制數(shù)字
LCD_PutString(40,60,"I LOVE MY JOB ",Blue2,Yellow);
LCD_PutString(40,80,"碩耀電子科技有限公司",Magenta,Green);
LCD_PutString(40,100,"專業(yè)技術(shù)支持論壇",0x07e0,0xf800);
LCD_PutString(40,120,"專業(yè)開發(fā)板工控板",0xF800,Yellow);
LCD_PutString(40,140,"1234567890",0xF800,Yellow);
LCD_PutString(20,160,"abcdefghijklmnopqistuvwxyz",0xF800,Yellow);
LCD_PutString(20,180,"`,./<>';:[]{}\|?)(-=+*&^%$",0xF800,Yellow);
PutGB3232(20,200,"我",Blue,Yellow); //寫入32x32漢字
PutGB3232(60,200,"愛",Blue,Red);
PutGB3232(100,200,"單",Blue,Magenta);
PutGB3232(140,200,"片",Blue,Green);
PutGB3232(180,200,"機(jī)",Blue,Cyan);
PutGB3232(20,240,"碩",Blue,0X00);
PutGB3232(60,240,"耀",Blue,0X00);
PutGB3232(100,240,"電",Blue,0X00);
PutGB3232(140,240,"子",Blue,0X00);
PutGB3232(180,240,"科",Blue,0X00);
PutGB3232(20,280,"技",Blue,0X00);
PutGB3232(60,280,"歡",Blue,0X00);
PutGB3232(100,280,"迎",Blue,0X00);
PutGB3232(140,280,"你",Blue,0X00);
PutGB3232(180,280,"!",Blue,0X00);
// show_photo();
while(1);
}
}
void ClearScreen(unsigned int bColor) //清屏,可以設(shè)置顏色
{
unsigned int i,j;
LCD_SetPos(0,240,0,320);//320x240
for (i=0;i<325;i++) //按地址來說只能是從上往下刷屏,循環(huán)只是為了計(jì)數(shù)
{
for (j=0;j<240;j++)
Write_Data_U16(bColor);
}
}
/////////////////////////////////////////////////////////////
#include "8X16.h"
void LCD_PutChar8x16(unsigned short x, unsigned short y, char c, unsigned int fColor, unsigned int bColor)
{
unsigned int i,j;
LCD_SetPos(x,x+8-1,y,y+16-1);
for(i=0; i<16;i++) {
unsigned char m=Font8x16[c*16+i]; //數(shù)組中一個(gè)字符占了橫8豎16,相當(dāng)于先取行再取排,m是每一組數(shù)的第i+1行字符8位
for(j=0;j<8;j++) {
if((m&0x80)==0x80) { //每次m左移一位,即每次取第一個(gè)數(shù)判斷是0還是1
Write_Data_U16(fColor);
}
else {
Write_Data_U16(bColor); //兩種顏色,字色和底色
}
m<<=1;
}
}
}
void LCD_PutChar(unsigned short x, unsigned short y, char c, unsigned int fColor, unsigned int bColor) {
LCD_PutChar8x16( x, y, c, fColor, bColor );
}
#include "GB1616.h" //16*16漢字字模
void PutGB1616(unsigned short x, unsigned short y, unsigned char c[2], unsigned int fColor,unsigned int bColor){
unsigned int i,j,k;
LCD_SetPos(x, x+16-1,y, y+16-1);
for (k=0;k<64;k++) { //64標(biāo)示自建漢字庫中的個(gè)數(shù),循環(huán)查詢內(nèi)碼 ?應(yīng)該是25個(gè)吧。。
if ((codeGB_16[k].Index[0]==c[0])&&(codeGB_16[k].Index[1]==c[1])){
for(i=0;i<32;i++) {
unsigned short m=codeGB_16[k].Msk[i];
for(j=0;j<8;j++) {
if((m&0x80)==0x80) {
Write_Data_U16(fColor);
}
else {
Write_Data_U16(bColor);
}
m<<=1;
}
}
}
}
}
#include "GB3232.h" //32*32漢字字模
void PutGB3232(unsigned short x, unsigned short y, unsigned char c[2], unsigned int fColor,unsigned int bColor){
unsigned int i,j,k;
LCD_SetPos(x, x+32-1,y, y+32-1);
for (k=0;k<15;k++) { //15標(biāo)示自建漢字庫中的個(gè)數(shù),循環(huán)查詢內(nèi)碼 這個(gè)15倒是對的。。
if ((codeGB_32[k].Index[0]==c[0])&&(codeGB_32[k].Index[1]==c[1])){
for(i=0;i<128;i++) {
unsigned short m=codeGB_32[k].Msk[i];
for(j=0;j<8;j++) {
if((m&0x80)==0x80) {
Write_Data_U16(fColor);
}
else {
Write_Data_U16(bColor);
}
m<<=1;
}
}
}
}
}
void LCD_PutString(unsigned short x, unsigned short y, unsigned char *s, unsigned int fColor, unsigned int bColor) {
unsigned char l=0;
while(*s) {
if( *s < 0x80)
{
LCD_PutChar(x+l*8,y,*s,fColor,bColor); //橫著寫,縱坐標(biāo)不變,間距8
s++;l++;
}
else
{
PutGB1616(x+l*8,y,(unsigned char*)s,fColor,bColor); //間距16
s+=2;l+=2;
}
}
}
//==================== 顯示R G B 顔色 ====================//
void Show_RGB (unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1,unsigned int Color)
{
unsigned int i,j;
LCD_SetPos(x0,x1,y0,y1);
for (i=y0;i<=y1;i++)
{
for (j=x0;j<=x1;j++)
Write_Data_U16(Color); //寫像素點(diǎn)
}
}
//====================== 顯示彩條 ======================//
void show_colour_bar (void) //和上一個(gè)函數(shù)沒有本質(zhì)區(qū)別,只是規(guī)定了寬度
{
int V,H;
LCD_SetPos(0,240,0,320);//320x240
for(H=0;H<240;H++)
{
for(V=0;V<40;V++)
Write_Data(0xf8,0x00); //干嘛非要把16位數(shù)用兩個(gè)8位拼起來,為什么不直接write_data_U16那個(gè)函數(shù)呢?真蛋疼。。
}
for(H=0;H<240;H++)
{
for(V=40;V<80;V++)
Write_Data(0x07,0xe0);
}
for(H=0;H<240;H++)
{
for(V=80;V<120;V++)
Write_Data(0x00,0x1f);
}
for(H=0;H<240;H++)
{
for(V=120;V<160;V++)
Write_Data(0xff,0xe0);
}
for(H=0;H<240;H++)
{
for(V=160;V<200;V++)
Write_Data(0xf8,0x1f);
}
for(H=0;H<240;H++)
{
for(V=200;V<240;V++)
Write_Data(0x07,0xff);
}
for(H=0;H<240;H++)
{
for(V=240;V<280;V++)
Write_Data(0xff,0xff);
}
for(H=0;H<240;H++)
{
for(V=280;V<320;V++)
Write_Data(0x00,0x00);
}
}
void show_photo(void)
{
unsigned char j;
unsigned int i;
unsigned long s=0;
LCD_SetPos(0,240,0,320);//320x240
for (i=0;i<75;i++)
{
for (j=0;j<240;j++)
Write_Data(0xff,0xff);
}
for (i=0;i<170;i++)
{
for (j=0;j<55;j++)
Write_Data(0xff,0xff);
for (j=0;j<130;j++)
Write_Data(pic[s++],pic[s++]);
for (j=0;j<55;j++)
Write_Data(0xff,0xff);
}
for (i=0;i<75;i++)
{
for (j=0;j<240;j++)
Write_Data(0xff,0xff);
}
}
//=======================================================//
void Init_data (unsigned char x,unsigned int y)
{
unsigned char m,n;
m=y>>8;
n=y;
Write_Cmd(0x00,x);
Write_Data(m,n);
}
void Write_Data_U16(unsigned int y)
{
unsigned char m,n;
m=y>>8;
n=y;
Write_Data(m,n);
}
//====================== 寫命令 ==========================//
void Write_Cmd(unsigned char DH,unsigned char DL)
{
CS=0;
RS=0;
P1=DH;
RW=0;
RW=1;
P1=DL;
RW=0;
RW=1;
CS=1;
}
//===================== 寫數(shù)據(jù) ===========================//
void Write_Data(unsigned char DH,unsigned char DL)
{
CS=0;
RS=1;
P1=DH;
RW=0;
RW=1;
P1=DL;
RW=0;
RW=1;
CS=1;
}
//=======================================================
void delayms(unsigned int count)
{
int i,j;
for(i=0;i<count;i++)
{
for(j=0;j<260;j++);
}
}
//===================== 初始化代碼 =======================//
void ILI9325_Initial(void) //看不懂,反正照抄。。而且為什么參數(shù)是16位的。。。
{
//////////////////////////////////////////////////////////
delayms(150); //根據(jù)不同晶振速度可以調(diào)整延時(shí),保障穩(wěn)定顯示
Init_data(0x00E5, 0x8000); // Set the Vcore voltage and this setting is must.
Init_data(0x0000, 0x0001); // Start internal OSC.
Init_data(0x0001, 0x0100); // set SS and SM bit
Init_data(0x0002, 0x0700); // set 1 line inversion
Init_data(0x0003, 0x0030); // set GRAM write direction and BGR=0.
Init_data(0x0004, 0x0000); // Resize register
Init_data(0x0008, 0x0202); // set the back porch and front porch
Init_data(0x0009, 0x0000); // set non-display area refresh cycle ISC[3:0]
Init_data(0x000A, 0x0000); // FMARK function
Init_data(0x000C, 0x0000); // RGB interface setting
Init_data(0x000D, 0x0000); // Frame marker Position
Init_data(0x000F, 0x0000); // RGB interface polarity
//*************Power On sequence ****************//
Init_data(0x0010, 0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB
Init_data(0x0011, 0x0007); // DC1[2:0], DC0[2:0], VC[2:0]
Init_data(0x0012, 0x0000); // VREG1OUT voltage
Init_data(0x0013, 0x0000); // VDV[4:0] for VCOM amplitude
delayms(200); // Dis-charge capacitor power voltage
Init_data(0x0010, 0x17B0); // SAP, BT[3:0], AP, DSTB, SLP, STB
Init_data(0x0011, 0x0037); // DC1[2:0], DC0[2:0], VC[2:0]
delayms(50); // Delay 50ms
Init_data(0x0012, 0x013E); // VREG1OUT voltage
delayms(50); // Delay 50ms
Init_data(0x0013, 0x1F00); // VDV[4:0] for VCOM amplitude
Init_data(0x0029, 0x0013); // VCM[4:0] for VCOMH
delayms(50);
Init_data(0x0020, 0x0000); // GRAM horizontal Address
Init_data(0x0021, 0x0000); // GRAM Vertical Address
// ----------- Adjust the Gamma Curve ----------//
Init_data(0x0030, 0x0000);
Init_data(0x0031, 0x0404);
Init_data(0x0032, 0x0404);
Init_data(0x0035, 0x0004);
Init_data(0x0036, 0x0404);
Init_data(0x0037, 0x0404);
Init_data(0x0038, 0x0404);
Init_data(0x0039, 0x0707);
Init_data(0x003C, 0x0500);
Init_data(0x003D, 0x0607);
//------------------ Set GRAM area ---------------//
Init_data(0x0050, 0x0000); // Horizontal GRAM Start Address
Init_data(0x0051, 0x00EF); // Horizontal GRAM End Address
Init_data(0x0052, 0x0000); // Vertical GRAM Start Address
Init_data(0x0053, 0x013F); // Vertical GRAM Start Address
Init_data(0x0060, 0x2700); // Gate Scan Line
Init_data(0x0061, 0x0001); // NDL,VLE, REV
Init_data(0x006A, 0x0000); // set scrolling line
//-------------- Partial Display Control ---------//
Init_data(0x0080, 0x0000);
Init_data(0x0081, 0x0000);
Init_data(0x0082, 0x0000);
Init_data(0x0083, 0x0000);
Init_data(0x0084, 0x0000);
Init_data(0x0085, 0x0000);
//-------------- Panel Control -------------------//
Init_data(0x0090, 0x0010);
Init_data(0x0092, 0x0000);
Init_data(0x0093, 0x0003);
Init_data(0x0095, 0x0110);
Init_data(0x0097, 0x0000);
Init_data(0x0098, 0x0000);
Init_data(0x0007, 0x0173); // 262K color and display ON
// Write_Cmd_Data(0x0022);//
}
/*===========================================================*/
/*************************************************************
函數(shù)名稱:LCD_DefineDispWindow
功 能:定義顯示窗體
參 數(shù):x0: 窗體中X坐標(biāo)中較小者
x1: 窗體中X坐標(biāo)中較大者
y0: 窗體中Y坐標(biāo)中較小者
y1: 窗體中Y坐標(biāo)中較大者
返 回 值:無
*************************************************************/
static void LCD_SetPos(unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1) //寫彩屏必須要知道,寫之前必須激活區(qū)域,而且地址會自動(dòng)加1等基本常識
{
Init_data(WINDOW_XADDR_START,x0);
Init_data(WINDOW_XADDR_END,x1);
Init_data(WINDOW_YADDR_START,y0);
Init_data(WINDOW_YADDR_END,y1);
Init_data(GRAM_XADDR,x0);
Init_data(GRAM_YADDR,y0);
Write_Cmd (0x00,0x22);//LCD_WriteCMD(GRAMWR);
}
復(fù)制代碼
作者:
lyl_420819
時(shí)間:
2017-5-16 15:58
沒下載成,積分反而給扣了,胸悶!
作者:
helen
時(shí)間:
2017-8-24 10:46
為什么扣了我黑幣,但是沒有讓我下載
作者:
lyl_420819
時(shí)間:
2018-2-21 16:34
感謝你的分享
作者:
qjzyx
時(shí)間:
2018-2-21 17:21
等幾天在下個(gè)個(gè)看
作者:
lyl_420819
時(shí)間:
2018-3-1 13:49
好資料,謝謝分享。
作者:
huaishang
時(shí)間:
2018-7-19 22:55
感謝你的分享,對初學(xué)是好資料!
作者:
星隕
時(shí)間:
2018-7-20 10:59
不錯(cuò)不錯(cuò),謝謝樓主
作者:
htzsz
時(shí)間:
2018-8-2 20:12
正在找lcd取模軟件,謝謝樓主.
作者:
vvvgggy
時(shí)間:
2018-8-3 00:12
為什么扣了我黑幣,但是沒有讓我下載
作者:
滴滴答
時(shí)間:
2018-10-17 21:42
謝謝分享
作者:
wzp1995
時(shí)間:
2018-10-17 22:13
沒下載成,胸悶!
作者:
yasi666
時(shí)間:
2019-2-16 20:23
給力,太好了,鼓掌吧
作者:
中恒電子asus
時(shí)間:
2019-2-23 11:26
好資料,謝謝分享
作者:
1743146573
時(shí)間:
2019-4-5 11:01
感謝樓主分享
作者:
jinniuxing88888
時(shí)間:
2020-5-22 10:39
謝謝分享!
作者:
大漠游民
時(shí)間:
2021-3-8 18:55
好資料,謝謝分享!
作者:
希望在前方
時(shí)間:
2021-3-12 10:15
好資料,謝謝分享!
作者:
越南超級人類
時(shí)間:
2021-8-10 14:52
16位的51單片機(jī)用不了code8781
作者:
桃源客
時(shí)間:
2022-5-6 06:24
好東西,感謝分享,下來試下能不能點(diǎn)亮屏幕!
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1