ILI93xx.c ( File view )

  • By Karma_w 2015-06-09
  • View(s):16
  • Download(s):1
  • Point(s): 1
			#include "lcd.h"
#include "stdlib.h"
#include "font.h" 
#include "usart.h"
#include "delay.h"	 
//////////////////////////////////////////////////////////////////////////////////	 
//ֻѧϰʹãδɣκ;
//Mini STM32
//2.4/2.8TFTҺ	  
//֧ICͺŰ:ILI9341/ILI9325/RM68021/ILI9320/ILI9328/LGDP4531/LGDP4535/SPFD5408/SSD1289/1505/B505/C505
//ԭ@ALIENTEK
//̳:www.openedv.com
//:2011/1/13
//汾V1.7
//ȨУؾ
//Copyright(C) ԭ 2009-2019
//All rights reserved
//********************************************************************************
//V1.2޸˵
//֧SPFD5408,ҺIDֱӴӡHEXʽ.鿴LCDIC.
//V1.3
//˿IO֧
//޸˱ƵļԣV1.8ԺĿ汾
//1.8汾֮ǰ(1.8)Һģ,޸LCD_InitLCD_LED=1;ΪLCD_LED=1;
//V1.4
//޸LCD_ShowCharʹû㹦ַܻ
//˺ʾ֧
//V1.5 20110730
//1,޸B505Һɫbug.
//2,޸˿IO÷ʽ.
//V1.6 20111116
//1,LGDP4535Һ֧
//V1.7 20120713
//1,LCD_RD_DATA
//2,ӶILI9341֧
//3,ILI9325Ķ
//4,LCD_Scan_Dir(ʹ)	  
//6,޸˲ԭĺ,Ӧ9341IJ
//////////////////////////////////////////////////////////////////////////////////
	   
					 
//ɫ,ɫ
u16 POINT_COLOR = 0x0000,BACK_COLOR = 0xFFFF;  
u16 DeviceCode;	 					    

#if LCD_FAST_IO==1 //IO
//дĴ
//data:Ĵֵ
void LCD_WR_REG(u8 data)
{
 
	LCD_RS_CLR;//дַ  
 	LCD_CS_CLR; 
	DATAOUT(data); 
	LCD_WR_CLR; 
	LCD_WR_SET; 
 	LCD_CS_SET;   

}
#else//IO
//дĴ
//data:Ĵֵ
void LCD_WR_REG(u8 data)
{
 
	LCD_RS=0;//дַ  
 	LCD_CS=0; 
	DATAOUT(data); 
	LCD_WR=0; 
	LCD_WR=1; 
 	LCD_CS=1;   

} 	
#endif		   
//LCD
//ֵ:ֵ
u16 LCD_RD_DATA(void)
{
										   
	u16 t;
 	GPIOB->CRL=0X88888888; //PB0-7  
	GPIOB->CRH=0X88888888; //PB8-15 
	GPIOB->ODR=0X0000;     //ȫ0
#if LCD_FAST_IO==1 //IO
	LCD_RS_SET;
	LCD_CS_CLR;
	//ȡ(Ĵʱ,Ҫ2)
	LCD_RD_CLR;
	if(DeviceCode==0X8989)delay_us(2);//FOR 8989,ʱ2us					   
	LCD_RD_SET;
	t=DATAIN;  
	LCD_CS_SET; 
#else
	LCD_RS=1;
	LCD_CS=0;
	//ȡ(Ĵʱ,Ҫ2)
	LCD_RD=0;					   
	LCD_RD=1;
	t=DATAIN;  
	LCD_CS=1; 
#endif  
	GPIOB->CRL=0X33333333; //PB0-7  
	GPIOB->CRH=0X33333333; //PB8-15 
	GPIOB->ODR=0XFFFF;    //ȫ
	return t;  

}		    

//дĴ
//LCD_Reg:Ĵ
//LCD_RegValue:Ҫдֵ
void LCD_WriteReg(u8 LCD_Reg,u16 LCD_RegValue)
{
	
	LCD_WR_REG(LCD_Reg);  
	LCD_WR_DATA(LCD_RegValue);	    		 

}
	   
//Ĵ
//LCD_Reg:Ĵ
//ֵ:ֵ
u16 LCD_ReadReg(u8 LCD_Reg)
{
										   
 	LCD_WR_REG(LCD_Reg);  //дҪļĴ  
	return LCD_RD_DATA(); 

}  
 
