久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费
標題:
STM32 I/O 口驅動程序 ILI9325 TFT
[打印本頁]
作者:
luxuan_006
時間:
2017-3-6 12:59
標題:
STM32 I/O 口驅動程序 ILI9325 TFT
STM32F103 使用 IO 口驅動 320240 TFT(ILI9325) 液晶屏頭文件+函數文件。分享給大家,希望對大家有用。
0.png
(63.32 KB, 下載次數: 96)
下載附件
2017-3-6 21:03 上傳
完整源碼下載:
ILI9325.rar
(7.13 KB, 下載次數: 128)
2017-3-6 12:55 上傳
點擊文件名下載附件
ILI9325.h+ILI9325.c
下載積分: 黑幣 -5
主程序:
#include "mILI9325.h"
#include "mFONT.h"
extern mDis_Color ILI9325;
GPIO_InitTypeDef GPIO_InitStructure;
//Red Gray scale灰階(65K)
const unsigned char RedGrayScale[]={
0x00,0x00, 0x08,0x00, 0x10,0x00, 0x18,0x00, 0x20,0x00, 0x28,0x00, 0x30,0x00, 0x38,0x00,
0x40,0x00, 0x48,0x00, 0x50,0x00, 0x58,0x00, 0x60,0x00, 0x68,0x00, 0x70,0x00, 0x78,0x00,
0x80,0x00, 0x88,0x00, 0x90,0x00, 0x98,0x00, 0xA0,0x00, 0xA8,0x00, 0xB0,0x00, 0xB8,0x00,
0xC0,0x00, 0xC8,0x00, 0xD0,0x00, 0xD8,0x00, 0xE0,0x00, 0xE8,0x00, 0xF0,0x00, 0xF8,0x00,
};
//Green Gray scale灰階(65K)
const unsigned char GreenGrayScale[]={
0x00,0x00, 0x00,0x60, 0x00,0xA0, 0x00,0xE0, 0x01,0x00, 0x01,0x60, 0x01,0xA0, 0x01,0xE0,
0x02,0x00, 0x02,0x60, 0x02,0xA0, 0x02,0xE0, 0x03,0x00, 0x03,0x60, 0x03,0xA0, 0x03,0xE0,
0x04,0x00, 0x04,0x60, 0x04,0xA0, 0x04,0xE0, 0x05,0x00, 0x05,0x60, 0x05,0xA0, 0x05,0xE0,
0x06,0x00, 0x06,0x60, 0x06,0xA0, 0x06,0xE0, 0x07,0x00, 0x07,0x60, 0x07,0xA0, 0x07,0xE0,
};
//Blue Gray scale灰階(65K)
const unsigned char BlueGrayScale[]={
0x00,0x00, 0x00,0x01, 0x00,0x02, 0x00,0x03, 0x00,0x04, 0x00,0x05, 0x00,0x06, 0x00,0x07,
0x00,0x08, 0x00,0x09, 0x00,0x0A, 0x00,0x0B, 0x00,0x0C, 0x00,0x0D, 0x00,0x0E, 0x00,0x0F,
0x00,0x10, 0x00,0x11, 0x00,0x12, 0x00,0x13, 0x00,0x14, 0x00,0x15, 0x00,0x16, 0x00,0x17,
0x00,0x18, 0x00,0x19, 0x00,0x1A, 0x00,0x1B, 0x00,0x1C, 0x00,0x1D, 0x00,0x1E, 0x00,0x1F,
};
//White Gray scale灰階(65K)
const unsigned char WhiteGrayScale[]={
0x00,0x00, 0x08,0x61, 0x10,0xA2, 0x18,0xE3, 0x21,0x04, 0x29,0x65, 0x31,0xA6, 0x39,0xE7,
0x42,0x08, 0x4A,0x69, 0x52,0xAA, 0x5A,0xEB, 0x63,0x0C, 0x6B,0x6D, 0x73,0xAE, 0x7B,0xEF,
0x84,0x10, 0x8C,0x71, 0x94,0xB2, 0x9C,0xF3, 0xA5,0x14, 0xAD,0x75, 0xB5,0xB6, 0xBD,0xF7,
0xC6,0x18, 0xCE,0x79, 0xD6,0xBA, 0xDE,0xFB, 0xE7,0x1C, 0xEF,0x7D, 0xF7,0xBE, 0xFF,0xFF,
};
/*******************************************************************************
* Function Name : Delay_mS
* Description : 延時功能函數
* Input : nCount 延時值( mS )
* Output : None
* Return : None
*******************************************************************************/
void Delay_mS (uint16_t nCount){
unsigned int i;
do{
for(i=0; i<5000; i++);
}
while(nCount--);
}
/*******************************************************************************
* Function Name : Delay_uS
* Description : 延時功能函數
* Input : nCount 延時值( uS )
* Output : None
* Return : None
*******************************************************************************/
void Delay_uS (uint16_t nCount){
unsigned int i;
do{
for(i=0; i<5; i++);
}while(nCount--);
}
/*******************************************************************************
* Function Name : ILI9325_CtrlLinesConfig
* Description : Configures LCD control lines in Output Push-Pull mode.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_Reset(void){
//對TFT進行復位一次
ILI9325_RESET_HIGH();
Delay_mS(50);
ILI9325_RESET_LOW();
Delay_mS(100);
ILI9325_RESET_HIGH();
Delay_mS(50);
}
/*******************************************************************************
* Function Name : ILI9325_CtrlLinesConfig 控制線配置
* Description : Configures LCD control lines in Output Push-Pull mode.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_CtrlLinesConfig(void) {
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOD, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOE, ENABLE);
/* Configure PD.7--PD.11 as Output push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_LCD_CS | GPIO_LCD_RS | GPIO_LCD_WR | GPIO_LCD_RD |
GPIO_LCD_PW ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_LCD_RESET;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
/* Configure PE.00 -- PE.15 as Output push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
}
/*******************************************************************************
* Function Name : ILI9325_WriteIndex
* Description : 尋址寄存器
* Input : Index
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_WriteIndex(uint8_t Index) {
//寫索引寄存器
ILI9325_RS_LOW();
ILI9325_CS_LOW();
ILI9325_RD_HIGH();
GPIO_Write(GPIOD,Index);
ILI9325_WR_LOW();
ILI9325_WR_HIGH();
ILI9325_CS_HIGH();
}
/*******************************************************************************
* Function Name : ILI9325_WriteData
* Description :
* Input : Data
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_WriteData(uint16_t Data) {
ILI9325_RS_HIGH();
ILI9325_CS_LOW();
ILI9325_RD_HIGH();
GPIO_Write(GPIOD,Data);
ILI9325_WR_LOW();
ILI9325_WR_HIGH();
ILI9325_CS_HIGH();
}
/*******************************************************************************
* Function Name : ILI9325_ReadData
* Description :
* Input : None
* Output : None
* Return : None
*******************************************************************************/
uint16_t ILI9325_ReadData(void) {
unsigned short Data=0;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD, &GPIO_InitStructure);
ILI9325_CS_LOW();
ILI9325_RS_HIGH();
ILI9325_WR_HIGH();
//丟掉第一次讀出的不確定數
ILI9325_RD_LOW();
Data = GPIO_ReadInputData(GPIOD);
ILI9325_RD_HIGH();
ILI9325_RD_LOW();
Data = GPIO_ReadInputData(GPIOD);
ILI9325_RD_HIGH();
ILI9325_CS_HIGH();
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
return Data;
}
/*******************************************************************************
* Function Name : ILI9325_WriteReg
* Description : Writes to the selected LCD register.
* Input : - LCD_Reg: address of the selected register.
* - LCD_RegValue: value to write to the selected register.
* Output : None
* Return : None
*******************************************************************************/
/*void ILI9325_WriteReg(unsigned char LCD_Reg, unsigned short LCD_RegValue) {
//寫索引寄存器
ILI9325_WriteIndex(unsigned char LCD_Reg);
//向所尋寄存器中寫入值
ILI9325_WriteData(unsigned short LCD_RegValue);
}*/
void ILI9325_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue) {
//寫索引寄存器
ILI9325_RS_LOW();
ILI9325_CS_LOW();
ILI9325_RD_HIGH();
GPIO_Write(GPIOD,LCD_Reg);
ILI9325_WR_LOW();
ILI9325_WR_HIGH();
ILI9325_CS_HIGH();
//向所尋寄存器中寫入值
ILI9325_RS_HIGH();
ILI9325_CS_LOW();
ILI9325_RD_HIGH();
GPIO_Write(GPIOD,LCD_RegValue);
ILI9325_WR_LOW();
ILI9325_WR_HIGH();
ILI9325_CS_HIGH();
}
/*******************************************************************************
* Function Name : ILI9325_BackLight(
* Description : LCD 背景燈狀態設置.
* Input : - State: 背景燈狀態 ON 或者 OFF
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_BackLight(uint8_t State) {
if(State == ON)
ILI9325_PW_HIGH();
else
ILI9325_PW_LOW();
}
/*******************************************************************************
* Function Name : ILI9325_WriteGRAM
* Description : Writes to the LCD RAM.
* Input : - RGB_Code: the pixel color in RGB mode (5-6-5).
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_WriteGRAM(uint16_t RGB_Code) {
ILI9325_WriteReg(R22,RGB_Code);
}
/*******************************************************************************
* Function Name : ILI9325_Init
* Description : Initializes LCD.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_Init(void) {
//Driver IC:ILI9325
ILI9325_CtrlLinesConfig(); //TFT的系統接口配置(本TFT模塊采用的是i80 16-bit System Bus)
ILI9325_Reset(); //復位一次
//ILI9325_WriteReg(0x00E3, 0x3008);
//ILI9325_WriteReg(0x00E7, 0x0012);
//ILI9325_WriteReg(0x00EF, 0x1231);
ILI9325_WriteReg(0x00E5, 0x78F0);
/*其中的SM位配合R96中的GS位,來決定圖像刷新方向。本配置為從上到下
SM GS=00從下到上 SM GS=01從上到下 SM GS=10 從右到左 SM GS=11 從左到右*/
ILI9325_WriteReg(R1, 0x0100);//R1:驅動輸出控制
ILI9325_WriteReg(R2, 0x0700);//line inversion
/*GRAM水平方向更新*/
ILI9325_WriteReg(R3, 0x1018);//R3:數據進入模式設置 1030
/*保持原圖像大小*/
ILI9325_WriteReg(R4, 0x0000);//R4:可將原圖像縮小到1/2或1/4來顯示
/*****************Display Control*******************/
ILI9325_WriteReg(R8, 0x0202);//0207
ILI9325_WriteReg(R9, 0x0000);
ILI9325_WriteReg(R0A, 0x0000);
ILI9325_WriteReg(R0C, 0x0000);
ILI9325_WriteReg(R0D, 0x0000);
ILI9325_WriteReg(R0F, 0x0000);
/***************Power Control*********************/
ILI9325_WriteReg(R10, 0x0000);
ILI9325_WriteReg(R11, 0x0007);//0004
ILI9325_WriteReg(R12, 0x0000);
ILI9325_WriteReg(R13, 0x0000);
ILI9325_WriteReg(R7, 0x0000);
Delay_mS(200);
ILI9325_WriteReg(R10, 0x1690);
ILI9325_WriteReg(R11, 0x0227);//0224
Delay_mS(50);
ILI9325_WriteReg(R12, 0x009d);//001b
Delay_mS(50);
ILI9325_WriteReg(R13, 0x1900);//1100
ILI9325_WriteReg(R29, 0x0025);//0008
ILI9325_WriteReg(R2B, 0x000d);
Delay_mS(50);
//默認顯示坐標(0,0)
ILI9325_WriteReg(R20, 0x0000);
ILI9325_WriteReg(R21, 0x0000);
/**************Gamma Control***********/
ILI9325_WriteReg(R30, 0x0007);
ILI9325_WriteReg(R31, 0x0303);
ILI9325_WriteReg(R32, 0x0003);
ILI9325_WriteReg(R35, 0x0206);
ILI9325_WriteReg(R36, 0x0008);
ILI9325_WriteReg(R37, 0x0406);
ILI9325_WriteReg(R38, 0x0304);
ILI9325_WriteReg(R39, 0x0007);
ILI9325_WriteReg(R3C, 0x0602);
ILI9325_WriteReg(R3D, 0x0008);
/********Sets display window,默認為整個屏幕********/
ILI9325_WriteReg(R50, 0x0000);
ILI9325_WriteReg(R51, 0x00ee);
ILI9325_WriteReg(R52, 0x0000);
ILI9325_WriteReg(R53, 0x013f);
/*******Gate Scan Control*************************/
ILI9325_WriteReg(R60, 0xa700);
ILI9325_WriteReg(R61, 0x0001);
ILI9325_WriteReg(R6A, 0x0000);
/********Partial Image Display Position Control***/
ILI9325_WriteReg(R80, 0x0000);
ILI9325_WriteReg(R81, 0x0000);
ILI9325_WriteReg(R82, 0x0000);
ILI9325_WriteReg(R83, 0x0000);
ILI9325_WriteReg(R84, 0x0000);
ILI9325_WriteReg(R85, 0x0000);
/*******Panel Interface Control******************/
ILI9325_WriteReg(R90, 0x0010);
ILI9325_WriteReg(R92, 0x0600);
ILI9325_WriteReg(R7, 0x0133);
ILI9325_WriteReg(R0, 0x0022);
ILI9325.TextColor = 0x0000;
ILI9325.BackColor = 0x667F;
ILI9325_FillSCR(ILI9325.BackColor);
ILI9325_BackLight(ON);
}
/*******************************************************************************
* Function Name : ILI9325_SetDisplayWindow
* Description : 設置顯示窗口
* Input : - startx: specifies the X buttom left position.
* - starty: specifies the Y buttom left position.
* - endx: display window width.
* - endy: display window height.
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_SetDisplayWindow(uint16_t startx, uint16_t starty, uint16_t endx, uint16_t endy) {
// 順轉90度
ILI9325_WriteReg(R50, starty);
ILI9325_WriteReg(R51, endy);
ILI9325_WriteReg(R52, 319-endx);
ILI9325_WriteReg(R53, 319-startx);
ILI9325_WriteReg(R20, endy);
ILI9325_WriteReg(R21, 319-endx);
/*// 逆轉90度
ILI9325_WriteReg(R50, 239-endy);
ILI9325_WriteReg(R51, 239-starty);
ILI9325_WriteReg(R52, startx);
ILI9325_WriteReg(R53, endx);
ILI9325_WriteReg(R20, 239-starty);
ILI9325_WriteReg(R21, startx);
*/
}
/*******************************************************************************
* Function Name : ILI9325_EnterSleep
* Description : LCD 進入休眠模式
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_EnterSleep(void) {
ILI9325_WriteReg(R7, 0x0131);
Delay_mS(10);
ILI9325_WriteReg(R7, 0x0130);
Delay_mS(10);
ILI9325_WriteReg(R7, 0x0000);
ILI9325_WriteReg(R10, 0x0080);
ILI9325_WriteReg(R11, 0x0000);
ILI9325_WriteReg(R12, 0x0000);
ILI9325_WriteReg(R13, 0x0000);
Delay_mS(10);
ILI9325_WriteReg(R10, 0x0082);
}
/*******************************************************************************
* Function Name : ILI9325_ExitSleep
* Description : LCD 退出休眠模式
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_ExitSleep(void) {
ILI9325_WriteReg(R10, 0x0080);
ILI9325_WriteReg(R11, 0x0000);
ILI9325_WriteReg(R12, 0x0000);
ILI9325_WriteReg(R13, 0x0000);
Delay_mS(10);
ILI9325_WriteReg(R10, 0x1490);
ILI9325_WriteReg(R11, 0x0224);
Delay_mS(10);
ILI9325_WriteReg(R12, 0x001A);
Delay_mS(10);
ILI9325_WriteReg(R13, 0x1100);
ILI9325_WriteReg(R29, 0x0011);
Delay_mS(10);
ILI9325_WriteReg(R7, 0x0133);
}
/*******************************************************************************
* Function Name : ILI9325_SetPixel
* Description : 在指定的 x,y 坐標描點
* Input : -x: 指定描點坐標 x 值
* -y: 指定描點坐標 y 值
* -color: 描點顏色值
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_SetPixel(uint16_t x, uint16_t y, uint16_t color) {
ILI9325_SetDisplayWindow(x,y,x,y);
ILI9325_WriteGRAM(color);
}
/*******************************************************************************
* Function Name : ILI9325_RectangleFill
* Description : 顯示窗口內以指定顏色局部填充
* Input : -x: 指定起點坐標 x 值
* -y: 指定起點坐標 y 值
* -width: 指定填充寬度
* -hight: 指定填充高度
* -color: 指定填充顏色
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_RectangleFill(uint16_t x, uint16_t y, uint16_t width, uint16_t hight, uint16_t color) {
uint16_t i,j;
ILI9325_SetDisplayWindow(x, y, x+width-1, y+hight-1);
for(i=0; i<width; i++) {
for(j=0; j<hight; j++) {
ILI9325_WriteGRAM(color);
}
}
}
/*******************************************************************************
* Function Name : ILI9325_FillSCR
* Description : 顯示窗口全部以指定顏色填充
* Input : -color: 指定填充顏色
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_FillSCR(uint16_t color) {
uint16_t i,j;
ILI9325_SetDisplayWindow(0, 0, 319, 239);
for(i=0; i<320; i++) {
for(j=0; j<240; j++) {
ILI9325_WriteGRAM(color);
}
}
}
/*******************************************************************************
* Function Name : ILI9325_DrawBMP
* Description : 圖片顯示
* Input : -x: 指定起點坐標 x 值
* -y: 指定起點坐標 y 值
* -width: 指定圖片寬度
* -hight: 指定圖片高度
* -*pBmp: 圖片數據指針
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_DrawBMP(uint16_t x,uint16_t y,uint16_t width,uint16_t hight,const uint8_t *pBmp) {
uint16_t i,j;
uint16_t Data;
ILI9325_SetDisplayWindow(x, y, x+width-1, y+hight-1);
for(i=0; i<width; i++) {
for(j=0; j<hight; j++) {
Data = (*pBmp++)<<8;
Data = Data | (*pBmp++);
ILI9325_WriteGRAM(Data);
}
}
}
/*******************************************************************************
* Function Name : ILI9325_SetCursor
* Description : Sets the cursor position.
* Input : - Xpos: specifies the X position.
* - Ypos: specifies the Y position.
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_SetCursor(uint16_t x, uint16_t y) {
ILI9325_SetDisplayWindow(x, y, x, y);
//ILI9325_WriteReg(R20, x);
//ILI9325_WriteReg(R21, y);
}
/*******************************************************************************
* Function Name : ILI9325_BGR2RGB
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
uint16_t ILI9325_BGR2RGB(uint16_t BGR_Code) {
uint16_t r, g, b;
r = BGR_Code & 0x1f;
g = (BGR_Code>>5) & 0x3f;
b = (BGR_Code>>11) & 0x1f;
return( (r<<11) + (g<<5) + (b<<0) );
}
/*******************************************************************************
* Function Name : ILI9325_ReadRegister
* Description : Get the data of the appointed register.
* Input :
* Output :
* Return :
*******************************************************************************/
uint16_t ILI9325_ReadRegister(uint16_t LCD_Reg) {
//寫索引寄存器
ILI9325_WriteIndex(LCD_Reg);
return(ILI9325_ReadData());
}
/*******************************************************************************
* Function Name : CheckController
* Description : 讀取 LCD 標示字符串
* Input :
* Output :
* Return : int 類型標示字符串代碼
*******************************************************************************/
uint16_t CheckController(void) {
return(ILI9325_ReadRegister(R0));
}
/*******************************************************************************
* Function Name : ILI9325_GetPointRGB 獲得指定像素點的顏色數據
* Description : Get the color data of the appointed pixel.
* Input :
* Output :
* Return :
*******************************************************************************/
uint16_t ILI9325_GetPointRGB(uint16_t x,uint16_t y) {
//ILI9325_SetDisplayWindow(x, y, x, y);
ILI9325_SetCursor(x,y);
return(ILI9325_BGR2RGB(ILI9325_ReadRegister(R22)));
}
/*******************************************************************************
* Function Name : ILI9325_ClearLine
* Description : Clears the selected line.
* Input : - Line: the Line to be cleared.
* This parameter can be one of the following values:
* - Linex: where x can be 0..19
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_ClearLine(uint8_t Line) {
//ILI9325_DisplayStringLine(Line, " ");
}
/*******************************************************************************
* Function Name : ILI9325_SetTextColor
* Description : Sets the Text color.
* Input : - Color: specifies the Text color code RGB(5-6-5).
* Output : - TextColor: Text color global variable used by LCD_DrawChar
* and LCD_DrawPicture functions.
* Return : None
*******************************************************************************/
void ILI9325_SetTextColor(uint16_t Color) {
ILI9325.TextColor = Color;
}
/*******************************************************************************
* Function Name : ILI9325_SetBackColor
* Description : Sets the Background color.
* Input : - Color: specifies the Background color code RGB(5-6-5).
* Output : - BackColor: Background color global variable used by
* LCD_DrawChar and LCD_DrawPicture functions.
* Return : None
*******************************************************************************/
void ILI9325_SetBackColor(uint16_t Color) {
ILI9325.BackColor = Color;
}
/******************************************************************
- 功能描述:將一個32位的變量dat轉為字符串,比如把1234轉為"1234"
- 參數說明:dat:帶轉的long型的變量
str:指向字符數組的指針,轉換后的字節串放在其中
- 返回說明:無
******************************************************************/
void u32tostr(uint32_t dat,uint8_t *str) {
int8_t temp[20];
uint8_t i=0,j=0;
i=0;
while(dat){
temp[i]=dat%10+0x30;
i++;
dat/=10;
}
j=i;
for(i=0;i<j;i++) {
str[i]=temp[j-i-1];
}
if(!i) {str[i++]='0';}
str[i]=0;
}
/******************************************************************
- 功能描述:將一個字符串轉為32位的變量,比如"1234"轉為1234
- 參數說明:str:指向待轉換的字符串
- 返回說明:轉換后的數值
******************************************************************/
unsigned long strtou32(unsigned char *str) {
uint32_t temp=0;
uint32_t fact=1;
uint8_t len=StrLength(str);
uint8_t i;
for(i=len;i>0;i--) {
temp+=((str[i-1]-0x30)*fact);
fact*=10;
}
return temp;
}
/*******************************************************************************
* Function Name : StrLength
* Description : Returns length of string.
* Input : - Str: Character Pointer.
* Output : None
* Return : String length.
*******************************************************************************/
static uint32_t StrLength(uint8_t *Str) {
uint32_t Index = 0;
/* Increment the Index unless the end of string */
for(Index = 0; *Str != '\0'; Str++, Index++);
return Index;
}
/*******************************************************************************
* Function Name : ILI9325_DrawChar
* Description : Draws a character on LCD.
* Input : - Xpos: the Line where to display the character shape.
* This parameter can be one of the following values:
* - Linex: where x can be 0..19
* - Ypos: start column address.
* - c: pointer to the character data.
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_DrawChar_8x16(uint16_t x, uint16_t y, uint8_t *c) {
uint16_t i=0,j=0,str=0;
uint16_t OffSet=0;
OffSet = (*c - 32)*16;//尋找ASCII_Table[]中相應字符的點陣數據
/*pAscii傳過來的是該字符的ASCII碼數字表示(參看ASCII表,有嚴格
順序表示),減32是因為第0~31號是控制字符,第32號為“空格”字符
除以16是因為在ASCII_Table[]中的每個字符點陣為16個字節表示*/
ILI9325_SetDisplayWindow(x, y, x+7, y+15);
for(i=0;i<16;i++) {
str = *(ascii_8x16 + OffSet + i);
for(j=0;j<8;j++) {
if(str & (0x80>>j)) {
ILI9325_WriteGRAM(ILI9325.TextColor);
}
else {
ILI9325_WriteGRAM(ILI9325.BackColor);
}
}
}
}
/*******************************************************************************
* Function Name : ILI9325_DisplayChar
* Description : Displays one character .
* Input : - Line: the Line where to display the character shape .
* This parameter can be one of the following values:
* - Linex: where x can be 0..19
* - Column: start column address.
* - Ascii: character ascii code
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_DisplayChar_8x16(uint16_t x, uint16_t y, uint8_t *Ascii) {
while(*Ascii != 0){
ILI9325_DrawChar_8x16(x,y,Ascii);
x += 8;
Ascii += 1;
}
}
/*******************************************************************************
* Function Name : ILI9325_DisplayChar
* Description : Displays one character .
* Input : - Line: the Line where to display the character shape .
* This parameter can be one of the following values:
* - Linex: where x can be 0..19
* - Column: start column address.
* - Ascii: character ascii code
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_DrawChar_16x16(uint16_t x,uint16_t y,uint16_t Num){
uint8_t i=0,j=0;
uint16_t OffSet=0;
uint16_t str=0;
OffSet = Num*32;//尋找ASCII_Table[]中相應字符的點陣數據
/*pAscii傳過來的是該字符的ASCII碼數字表示(參看ASCII表,有嚴格
順序表示),減32是因為第0~31號是控制字符,第32號為“空格”字符
除以16是因為在ASCII_Table[]中的每個字符點陣為16個字節表示*/
ILI9325_SetDisplayWindow(x,y,x+15,y+15);
for(i = 0; i < 16; i++){
str = ((uint16_t)(*(china_16x16 + OffSet + i*2)<<8)+*(china_16x16 + OffSet + i*2+1));
for(j=0;j<16;j++) {
if(str & (0x8000>>j)) {
ILI9325_WriteGRAM(ILI9325.TextColor);
}
else {
ILI9325_WriteGRAM(ILI9325.BackColor);
}
}
}
}
/*******************************************************************************
* Function Name : ILI9325_DrawChar
* Description : Draws a character on LCD.
* Input : - Xpos: the Line where to display the character shape.
* This parameter can be one of the following values:
* - Linex: where x can be 0..19
* - Ypos: start column address.
* - c: pointer to the character data.
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_DrawChar_16x24(uint16_t x, uint16_t y, uint8_t *c) {
uint8_t i=0,j=0;
uint16_t str=0;
uint16_t OffSet=0;
OffSet = (*c - 32)*48;//尋找ASCII_Table[]中相應字符的點陣數據
/*pAscii傳過來的是該字符的ASCII碼數字表示(參看ASCII表,有嚴格
順序表示),減32是因為第0~31號是控制字符,第32號為“空格”字符
除以16是因為在ASCII_Table[]中的每個字符點陣為16個字節表示*/
ILI9325_SetDisplayWindow(x, y, x+15, y+23);
for(i=0;i<24;i++) {
str = ((uint16_t)(*(ascii_16x24 + OffSet + i*2)<<8))+(*(ascii_16x24 + OffSet + i*2+1));
for(j=0;j<16;j++) {
if(str & (0x8000>>j)) {
ILI9325_WriteGRAM(ILI9325.TextColor);
}
else {
ILI9325_WriteGRAM(ILI9325.BackColor);
}
}
}
}
/*******************************************************************************
* Function Name : ILI9325_DisplayChar
* Description : Displays one character .
* Input : - Line: the Line where to display the character shape .
* This parameter can be one of the following values:
* - Linex: where x can be 0..19
* - Column: start column address.
* - Ascii: character ascii code
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_DisplayChar_16x24(uint16_t x, uint16_t y, uint8_t *Ascii) {
while(*Ascii != 0){
ILI9325_DrawChar_16x24(x,y,Ascii);
x += 16;
Ascii += 1;
}
}
/*******************************************************************************
* Function Name : ILI9325_DisplayChar
* Description : Displays one character .
* Input : - Line: the Line where to display the character shape .
* This parameter can be one of the following values:
* - Linex: where x can be 0..19
* - Column: start column address.
* - Ascii: character ascii code
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_DrawChar_24x24(uint16_t x,uint16_t y,uint16_t Num){
uint8_t i=0,j=0;
uint16_t OffSet=0;
uint32_t str=0;
OffSet = Num*72;//尋找ASCII_Table[]中相應字符的點陣數據
/*pAscii傳過來的是該字符的ASCII碼數字表示(參看ASCII表,有嚴格
順序表示),減32是因為第0~31號是控制字符,第32號為“空格”字符
除以16是因為在ASCII_Table[]中的每個字符點陣為16個字節表示*/
ILI9325_SetDisplayWindow(x,y,x+23,y+23);
for(i = 0; i < 24; i++){
str = ((uint32_t)(*(china_24x24 + OffSet + i*3)<<16))+((uint16_t)(*(china_24x24 + OffSet + i*3+1)<<8))+(*(china_24x24 + OffSet + i*3+2));
for(j=0;j<24;j++) {
if(str & (0x00800000>>j)) {
ILI9325_WriteGRAM(ILI9325.TextColor);
}
else {
ILI9325_WriteGRAM(ILI9325.BackColor);
}
}
}
}
/*******************************************************************************
* Function Name : ILI9325_DisplayChar
* Description : Displays one character .
* Input : - Line: the Line where to display the character shape .
* This parameter can be one of the following values:
* - Linex: where x can be 0..19
* - Column: start column address.
* - Ascii: character ascii code
* Output : None
* Return : None
******************************************************************************
void ILI9325_DisplayChar_24x24(uint16_t x, uint16_t y, uint8_t *Ascii) {
while(*Ascii != 0){
ILI9325_DrawChar_24x24(x,y,Ascii);
x += 24;
Ascii += 1;
}
}
*/
/*******************************************************************************
* Function Name : ILI9325_DisplayChar
* Description : Displays one character .
* Input : - Line: the Line where to display the character shape .
* This parameter can be one of the following values:
* - Linex: where x can be 0..19
* - Column: start column address.
* - Ascii: character ascii code
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_DrawChar_24x48(uint16_t x,uint16_t y,uint8_t *c){
unsigned char i=0,j=0;
unsigned long str=0;
unsigned short OffSet=0;
OffSet = (*c - 32)*144;//尋找ASCII_Table[]中相應字符的點陣數據
/*pAscii傳過來的是該字符的ASCII碼數字表示(參看ASCII表,有嚴格
順序表示),減32是因為第0~31號是控制字符,第32號為“空格”字符
除以16是因為在ASCII_Table[]中的每個字符點陣為16個字節表示*/
ILI9325_SetDisplayWindow(x,y,x+23,y+47);
for(i = 0; i < 48; i++){
str = ((uint32_t)(*(ascii_24x48 + OffSet + i*3)<<16))+((uint16_t)(*(ascii_24x48 + OffSet + i*3+1)<<8))+(*(ascii_24x48 + OffSet + i*3+2));
for(j=0;j<24;j++) {
if(str & (0x00800000>>j)) {
ILI9325_WriteGRAM(ILI9325.TextColor);
}
else {
ILI9325_WriteGRAM(ILI9325.BackColor);
}
}
}
}
/*******************************************************************************
* Function Name : ILI9325_DisplayChar
* Description : Displays one character .
* Input : - Line: the Line where to display the character shape .
* This parameter can be one of the following values:
* - Linex: where x can be 0..19
* - Column: start column address.
* - Ascii: character ascii code
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_DisplayChar_24x48(uint16_t x, uint16_t y, uint8_t *Ascii) {
while(*Ascii != 0){
ILI9325_DrawChar_24x48(x,y,Ascii);
x += 24;
Ascii += 1;
}
}
/*******************************************************************************
* Function Name : ILI9325_Bre_Line
* Description : Bresenham 畫線程序
* Input : - x1: 指定的畫線起點 x 坐標
* - y1: 指定的畫線起點 y 坐標
* - x2: 指定的畫線終點 x 坐標
* - y2: 指定的畫線終點 y 坐標
* - color: 畫線顏色
* - type: 類型
* Output : None
* Return : None
*******************************************************************************/
void ILI9325_Bre_Line(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t color,uint16_t type) {
int16_t dx,dy,e,count = 0;
dx=x2-x1;
dy=y2-y1;
if(dx>=0) {
if(dy >= 0) { // dy>=0
if(dx>=dy) { // 1/8 octant
e=dy-dx/2;
while(x1<=x2) {
count++;
if(type != 0){
if(count%2)
ILI9325_SetPixel(x1,y1,ILI9325.BackColor);
else
ILI9325_SetPixel(x1,y1,color);
}
else
ILI9325_SetPixel(x1,y1,color);
if(e>0){
y1+=1;
e-=dx;
}
x1+=1;
e+=dy;
}
}
else { // 2/8 octant
e=dx-dy/2;
while(y1<=y2) {
count++;
if(type != 0){
if(count%2)
ILI9325_SetPixel(x1,y1,ILI9325.BackColor);
else
ILI9325_SetPixel(x1,y1,color);
}
else
ILI9325_SetPixel(x1,y1,color);
if(e>0){
x1+=1;
e-=dy;
}
y1+=1;
e+=dx;
}
}
}
else { // dy<0
dy=-dy; // dy=abs(dy)
if(dx>=dy) { // 8/8 octant
e=dy-dx/2;
while(x1<=x2) {
count++;
if(type != 0){
if(count%2)
ILI9325_SetPixel(x1,y1,ILI9325.BackColor);
else
ILI9325_SetPixel(x1,y1,color);
}
else
ILI9325_SetPixel(x1,y1,color);
if(e>0){
y1-=1;
e-=dx;
}
x1+=1;
e+=dy;
}
}
else { // 7/8 octant
e=dx-dy/2;
while(y1>=y2) {
count++;
if(type != 0){
if(count%2)
ILI9325_SetPixel(x1,y1,ILI9325.BackColor);
else
ILI9325_SetPixel(x1,y1,color);
}
else
ILI9325_SetPixel(x1,y1,color);
if(e>0){
x1+=1;
e-=dy;
}
y1-=1;
e+=dx;
}
}
}
}
else { //dx<0
dx=-dx; //dx=abs(dx)
if(dy >= 0) { // dy>=0
if(dx>=dy) { // 4/8 octant
e=dy-dx/2;
while(x1>=x2) {
count++;
if(type != 0){
if(count%2)
ILI9325_SetPixel(x1,y1,ILI9325.BackColor);
else
ILI9325_SetPixel(x1,y1,color);
}
else
ILI9325_SetPixel(x1,y1,color);
if(e>0){
y1+=1;
e-=dx;
}
x1-=1;
e+=dy;
}
}
else { // 3/8 octant
e=dx-dy/2;
while(y1<=y2) {
count++;
if(type != 0){
if(count%2)
ILI9325_SetPixel(x1,y1,ILI9325.BackColor);
else
ILI9325_SetPixel(x1,y1,color);
}
else
ILI9325_SetPixel(x1,y1,color);
if(e>0){
x1-=1;
e-=dy;
}
y1+=1;
e+=dx;
}
}
}
else { // dy<0
dy=-dy; // dy=abs(dy)
if(dx>=dy) { // 5/8 octant
e=dy-dx/2;
while(x1>=x2) {
count++;
if(type != 0){
if(count%2)
ILI9325_SetPixel(x1,y1,ILI9325.BackColor);
else
ILI9325_SetPixel(x1,y1,color);
}
else
ILI9325_SetPixel(x1,y1,color);
if(e>0){
y1-=1;
e-=dx;
}
x1-=1;
e+=dy;
}
}
else { // 6/8 octant
e=dx-dy/2;
while(y1>=y2) {
count++;
if(type != 0){
if(count%2)
ILI9325_SetPixel(x1,y1,ILI9325.BackColor);
else
ILI9325_SetPixel(x1,y1,color);
}
else
ILI9325_SetPixel(x1,y1,color);
if(e>0){
x1-=1;
e-=dy;
}
y1-=1;
e+=dx;
}
}
}
}
}
復制代碼
作者:
waitopen
時間:
2017-6-18 00:38
感謝分享,這個是我目前看到最全的函數
作者:
Randy510
時間:
2017-11-29 09:57
感謝樓主的無私分享
作者:
cnc2020
時間:
2018-2-12 22:40
感謝樓主
作者:
cnc2020
時間:
2018-3-10 15:33
感謝樓主的無私分享
作者:
h415746969
時間:
2018-7-4 13:31
非常感謝,正需要呢,謝謝。
作者:
h415746969
時間:
2018-7-6 17:01
你好我下載了你的文檔,,你的代碼少了一個字庫頭文件沒法用呀,能否發一下。謝謝。。
415746969@qq.com
作者:
gdgn_526345
時間:
2018-8-26 21:18
感謝,感謝樓主的分享!
作者:
endlesscode
時間:
2018-11-16 18:21
少了個頭文件啊 #include "mFONT.h"
作者:
電控mmbd
時間:
2019-11-19 13:42
白下了,少文件啊
歡迎光臨 (http://www.zg4o1577.cn/bbs/)
Powered by Discuz! X3.1
主站蜘蛛池模板:
一区二区三区日
|
成人在线免费观看
|
夜夜夜夜夜夜曰天天天
|
日本免费视频在线观看
|
久久丝袜
|
色偷偷噜噜噜亚洲男人
|
精品欧美乱码久久久久久
|
日本免费一区二区三区四区
|
中文字幕第九页
|
天天天操天天天干
|
久久精品免费观看
|
国产激情偷乱视频一区二区三区
|
中文字幕在线观看国产
|
国产精品久久久久久久粉嫩
|
午夜久久久
|
精品久久久久久久
|
www.狠狠操
|
亚洲精品视频免费观看
|
日韩在线
|
国产精品69毛片高清亚洲
|
国产毛片久久久久久久久春天
|
91精品国产91久久久久久吃药
|
久久一二区
|
99精品国产一区二区三区
|
久久精品无码一区二区三区
|
亚洲综合日韩精品欧美综合区
|
精品在线一区
|
欧洲一区二区三区
|
美女视频一区二区三区
|
国产精品视频免费观看
|
欧美日韩在线精品
|
国产一区二区在线免费观看
|
日韩中文字幕
|
久久综合入口
|
国产精品美女www爽爽爽视频
|
欧美黑人一级爽快片淫片高清
|
av黄色片
|
91久久国产综合久久
|
精品国产欧美日韩不卡在线观看
|
精品成人免费视频
|
亚洲免费精品一区
|