完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
最近在用一块1.44的液晶屏,驱动IC是ST7735 买屏的时候卖家有给例程,里面有一份例程是显示英文字符的, 我看不明白,特别是里面对数据的处理方式。 求哪位用过的前辈指点一下。谢谢 不甚感激。 #include #include #include #include #define uchar unsigned char #define uint unsigned int //测试硬件平台:STC12C5A60S2/STC12LE5A60S2 //主频:12MHZ //单片机IO推挽输出设置定义 //#define USE_LANDSCAPE//测试程序横竖屏切换,横屏请开启此宏,竖屏请屏蔽 #define MCU_STC12//如果您使用的单片机不是STC12系列(如STC89C52)请屏蔽此宏定义 #ifdef MCU_STC12 sfr P3M1 = 0xB1; //P3M1.n,P3M0.n =00--->Standard, 01--->push-pull sfr P3M0 = 0xB2; // =10--->pure input, 11--->open drain #endif //---------------------------液晶屏接线说明-------------------------------------// //接线前请参考液晶屏说明书第10页引脚定义 ***it bl =P3^2;//接模块BL引脚,背光可以采用IO控制或者PWM控制,也可以直接接到高电平常亮 ***it scl =P1^7;//接模块CLK引脚,接裸屏Pin9_SCL ***it sda =P1^5;//接模块DIN/MOSI引脚,接裸屏Pin8_SDA ***it rs =P1^2;//接模块D/C引脚,接裸屏Pin7_A0 ***it cs =P1^3;//接模块CE引脚,接裸屏Pin12_CS ***it reset =P3^3;//接模块RST引脚,接裸屏Pin6_RES //---------------------------End of液晶屏接线---------------------------------// //定义常用颜色 #define RED 0xf800 #define GREEN 0x07e0 #define BLUE 0x001f #define WHITE 0xffff #define BLACK 0x0000 #define YELLOW 0xFFE0 #define GRAY0 0xEF7D #define GRAY1 0x8410 #define GRAY2 0x4208 void Contrast_Adjust(); uchar code Zk_ASCII8X16[]; void Display_Desc(); void Output_Pixel(uint x,uint y); void Display_ASCII8X16(uint x0,uint y0,uchar *s); void delay_ms(uint time) { uint i,j; for(i=0;i for(j=0;j<250;j++); } //向SPI总线传输一个8位数据 void SPI_WriteData(uchar Data) { unsigned char i=0; for(i=8;i>0;i--) { if(Data&0x80) sda=1; //输出数据 else sda=0; scl=0; scl=1; Data<<=1; } } //向液晶屏写一个8位指令 void Lcd_WriteIndex(uchar Data) { cs=0; rs=0; SPI_WriteData(Data); cs=1; } //向液晶屏写一个8位数据 void Lcd_WriteData(uchar Data) { unsigned char i=0; cs=0; rs=1; SPI_WriteData(Data); cs=1; } //向液晶屏写一个16位数据 void LCD_WriteData_16Bit(unsigned int Data) { unsigned char i=0; cs=0; rs=1; SPI_WriteData(Data>>8); //写入高8位数据 SPI_WriteData(Data); //写入低8位数据 cs=1; } void Reset() { reset=0; delay_ms(100); reset=1; delay_ms(100); } ////////////////////////////////////////////////////////////////////////////////////////////// //液晶屏初始化 for S6D02A1 void lcd_initial() { Reset();//Reset before LCD Init. //LCD Init For 1.44Inch LCD Panel with ST7735R. Lcd_WriteIndex(0x11);//Sleep exit delay_ms (120); //ST7735R Frame Rate Lcd_WriteIndex(0xB1); Lcd_WriteData(0x01); Lcd_WriteData(0x2C); Lcd_WriteData(0x2D); Lcd_WriteIndex(0xB2); Lcd_WriteData(0x01); Lcd_WriteData(0x2C); Lcd_WriteData(0x2D); Lcd_WriteIndex(0xB3); Lcd_WriteData(0x01); Lcd_WriteData(0x2C); Lcd_WriteData(0x2D); Lcd_WriteData(0x01); Lcd_WriteData(0x2C); Lcd_WriteData(0x2D); Lcd_WriteIndex(0xB4); //Column inversion Lcd_WriteData(0x07); //ST7735R Power Sequence Lcd_WriteIndex(0xC0); Lcd_WriteData(0xA2); Lcd_WriteData(0x02); Lcd_WriteData(0x84); Lcd_WriteIndex(0xC1); Lcd_WriteData(0xC5); Lcd_WriteIndex(0xC2); Lcd_WriteData(0x0A); Lcd_WriteData(0x00); Lcd_WriteIndex(0xC3); Lcd_WriteData(0x8A); Lcd_WriteData(0x2A); Lcd_WriteIndex(0xC4); Lcd_WriteData(0x8A); Lcd_WriteData(0xEE); Lcd_WriteIndex(0xC5); //VCOM Lcd_WriteData(0x0E); Lcd_WriteIndex(0x36); //MX, MY, RGB mode #ifdef USE_LANDSCAPE Lcd_WriteData(0xA8); //竖屏C8 横屏08 A8 #else Lcd_WriteData(0xC8); //竖屏C8 横屏08 A8 #endif //ST7735R Gamma Sequence Lcd_WriteIndex(0xe0); Lcd_WriteData(0x0f); Lcd_WriteData(0x1a); Lcd_WriteData(0x0f); Lcd_WriteData(0x18); Lcd_WriteData(0x2f); Lcd_WriteData(0x28); Lcd_WriteData(0x20); Lcd_WriteData(0x22); Lcd_WriteData(0x1f); Lcd_WriteData(0x1b); Lcd_WriteData(0x23); Lcd_WriteData(0x37); Lcd_WriteData(0x00); Lcd_WriteData(0x07); Lcd_WriteData(0x02); Lcd_WriteData(0x10); Lcd_WriteIndex(0xe1); Lcd_WriteData(0x0f); Lcd_WriteData(0x1b); Lcd_WriteData(0x0f); Lcd_WriteData(0x17); Lcd_WriteData(0x33); Lcd_WriteData(0x2c); Lcd_WriteData(0x29); Lcd_WriteData(0x2e); Lcd_WriteData(0x30); Lcd_WriteData(0x30); Lcd_WriteData(0x39); Lcd_WriteData(0x3f); Lcd_WriteData(0x00); Lcd_WriteData(0x07); Lcd_WriteData(0x03); Lcd_WriteData(0x10); Lcd_WriteIndex(0x2a); Lcd_WriteData(0x00); Lcd_WriteData(0x00+2); Lcd_WriteData(0x00); Lcd_WriteData(0x80+2); Lcd_WriteIndex(0x2b); Lcd_WriteData(0x00); Lcd_WriteData(0x00+3); Lcd_WriteData(0x00); Lcd_WriteData(0x80+3); Lcd_WriteIndex(0xF0); //Enable test command Lcd_WriteData(0x01); Lcd_WriteIndex(0xF6); //Disable ram power save mode Lcd_WriteData(0x00); Lcd_WriteIndex(0x3A); //65k mode Lcd_WriteData(0x05); Lcd_WriteIndex(0x29);//Display on } /************************************************* 函数名:LCD_Set_Region 功能:设置lcd显示区域,在此区域写点数据自动换行 入口参数:xy起点和终点 返回值:无 *************************************************/ void Lcd_SetRegion(unsigned int x_start,unsigned int y_start,unsigned int x_end,unsigned int y_end) { #ifdef USE_LANDSCAPE//使用横屏模式 Lcd_WriteIndex(0x2a); Lcd_WriteData(0x00); Lcd_WriteData(x_start+3); Lcd_WriteData(0x00); Lcd_WriteData(x_end+3); Lcd_WriteIndex(0x2b); Lcd_WriteData(0x00); Lcd_WriteData(y_start+2); Lcd_WriteData(0x00); Lcd_WriteData(y_end+2); #else//竖屏模式 Lcd_WriteIndex(0x2a); Lcd_WriteData(0x00); Lcd_WriteData(x_start+2); Lcd_WriteData(0x00); Lcd_WriteData(x_end+2); Lcd_WriteIndex(0x2b); Lcd_WriteData(0x00); Lcd_WriteData(y_start+3); Lcd_WriteData(0x00); Lcd_WriteData(y_end+3); #endif Lcd_WriteIndex(0x2c); } void PutPixel(uint x_start,uint y_start,uint color) { Lcd_SetRegion(x_start,y_start,x_start+1,y_start+1); LCD_WriteData_16Bit(color); } void dsp_single_colour(int color) { uchar i,j; Lcd_SetRegion(0,0,128-1,128-1); for (i=0;i<128;i++) for (j=0;j<128;j++) LCD_WriteData_16Bit(color); } void Display_Desc() { Display_ASCII8X16(10,10,"Welcome"); Display_ASCII8X16(10,26,"QDtech"); Display_ASCII8X16(10,42,"Dots:128*128"); Display_ASCII8X16(10,58,"IC: ST7735"); Display_ASCII8X16(10,74,"VA:6 o'clock"); Display_ASCII8X16(10,90,"2013.10.26"); } //显示一个英文字符 void Display_ASCII8X16(uint x0,uint y0,uchar *s) { int i,j,k,x,y,xx; unsigned char qm; long int ulOffset; char ywbuf[32],temp[2]; for(i = 0; i if(((unsigned char)(*(s+i))) >= 161) { temp[0] = *(s+i); temp[1] = ' |