//ʼдGRAM
void LCD_WriteRAM_Prepare(void)
{

	if(DeviceCode==0X9341)LCD_WR_REG(0x2C);//ILI93410X2Cʼ
	else LCD_WR_REG(R34);

}	
 
//LCDдGRAM
//RGB_Code:ɫֵ
void LCD_WriteRAM(u16 RGB_Code)
{
							    
	LCD_WR_DATA(RGB_Code);//дʮλGRAM

}
//ILI93xxΪGBRʽдʱΪRGBʽ
//ͨúת
//c:GBRʽɫֵ
//ֵRGBʽɫֵ
u16 LCD_BGR2RGB(u16 c)
{

	u16  r,g,b,rgb;   
	b=(c>>0)&0x1f;
	g=(c>>5)&0x3f;
	r=(c>>11)&0x1f;	 
	rgb=(b<<11)+(g<<5)+(r<<0);		 
	return(rgb);

}		 
//ȡijɫֵ	 
//x:0~239
//y:0~319
//ֵ:˵ɫ
u16 LCD_ReadPoint(u16 x,u16 y)
{

 	u16 r,g,b;
	if(x>=LCD_W||y>=LCD_H)return 0;			//˷Χ,ֱӷ		   
	LCD_SetCursor(x,y);
	if(DeviceCode==0X9341)LCD_WR_REG(0X2E);	//ILI9341ͶGRAMָ
	else LCD_WR_REG(R34);      		 		//ICͶGRAMָ
	GPIOB->CRL=0X88888888; //PB0-7  
	GPIOB->CRH=0X88888888; //PB8-15 
	GPIOB->ODR=0XFFFF;     //ȫ
#if LCD_FAST_IO==1 //IO
	LCD_RS_SET;
	LCD_CS_CLR;
	//ȡ(GRAMʱ,һΪٶ)	
	LCD_RD_CLR;	
  	delay_us(1);//ʱ1us					   
	LCD_RD_SET;
 	//dummy READ
	LCD_RD_CLR;					   
	delay_us(1);//ʱ1us					   
	LCD_RD_SET;
 	r=DATAIN;  
 	if(DeviceCode==0X9341)
	{
	 
		LCD_RD_CLR;					   
	 	LCD_RD_SET;
		b=DATAIN;//ȡɫֵ  	  
		g=r&0XFF;//9341,һζȡRGֵ,Rǰ,Gں,ռ8λ
		g<<=8;
	
}	 
	LCD_CS_SET;
#else
	LCD_RS=1;
	LCD_CS=0;
	//ȡ(GRAMʱ,Ҫ2)
	LCD_RD=0;					   
 	LCD_RD=1;
 	//dummy READ
	LCD_RD=0;					   
 	LCD_RD=1;
	r=DATAIN;  
 	if(DeviceCode==0X9341)
	{
	 
		LCD_RD=0;					   
	 	LCD_RD=1;
		b=DATAIN;//ȡɫֵ  	  
		g=r&0XFF;//9341,һζȡRGֵ,Rǰ,Gں,ռ8λ
		g<<=8;
	
}	
	LCD_CS=1;
#endif 
	GPIOB->CRL=0X33333333; //PB0-7  
	GPIOB->CRH=0X33333333; //PB8-15 
	GPIOB->ODR=0XFFFF;    //ȫ  
	if(DeviceCode==0X9325||DeviceCode==0X4535||DeviceCode==0X4531||DeviceCode==0X8989||DeviceCode==0XB505)return r;	//⼸ICֱӷɫֵ
	else if(DeviceCode==0X9341)return (((r>>11)<<11)|((g>>10)<<5)|(b>>11));						//ILI9341Ҫʽתһ
	else return LCD_BGR2RGB(r);																	//IC

}
//LCDʾ
void LCD_DisplayOn(void)
{
	
	if(DeviceCode==0X9341)LCD_WR_REG(0X29);	//ʾ
	else LCD_WriteReg(R7,0x0173); 			//ʾ

}	 
//LCDرʾ
void LCD_DisplayOff(void)
{
	   
	if(DeviceCode==0X9341)LCD_WR_REG(0X28);	//رʾ
	else LCD_WriteReg(R7, 0x0);//رʾ 

}   
//ùλ
//Xpos:
//Ypos:
__inline void LCD_SetCursor(u16 Xpos, u16 Ypos)
{

#if USE_HORIZONTAL==1 
	if(DeviceCode==0X8989)
	{

		Xpos=319-Xpos;
		LCD_WriteReg(0X4E, Ypos);
		LCD_WriteReg(0X4F, Xpos);
    
}else if(DeviceCode==0X9341)//9341,
	{
			 
		LCD_WR_REG(0x2B); 
		LCD_WR_DATA(Ypos>>8); 
		LCD_WR_DATA(Ypos&0XFF);			 
		LCD_WR_REG(0x2A); 
		LCD_WR_DATA(Xpos>>8); 
		LCD_WR_DATA(Xpos&0XFF);
	
}else
	{

		Xpos=319-Xpos;
		LCD_WriteReg(R32,Ypos);
		LCD_WriteReg(R33,Xpos);
	
}							   
#else
	if(DeviceCode==0X8989)
	{

		LCD_WriteReg(0X4E, Xpos);
		LCD_WriteReg(0X4F, Ypos);
    
}else if(DeviceCode==0X9341)
	{
		    
		LCD_WR_REG(0x2A); 
		LCD_WR_DATA(Xpos>>8); 
		LCD_WR_DATA(Xpos&0XFF);	 
		LCD_WR_REG(0x2B); 
		LCD_WR_DATA(Ypos>>8); 
		LCD_WR_DATA(Ypos&0XFF);
	
}else
	{

		LCD_WriteReg(R32, Xpos);
		LCD_WriteReg(R33, Ypos);
	
}						    
#endif

}
//LCDԶɨ跽
//ע:ܻܵ˺õӰ(9341),,
//һΪL2R_U2D,Ϊɨ跽ʽ,ܵʾ.
//0~78(嶨lcd.h)
//9320/9325/9328/4531/4535/1505/b505/8989/5408/9341ICѾʵʲ	   
void LCD_Scan_Dir(u8 dir)
{

	u16 regval=0;
	u8 dirreg=0;
#if USE_HORIZONTAL//ʹú
	switch(dir)//ת
	{

		case 0:dir=6;break;
		case 1:dir=7;break;
		case 2:dir=4;break;
		case 3:dir=5;break;
		case 4:dir=1;break;
		case 5:dir=0;break;
		case 6:dir=3;break;
		case 7:dir=2;break;	     
	
}
#endif
	if(DeviceCode==0x9341)//9341,
	{

		switch(dir)
		{

			case L2R_U2D://,ϵ
				regval|=(0<<7)|(0<<6)|(0<<5); 
				break;
			case L2R_D2U://,µ
				regval|=(1<<7)|(0<<6)|(0<<5); 
				break;
			case R2L_U2D://ҵ,ϵ
				regval|=(0<<7)|(1<<6)|(0<<5); 
				break;
			case R2L_D2U://ҵ,µ
				regval|=(1<<7)|(1<<6)|(0<<5); 
				break;	 
			case U2D_L2R://ϵ,
				regval|=(0<<7)|(0<<6)|(1<<5); 
				break;
			case U2D_R2L://ϵ,ҵ
				regval|=(0<<7)|(1<<6)|(1<<5); 
				break;
			case D2U_L2R://µ,
				regval|=(1<<7)|(0<<6)|(1<<5); 
				break;
			case D2U_R2L://µ,ҵ
				regval|=(1<<7)|(1<<6)|(1<<5); 
				break;	 
		
}
		dirreg=0X36;
 		regval|=0X08;//BGR   
		LCD_WriteReg(dirreg,regval);
		if(regval&0X20)
		{

 	 		LCD_WR_REG(0x2A); 
			LCD_WR_DATA(0);LCD_WR_DATA(0);
			LCD_WR_DATA(319>>8);LCD_WR_DATA(319&0XFF);
	 		LCD_WR_REG(0x2B); 
			LCD_WR_DATA(0);LCD_WR_DATA(0);
			LCD_WR_DATA(239>>8);LCD_WR_DATA(239&0XFF);
		
}else 
		{

 	 		LCD_WR_REG(0x2A); 
			LCD_WR_DATA(0);LCD_WR_DATA(0);
			LCD_WR_DATA(239>>8);LCD_WR_DATA(239&0XFF);
	 		LCD_WR_REG(0x2B); 
			LCD_WR_DATA(0);LCD_WR_DATA(0);
			LCD_WR_DATA(319>>8);LCD_WR_DATA(319&0XFF);
		
}  
 	
}else 
	{

		switch(dir)
		{

			case L2R_U2D://,ϵ
				regval|=(1<<5)|(1<<4)|(0<<3); 
				break;
			case L2R_D2U://,µ
				regval|=(0<<5)|(1<<4)|(0<<3); 
				break;
			case R2L_U2D://ҵ,ϵ
				regval|=(1<<5)|(0<<4)|(0<<3);
				break;
			case R2L_D2U://ҵ,µ
				regval|=(0<<5)|(0<<4)|(0<<3); 
				break;	 
			case U2D_L2R://ϵ,
				regval|=(1<<5)|(1<<4)|(1<<3); 
				break;
			case U2D_R2L://ϵ,ҵ
				regval|=(1<<5)|(0<<4)|(1<<3); 
				break;
			case D2U_L2R://µ,
				regval|=(0<<5)|(1<<4)|(1<<3); 
				break;
			case D2U_R2L://µ,ҵ
				regval|=(0<<5)|(0<<4)|(1<<3); 
				break;	 
		
}
		if(DeviceCode==0x8989)//8989 IC
		{

			dirreg=0X11;
			regval|=0X6040;	//65K   
	 	
}else//IC		  
		{

			dirreg=0X03;
			regval|=1<<12;  
		
}
		LCD_WriteReg(dirreg,regval);
	
}

}  
//
//x:0~239
//y:0~319
//POINT_COLOR:˵ɫ
void LCD_DrawPoint(u16 x,u16 y)
{

	LCD_SetCursor(x,y);		//ùλ 
	LCD_WriteRAM_Prepare();	//ʼдGRAM
	LCD_WR_DATA(POINT_COLOR); 

}  	  
//ʼlcd
//óʼԳʼILI93XXҺ,ǻILI9320!!!
//ͺŵоƬûв! 
void LCD_Init(void)
{
 
 	RCC->APB2ENR|=1<<3;//ʹPORTBʱ
 	RCC->APB2ENR|=1<<4;//ʹPORTCʱ

	RCC->APB2ENR|=1<<0;    //ʱ
	JTAG_Set(SWD_ENABLE);  //SWD
											 
	//PORTC6~10 	
	GPIOC->CRH&=0XFFFFF000;
	GPIOC->CRH|=0X00000333; 
	GPIOC->CRL&=0X00FFFFFF;
	GPIOC->CRL|=0X33000000;  
	GPIOC->ODR|=0X07C0; 	 
	//PORTB  	
	GPIOB->CRH=0X33333333;
	GPIOB->CRL=0X33333333; 	 
	GPIOB->ODR=0XFFFF;

	delay_ms(50); // delay 50 ms 
	LCD_WriteReg(0x0000,0x0001);
	delay_ms(50); // delay 50 ms 
	DeviceCode = LCD_ReadReg(0x0000);   
 	if(DeviceCode==0||DeviceCode==0XFFFF)//IDȷ
	{
	
		//
...
...
(Not finished, please download and read the complete file)
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
01.97 kB
01.97 kB
01.97 kB
adc.c2.48 kB2015-06-03 11:04
adc.h693.00 B2011-01-12 21:19
01.97 kB
dma.c1.31 kB2010-06-07 16:30
dma.h378.00 B2010-06-07 16:30
01.97 kB
exti.c1.71 kB2011-01-12 20:50
exti.h628.00 B2011-01-12 20:51
01.97 kB
key.c1.73 kB2013-04-03 14:18
key.h839.00 B2011-01-12 20:46
01.97 kB
FONT.H15.78 kB2010-06-21 11:18
ILI93xx.c38.75 kB2012-10-25 23:18
LCD.h8.94 kB2012-10-25 22:28
01.97 kB
led.c910.00 B2013-04-03 14:18
led.h288.00 B2010-05-27 17:30
01.97 kB
FONT.H15.78 kB2010-03-19 17:16
oled.c6.70 kB2011-01-12 21:02
oled.h1.59 kB2011-01-12 21:02
01.97 kB
rtc.c7.75 kB2011-01-12 22:04
rtc.h1.35 kB2011-01-12 21:15
01.97 kB
timer.c2.10 kB2015-06-03 11:38
timer.h724.00 B2011-01-12 20:59
01.97 kB
wdg.c2.04 kB2011-01-12 20:56
wdg.h756.00 B2011-01-12 20:56
01.97 kB
wkup.c1.85 kB2011-01-12 21:18
wkup.h728.00 B2011-01-12 21:18
keilkilll.bat399.00 B2011-04-23 10:24
README.TXT377.00 B2012-07-19 22:20
01.97 kB
01.97 kB
delay.c2.02 kB2013-04-03 12:14
delay.h905.00 B2013-04-03 12:14
01.97 kB
cortexm3_macro.h2.17 kB2009-05-07 14:42
stm32f10x_conf.h6.05 kB2009-05-07 14:42
stm32f10x_it.h4.42 kB2012-12-18 12:35
stm32f10x_map.h27.63 kB2009-05-07 14:42
stm32f10x_nvic.h18.75 kB2009-05-07 14:42
stm32f10x_type.h3.31 kB2009-05-07 14:42
sys.c6.69 kB2013-04-03 12:13
sys.h3.78 kB2013-04-03 12:13
01.97 kB
usart.c3.35 kB2015-06-03 11:28
usart.h1,010.00 B2015-06-03 10:57
01.97 kB
adc.crf34.24 kB2015-06-03 11:04
adc.d298.00 B2015-06-03 11:04
adc.o39.02 kB2015-06-03 11:04
delay.crf31.84 kB2015-06-03 10:54
delay.d286.00 B2015-06-03 10:54
delay.o37.45 kB2015-06-03 10:54
ili93xx.crf80.82 kB2015-06-03 10:57
ili93xx.d592.00 B2015-06-03 10:57
ili93xx.o79.87 kB2015-06-03 10:57
JLinkLog.txt59.16 kB2015-06-03 11:43
JLinkSettings.ini578.00 B2013-04-03 14:19
key.crf34.17 kB2015-06-03 10:54
key.d332.00 B2015-06-03 10:54
key.o40.01 kB2015-06-03 10:54
led.crf33.41 kB2015-06-03 10:54
led.d298.00 B2015-06-03 10:54
led.o38.35 kB2015-06-03 10:54
modbus.c5.44 kB2015-06-03 11:38
modbus.crf40.08 kB2015-06-03 11:38
modbus.d478.00 B2015-06-03 11:38
modbus.h404.00 B2015-06-03 10:54
modbus.o47.92 kB2015-06-03 11:38
rtc.crf41.95 kB2015-06-03 10:57
rtc.d434.00 B2015-06-03 10:57
rtc.o48.63 kB2015-06-03 10:57
STM32F10x.d28.00 B2015-06-03 10:54
STM32F10x.lst34.54 kB2015-06-03 10:54
stm32f10x.o5.58 kB2015-06-03 10:54
STM32F10x.s11.04 kB2009-12-22 19:16
sys.crf35.34 kB2015-06-03 10:54
sys.d264.00 B2015-06-03 10:54
sys.o42.51 kB2015-06-03 10:54
TEST.axf37.47 kB2015-06-03 11:43
TEST.build_log.htm1.36 kB2015-06-03 11:44
test.c601.00 B2015-06-03 11:41
test.crf51.11 kB2015-06-03 11:41
test.d792.00 B2015-06-03 11:41
TEST.hex13.17 kB2015-06-03 11:43
TEST.htm43.73 kB2015-06-03 11:43
TEST.lnp339.00 B2015-06-03 11:43
TEST.map64.78 kB2015-06-03 11:43
test.o54.43 kB2015-06-03 11:41
TEST.Opt2.03 kB2013-04-03 14:21
TEST.plg249.00 B2014-03-16 19:17
TEST.sct479.00 B2014-02-21 11:13
TEST.tra1.38 kB2014-02-21 11:13
TEST.Uv23.21 kB2013-04-03 14:21
TEST.uvgui.Administrator69.44 kB2013-04-03 14:20
TEST.uvgui.wjc72.16 kB2015-06-03 11:44
TEST.uvgui.WuJiChao67.42 kB2014-03-16 19:17
TEST.uvgui_wjc.bak72.08 kB2015-06-03 11:42
TEST.uvgui_WuJiChao.bak67.35 kB2014-02-21 11:21
TEST.uvopt10.12 kB2015-06-03 11:44
TEST.uvproj16.86 kB2015-06-03 11:42
TEST_Target8.60 kB2015-06-03 11:43
TEST_uvopt.bak10.12 kB2015-06-03 11:42
TEST_uvproj.bak17.39 kB2015-06-02 14:35
timer.crf38.84 kB2015-06-03 11:38
timer.d462.00 B2015-06-03 11:38
timer.o43.37 kB2015-06-03 11:38
usart.crf38.59 kB2015-06-03 11:28
usart.d388.00 B2015-06-03 11:28
usart.o43.36 kB2015-06-03 11:28
wdg.crf34.45 kB2015-06-03 10:54
wdg.d330.00 B2015-06-03 10:54
wdg.o41.05 kB2015-06-03 10:54
wkup.crf34.14 kB2015-06-03 10:54
wkup.d378.00 B2015-06-03 10:54
wkup.o41.15 kB2015-06-03 10:54
...
Sponsored links

ILI93xx.c (571.52 kB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D