|
TFT144液晶屏源程序(驅(qū)動程序)
單片機(jī)源程序如下:
- //********************************************************************************
- #include "STC15.H"
- #include <intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- #include "delay.h"
- #include "tft128128spi.h"
- //---------------------------液晶屏接線說明-------------------------------------//
- //接線前請參考液晶屏說明書第10頁引腳定義
- sbit scl =P2^7;//接模塊CLK引腳,接裸屏Pin9_SCL
- sbit sda =P2^6;//接模塊DIN/MOSI引腳,接裸屏Pin8_SDA
- sbit reset =P2^5;//接模塊dcT引腳,接裸屏Pin6_RES
- sbit dc =P2^4;//接模塊D/C引腳,接裸屏Pin7_A0
- sbit cs =P2^3;//接模塊CE引腳,接裸屏Pin12_CS
- sbit bl =P2^2;//接模塊BL引腳,背光可以采用IO控制或者PWM控制,也可以直接接到高電平常亮
- //---------------------------End of液晶屏接線---------------------------------//
- bit USE_LANDSCAPE;//程序橫豎屏切換
- //向液晶屏寫一個8位指令
- void LCD_WrCmd(uchar cmd)
- {
- uchar i;
- cs=0;dc=0;
- for(i=0;i<8;i++)
- {
- scl=0;
- if(cmd&0x80)sda=1;else sda=0;
- scl=1;
- cmd<<=1;
- }
- cs=1;
- }
- //向液晶屏寫一個8位數(shù)據(jù)
- void LCD_WrDat(uchar dat)
- {
- uchar i;
- cs=0;dc=1;
- for(i=0;i<8;i++)
- {
- scl=0;
- if(dat&0x80)sda=1;else sda=0;
- scl=1;
- dat<<=1;
- }
- cs=1;
- }
- //向液晶屏寫一個16位數(shù)據(jù)
- void LCD_WrDat_16Bit(uint dat)
- {
- LCD_WrDat(dat>>8); //寫入高8位數(shù)據(jù)
- LCD_WrDat(dat); //寫入低8位數(shù)據(jù)
-
- }
- void Reset()
- {
- reset=0;
- delayms(100);
- reset=1;
- delayms(100);
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- //液晶屏初始化 for S6D02A1
- void lcd_initial()
- { Reset();//Reset before LCD Init.
-
- //LCD Init For 1.44Inch LCD Panel with ST7735R.
- LCD_WrCmd(0x11);//Sleep exit
- delayms (120);
-
- //ST7735R Frame Rate
- LCD_WrCmd(0xB1);
- LCD_WrDat(0x01);
- LCD_WrDat(0x2C);
- LCD_WrDat(0x2D);
- LCD_WrCmd(0xB2);
- LCD_WrDat(0x01);
- LCD_WrDat(0x2C);
- LCD_WrDat(0x2D);
- LCD_WrCmd(0xB3);
- LCD_WrDat(0x01);
- LCD_WrDat(0x2C);
- LCD_WrDat(0x2D);
- LCD_WrDat(0x01);
- LCD_WrDat(0x2C);
- LCD_WrDat(0x2D);
-
- LCD_WrCmd(0xB4); //Column invedcion
- LCD_WrDat(0x07);
-
- //ST7735R Power Sequence
- LCD_WrCmd(0xC0);
- LCD_WrDat(0xA2);
- LCD_WrDat(0x02);
- LCD_WrDat(0x84);
- LCD_WrCmd(0xC1);
- LCD_WrDat(0xC5);
- LCD_WrCmd(0xC2);
- LCD_WrDat(0x0A);
- LCD_WrDat(0x00);
- LCD_WrCmd(0xC3);
- LCD_WrDat(0x8A);
- LCD_WrDat(0x2A);
- LCD_WrCmd(0xC4);
- LCD_WrDat(0x8A);
- LCD_WrDat(0xEE);
-
- LCD_WrCmd(0xC5); //VCOM
- LCD_WrDat(0x0E);
-
- LCD_WrCmd(0x36); //MX, MY, RGB mode
- if(USE_LANDSCAPE)
- LCD_WrDat(0xA8); //豎屏C8 橫屏08 A8
- else
- LCD_WrDat(0xC8); //豎屏C8 橫屏08 A8
-
- //ST7735R Gamma Sequence
- LCD_WrCmd(0xe0);
- LCD_WrDat(0x0f);
- LCD_WrDat(0x1a);
- LCD_WrDat(0x0f);
- LCD_WrDat(0x18);
- LCD_WrDat(0x2f);
- LCD_WrDat(0x28);
- LCD_WrDat(0x20);
- LCD_WrDat(0x22);
- LCD_WrDat(0x1f);
- LCD_WrDat(0x1b);
- LCD_WrDat(0x23);
- LCD_WrDat(0x37);
- LCD_WrDat(0x00);
- LCD_WrDat(0x07);
- LCD_WrDat(0x02);
- LCD_WrDat(0x10);
- LCD_WrCmd(0xe1);
- LCD_WrDat(0x0f);
- LCD_WrDat(0x1b);
- LCD_WrDat(0x0f);
- LCD_WrDat(0x17);
- LCD_WrDat(0x33);
- LCD_WrDat(0x2c);
- LCD_WrDat(0x29);
- LCD_WrDat(0x2e);
- LCD_WrDat(0x30);
- LCD_WrDat(0x30);
- LCD_WrDat(0x39);
- LCD_WrDat(0x3f);
- LCD_WrDat(0x00);
- LCD_WrDat(0x07);
- LCD_WrDat(0x03);
- LCD_WrDat(0x10);
-
- LCD_WrCmd(0x2a);
- LCD_WrDat(0x00);
- LCD_WrDat(0x00+2);
- LCD_WrDat(0x00);
- LCD_WrDat(0x80+2);
- LCD_WrCmd(0x2b);
- LCD_WrDat(0x00);
- LCD_WrDat(0x00+3);
- LCD_WrDat(0x00);
- LCD_WrDat(0x80+3);
-
- LCD_WrCmd(0xF0); //Enable test command
- LCD_WrDat(0x01);
- LCD_WrCmd(0xF6); //Disable ram power save mode
- LCD_WrDat(0x00);
-
- LCD_WrCmd(0x3A); //65k mode
- LCD_WrDat(0x05);
-
-
- LCD_WrCmd(0x29);//Display on
- bl=1; //背光
- }
- /*************************************************
- 函數(shù)名:LCD_Set_Region
- 功能:設(shè)置lcd顯示區(qū)域,在此區(qū)域?qū)扅c數(shù)據(jù)自動換行
- 入口參數(shù):xy起點和終點
- 返回值:無
- *************************************************/
- void Lcd_SetRegion(uint x_start,uint y_start,uint x_end,uint y_end)reentrant
- {
- if(USE_LANDSCAPE)//使用橫屏模式
- {
- LCD_WrCmd(0x2a);
- LCD_WrDat(0x00);
- LCD_WrDat(x_start+3);
- LCD_WrDat(0x00);
- LCD_WrDat(x_end+3);
- LCD_WrCmd(0x2b);
- LCD_WrDat(0x00);
- LCD_WrDat(y_start+2);
- LCD_WrDat(0x00);
- LCD_WrDat(y_end+2);
- }
- else//豎屏模式
- {
- LCD_WrCmd(0x2a);
- LCD_WrDat(0x00);
- LCD_WrDat(x_start+2);
- LCD_WrDat(0x00);
- LCD_WrDat(x_end+2);
- LCD_WrCmd(0x2b);
- LCD_WrDat(0x00);
- LCD_WrDat(y_start+3);
- LCD_WrDat(0x00);
- LCD_WrDat(y_end+3);
- }
- LCD_WrCmd(0x2c);
- }
- void LCD_Clear(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_WrDat_16Bit(color);
- }
- void LCD_A_Char8X16(uint x, uint y, uint fc, uint bc, uchar *s)reentrant
- {
- uchar i,j,temp;
- Lcd_SetRegion(x,y,x+8-1,y+16-1);
- for(i=0;i<16;i++)
- {
- temp=s[i];
- for(j=0;j<8;j++)
- {
- if(temp&0x80)LCD_WrDat_16Bit(fc);
- else if (fc!=bc) LCD_WrDat_16Bit(bc);
- temp<<=1;
- }
- }
- }
- void LCD_Char8X16_String(uint x,uint y,uint fc,uint bc,uchar *s,uchar c)reentrant
- {
- uchar i;
- for(i=0;i<c;i++) LCD_A_Char8X16(x+i*8,y,fc,bc,s+i*16);
- }
- void LCD_CHN16X16(uint x, uint y, uint fc, uint bc, uchar *s)reentrant //顯示一個漢字
- {
- uchar i,j,temp;
- Lcd_SetRegion(x,y,x+16-1,y+16-1);
- for(i=0;i<32;i++)
- {
- temp=s[i];
- for(j=0;j<8;j++)
- {
- if(temp&0x80)LCD_WrDat_16Bit(fc);
- else if (fc!=bc) LCD_WrDat_16Bit(bc);
- temp<<=1;
- }
- }
- }
- void LCD_CHN16X16_String(uint x,uint y,uint fc,uint bc,uchar *s,uchar c)
- {
- uchar i;
- for(i=0;i<c;i++)LCD_CHN16X16(x+i*16,y,fc,bc,s+i*32);
- }
-
- //void LCD_A_Char16X32(uint x, uint y, uint fc, uint bc, uchar *s)
- //{
- // uchar i,j,temp;
- // Lcd_SetRegion(x,y,x+16-1,y+32-1);
- // for(i=0;i<64;i++) //16*32西文字符點陣64個8位字節(jié)
- // {
- // temp=s[i];
- // for(j=0;j<8;j++)
- // {
- // if(temp&0x80)LCD_WrDat_16Bit(fc);
- // else if (fc!=bc) LCD_WrDat_16Bit(bc);
- // temp<<=1;
- // }
- // }
- //
- //}
- /*
- void LCD_A_Char24X48(uint x, uint y, uint fc, uint bc, uchar *s)
- {
- uchar i,j,temp;
- Lcd_SetRegion(x,y,x+24-1,y+48-1);
- for(i=0;i<144;i++) //24*48西文字符點陣144個8位字節(jié)
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
tft144.png (67.52 KB, 下載次數(shù): 90)
下載附件
2020-4-29 22:12 上傳
所有資料51hei提供下載:
TFT144液晶屏.zip
(2.56 KB, 下載次數(shù): 26)
2020-4-29 22:11 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|
|