C文件
#define _LCD_ODEV_C_
#include "LCD_odev.h"
#include "fonts.h" //ASCII×Ö·ûÐÍ×Ö¿â
void LCD_Delay(unsigned short int i)
{
while(i--);
}
void LCD_wt8bitData(unsigned char da) //·¢ËÍÊý¾Ý-8λ²ÎÊý
{
LCD_CS_en();
LCD_DC_data();
SPI1_ReadWriteByte(da);
LCD_CS_dis();
}
void LCD_wt16bitData(unsigned short int da)
{
LCD_CS_en();
LCD_DC_data();
SPI1_ReadWriteByte(da>>8);
SPI1_ReadWriteByte(da&0xFF);
LCD_CS_dis();
}
void LCD_wtREG(unsigned char cmd)
{
LCD_CS_en();
LCD_DC_reg();
SPI1_ReadWriteByte(cmd);
LCD_CS_dis();
}
void LCD_wtREG_DATA(unsigned char reg,unsigned short int da)
{
LCD_wtREG(reg);
LCD_wt16bitData(da);
}
unsigned char LCD_Read_Data(void)
{
LCD_CS_en();
LCD_DC_data();
//´Ë´¦½ûÖ¹disbaleµôCS½Å£¬CS½Å±ØÐëһֱʹÄÜ£¬·ñÔò¶ÁÈ¡µÄÊý¾ÝÈ«ÊÇ0xff
return SPI1_ReadWriteByte(0xFF);
}
void ILI9341_io_Init() // ÆäËûÒý½Å³õʼ»¯
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB , ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA , ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
// -------------------------------
void LCD_odev_init(void)
{
ILI9341_io_Init();
lcddev.width = LCD_Wide;
lcddev.height = LCD_High;
LCD_RST_Clr();
delay_ms(20);
LCD_RST_Set();
delay_ms(20);
//LCD_BLK_Set();
//************* Start Initial Sequence **********//
LCD_wtREG(0xCF);
LCD_wt8bitData(0x00);
LCD_wt8bitData(0xD9);
LCD_wt8bitData(0X30);
LCD_wtREG(0xED);
LCD_wt8bitData(0x64);
LCD_wt8bitData(0x03);
LCD_wt8bitData(0X12);
LCD_wt8bitData(0X81);
LCD_wtREG(0xE8);
LCD_wt8bitData(0x85);
LCD_wt8bitData(0x10);
LCD_wt8bitData(0x78);
LCD_wtREG(0xCB);
LCD_wt8bitData(0x39);
LCD_wt8bitData(0x2C);
LCD_wt8bitData(0x00);
LCD_wt8bitData(0x34);
LCD_wt8bitData(0x02);
LCD_wtREG(0xF7);
LCD_wt8bitData(0x20);
LCD_wtREG(0xEA);
LCD_wt8bitData(0x00);
LCD_wt8bitData(0x00);
LCD_wtREG(0xC0); //Power control
LCD_wt8bitData(0x21); //VRH[5:0]
LCD_wtREG(0xC1); //Power control
LCD_wt8bitData(0x12); //SAP[2:0];BT[3:0]
LCD_wtREG(0xC5); //VCM control
LCD_wt8bitData(0x32);
LCD_wt8bitData(0x3C);
LCD_wtREG(0xC7); //VCM control2
LCD_wt8bitData(0XC1);
LCD_wtREG(0x36); // Memory Access Control
LCD_wt8bitData(0x68);
LCD_wtREG(0x2A); //ÐеØÖ·ÉèÖÃ
LCD_wt8bitData(0x00);
LCD_wt8bitData(0x00);
LCD_wt8bitData(0x01);
LCD_wt8bitData(0x3f);
LCD_wtREG(0x2B); //ÁеØÖ·ÉèÖÃ
LCD_wt8bitData(0x00);
LCD_wt8bitData(0x00);
LCD_wt8bitData(0x00);
LCD_wt8bitData(0xef);
LCD_wtREG(0x3A);
LCD_wt8bitData(0x55);
LCD_wtREG(0xB1);
LCD_wt8bitData(0x00);
LCD_wt8bitData(0x18);
LCD_wtREG(0xB6); // Display Function Control
LCD_wt8bitData(0x0A);
LCD_wt8bitData(0xA2);
LCD_wtREG(0xF2); // 3Gamma Function Disable
LCD_wt8bitData(0x00);
LCD_wtREG(0x26); //Gamma curve selected
LCD_wt8bitData(0x01);
LCD_wtREG(0xE0); //Set Gamma
LCD_wt8bitData(0x0F);
LCD_wt8bitData(0x20);
LCD_wt8bitData(0x1E);
LCD_wt8bitData(0x09);
LCD_wt8bitData(0x12);
LCD_wt8bitData(0x0B);
LCD_wt8bitData(0x50);
LCD_wt8bitData(0XBA);
LCD_wt8bitData(0x44);
LCD_wt8bitData(0x09);
LCD_wt8bitData(0x14);
LCD_wt8bitData(0x05);
LCD_wt8bitData(0x23);
LCD_wt8bitData(0x21);
LCD_wt8bitData(0x00);
LCD_wtREG(0XE1); //Set Gamma
LCD_wt8bitData(0x00);
LCD_wt8bitData(0x19);
LCD_wt8bitData(0x19);
LCD_wt8bitData(0x00);
LCD_wt8bitData(0x12);
LCD_wt8bitData(0x07);
LCD_wt8bitData(0x2D);
LCD_wt8bitData(0x28);
LCD_wt8bitData(0x3F);
LCD_wt8bitData(0x02);
LCD_wt8bitData(0x0A);
LCD_wt8bitData(0x08);
LCD_wt8bitData(0x25);
LCD_wt8bitData(0x2D);
LCD_wt8bitData(0x0F);
LCD_wtREG(0x11); //Exit Sleep
delay_ms(120);
LCD_wtREG(0x29); //Display on
lcddev.bled = BLEDoff;
}
unsigned short int LCD_Read_Point(unsigned short int cx,unsigned short int cy)
{
unsigned char r=0,g=0,b=0;
LCD_set_windows(cx,cy,cx,cy);
LCD_wtREG(0x2E);
LCD_Read_Data(); //Ö»ÐèÒªÖ´ÐÐÒ»´Î¿Õ¶ÁÈ¡
r = LCD_Read_Data();
g = LCD_Read_Data();
b = LCD_Read_Data();
LCD_wtREG(0x2C); //¹Ø¼ü²½Ö裬±ØÐëÒªÓÐ
return (((r>>3)<<11)|((g>>2)<<5)|(b>>3));
}
void LCD_restar(void) //Èí¼þ¸´Î»Ö¸Áî²»ÄÜÔÚÍ˳ö˯ÃßÐòÁÐʱ·¢ËÍ
{
LCD_wtREG(0x01);
delay_ms(250);
}
void LCD_inSleep(void)
{
LCD_wtREG(0x28); //display TURNOFF
delay_ms(50);
LCD_wtREG(0x10); //sleep ENABLE
LCD_BLK_Clr();
}
void LCD_outSleep(void)
{
LCD_wtREG(0x11); //sleep DISABLE
delay_ms(50);
LCD_wtREG(0x29); //display TURNON
LCD_BLK_Set();
}
unsigned char LCD_onDisp(void)
{
LCD_wtREG(0x29); //display TURNON
return BLEDon;
}
unsigned char LCD_offDisp(void)
{
LCD_wtREG(0x28); //display TURNOFF
return BLEDoff;
}
/****************************************************
*** º¯Êý¹¦ÄÜ£ºÇóÏÔʾµÄµãÕóÃæ»ý
*** Èë¿Ú²ÎÊý£ºm:ºá×ø±ê
*** n:×Ý×ø±ê
****************************************************/
//m^nº¯Êý
//·µ»ØÖµ:m^n´Î·½.
unsigned long LCD_Pow(unsigned char m,unsigned char n)
{
unsigned long result=1;
while(n--)result*=m;
return result;
}
/****************************************************
*** º¯Êý¹¦ÄÜ£ºÉèÖùâ±êλÖ㬼´ÉèÖÃÏÔʾµÄÆðʼ×ø±ê
*** Èë¿Ú²ÎÊý£ºXpos:ºá×ø±ê
*** Ypos:×Ý×ø±ê
****************************************************/
void LCD_SetCursor(unsigned short int Xpos, unsigned short int Ypos)
{
LCD_wtREG_DATA(Xreg ,Xpos);
LCD_wtREG_DATA(Yreg ,Ypos);
}
/****************************************************
*** º¯Êý¹¦ÄÜ£ºÉèÖÃÏÔʾ´°¿Ú£¬¼´´´½¨Ò»¸öÏÔʾ´°¿Ú
*** Èë¿Ú²ÎÊý£ºx1,y1-->Æðʼ×ø±ê
*** x2,y2-->ÖÕµã×ø±ê
****************************************************/
void LCD_set_windows(unsigned short int x1,unsigned short int y1,unsigned short int x2,unsigned short int y2)
{
LCD_wtREG(0x2a);
LCD_wt16bitData(x1);
LCD_wt16bitData(x2);
LCD_wtREG(0x2b);
LCD_wt16bitData(y1);
LCD_wt16bitData(y2);
LCD_wtREG(0x2C);