完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
#include #define TFT_DATAPORTH P1 #define TFT_DATAPORTL P0 typedef unsigned char uchar; typedef unsigned int uint; ***it TFT_RW=P2^5; ***it TFT_RS=P2^6; ***it TFT_CS=P2^7; //片选(低电平有效) ***it TFT_RST=P3^3; //低电平复位 ***it TFT_RD=P3^0; //RD=0:读信号;RD=1:写数据 void TFT_init(void); void delay(int x); void TFT_writecmd(uint cmd); //该函数把命令字写入到TFT控制器 void TFT_writedata(uint dat); //该函数把数据字写入到TFT控制器 void TFT_write_cmd_data(uint cmd,uint dat); //该函数把命令字和数据字都写入到TFT控制器 void TFT_clearscreen(uint color); //清屏函数 void TFT_setwindow(uchar xStart,uchar yStart,uchar xEnd,uchar yEnd); //设置显示窗口 void GUI_Write32CnChar(uint x, uint y, uchar *cn, uint wordColor, uint backColor);//显示汉字 typedef struct _Cn32Char // 汉字字模数据结构 { uchar GBK[2]; // 汉字内码索引,一个汉字占两个字节 uchar hanzi[116]; // 点阵码数据(32*29/8) }Cn32Char; Cn32Char code CnChar32x29[]={ /*-- 文字: 普 --*/ /*-- 宋体22; 此字体下对应的点阵为:宽x高=29x29 --*/ /*-- 宽度不是8的倍数,现调整为:宽度x高度=32x29 --*/ "普",0x00,0x00,0x00,0x00,0x00,0x07,0x0C,0x00,0x00,0x1E,0x3E,0x00,0x00,0x3C,0x0E,0x00, 0x00,0x3C,0x87,0x03,0xF8,0xFF,0xFF,0x07,0x00,0x1C,0x07,0x00,0x60,0x1C,0xE7,0x00, 0xE0,0x1C,0xE7,0x01,0xC0,0x1D,0x77,0x00,0xC0,0x1F,0x77,0x00,0x80,0x1F,0x3F,0x00, 0x80,0x1D,0x1F,0x07,0xFF,0xFF,0xFF,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x80,0x00,0x30,0x00,0x80,0xFF,0x7F,0x00,0x80,0x03,0x38,0x00,0x80,0x03,0x38,0x00, 0x80,0x03,0x38,0x00,0x80,0xFF,0x3F,0x00,0x80,0x03,0x38,0x00,0x80,0x03,0x38,0x00, 0x80,0x03,0x38,0x00,0x80,0xFF,0x3F,0x00,0x80,0x03,0x38,0x00,0x80,0x01,0x18,0x00, 0x00,0x00,0x00,0x00 }; void main(void) { int i=0; TFT_init(); TFT_clearscreen(0xf800); GUI_Write32CnChar(24,25,"普",0x0000,0x0f800); while(1); } void delay(int x) { int a; while(x--) { for(a=0;a<200;a++); } } void TFT_init(void) { TFT_RST=1; delay(1); TFT_RST=0; delay(1); TFT_RST=1; delay(1); TFT_CS=0; TFT_write_cmd_data(0x0014,0x0030); TFT_write_cmd_data(0x000f,0x0008); TFT_write_cmd_data(0x0011,0x0231); TFT_write_cmd_data(0x0012,0x000a); TFT_write_cmd_data(0x0013,0x145d); TFT_write_cmd_data(0x0010,0x5268); delay(10); TFT_write_cmd_data(0x0012,0x001a); delay(10); TFT_write_cmd_data(0x0010,0x5260); TFT_write_cmd_data(0x0013,0x345d); delay(10); TFT_write_cmd_data(0x0030,0x0000); TFT_write_cmd_data(0x0031,0x0705); TFT_write_cmd_data(0x0032,0x0706); TFT_write_cmd_data(0x0033,0x0102); TFT_write_cmd_data(0x0034,0x0204); TFT_write_cmd_data(0x0035,0x0000); TFT_write_cmd_data(0x0036,0x0104); TFT_write_cmd_data(0x0037,0x0007); TFT_write_cmd_data(0x0038,0x0000); TFT_write_cmd_data(0x0039,0x0000); TFT_write_cmd_data(0x0001,0x011b); TFT_write_cmd_data(0x0002,0x0700); TFT_write_cmd_data(0x0003,0x1030); TFT_write_cmd_data(0x000b,0x1010); TFT_write_cmd_data(0x000a,0x4420); TFT_write_cmd_data(0x000b,0x5030); TFT_write_cmd_data(0x0007,0x0005); TFT_write_cmd_data(0x0007,0x0025); TFT_write_cmd_data(0x0007,0x0027); TFT_write_cmd_data(0x0007,0x0037); } void TFT_writecmd(uint cmd) { TFT_RW=1; TFT_CS=0; TFT_RD=1; TFT_RS=0; TFT_DATAPORTH=cmd>>8; TFT_RW=0; TFT_RW=1; TFT_DATAPORTL=cmd&0x00ff; TFT_RW=0; TFT_RW=1; TFT_CS=1; } void TFT_writedata(uint dat) { TFT_RW=1; TFT_CS=0; TFT_RD=1; TFT_RS=1; TFT_DATAPORTH=dat>>8; TFT_RW=0; TFT_RW=1; TFT_DATAPORTL=dat&0x00ff; TFT_RW=0; TFT_RW=1; TFT_CS=1; } void TFT_write_cmd_data(uint cmd,uint dat) { TFT_writecmd(cmd); TFT_writedata(dat); } void TFT_clearscreen(uint color) { int i,j; TFT_setwindow(0,0,175,219); for(i=0;i<=175;i++) { for(j=0;j<=219;j++) { TFT_writedata(color); } } } void TFT_setwindow(uchar xStart,uchar yStart,uchar xEnd,uchar yEnd) { uint x,y,z; x=(xEnd<<8)|xStart; y=(yEnd<<8)|yStart; z=(yStart<<8)|xStart; TFT_write_cmd_data(0x44,x); TFT_write_cmd_data(0x45,y); TFT_write_cmd_data(0x21,z); TFT_write_cmd_data(0x22,0x0000); } void GUI_Write32CnChar(uint x, uint y, uchar *cn, uint wordColor, uint backColor) { uchar i,j,wordNum; uint color; while(*cn!=' |