www.pudn.com > STM32_ucos.rar > LCD.h, change:2010-11-17,size:8956b


#ifndef __LCD_H 
#define __LCD_H	 
 
#include "stm32f10x.h"	 
//#include "sys.h"	  
#include "stdlib.h" 
//2.4/2.8寸TFT液晶驱动(ILI9325/RM68021/ILI9320 Verision) 
//Mini STM32开发板 
//TFTLCD 驱动代码			  
//正点原子@ALIENTEK 
//2010/6/5 
 
//TFTLCD部分外要调用的函数		    
extern u16  POINT_COLOR;//默认红色     
extern u16  BACK_COLOR; //背景颜色.默认为白色 
//定义LCD的尺寸 
#define LCD_W 240 
#define LCD_H 320 
 
//从其它LCD上移过来和宏定义,还没有确定 
//#define Line0          0 
//#define Line1          24 
//#define Line2          48 
//#define Line3          72 
//#define Line4          96 
//#define Line5          120 
//#define Line6          144 
//#define Line7          168 
//#define Line8          192 
//#define Line9          216 
 
/*硬件相关的宏定义*/ 
 
//-----------------LCD端口定义----------------  
/********************************************************************************/ 
//#define	LCD_LED PCout(10) //LCD背光    		 PC10 
#define LCD_GPIO_LED_PORT              GPIOC 
#define LCD_GPIO_LED_CLK               RCC_APB2Periph_GPIOC   
#define LCD_GPIO_LED_PIN               GPIO_Pin_10 
 
//#define	Set_nWr	PCout(9)  //片选端口  	     PC9 
#define LCD_GPIO_CS_PORT              GPIOC 
#define LCD_GPIO_CS_CLK               RCC_APB2Periph_GPIOC  
#define LCD_GPIO_CS_PIN               GPIO_Pin_9 
 
//#define	LCD_RS	PCout(8)  //数据/命令        PC8	 
#define LCD_GPIO_RS_PORT              GPIOC 
#define LCD_GPIO_RS_CLK               RCC_APB2Periph_GPIOC   
#define LCD_GPIO_RS_PIN               GPIO_Pin_8 
 
//#define	Set_nWr	PCout(7)  //写数据			 PC7 
#define LCD_GPIO_NWR_PORT              GPIOC 
#define LCD_GPIO_NWR_CLK               RCC_APB2Periph_GPIOC   
#define LCD_GPIO_NWR_PIN               GPIO_Pin_7 
 
//#define	LCD_RD	PCout(6)  //读数据			 PC6 
#define LCD_GPIO_RD_PORT              GPIOC 
#define LCD_GPIO_RD_CLK               RCC_APB2Periph_GPIOC   
#define LCD_GPIO_RD_PIN               GPIO_Pin_6 
 
//16位数据所在端口 
//PB0~15,作为数据线 
//#define DATAOUT(x) GPIOB->ODR=x; //数据输出	 
//#define DATAIN     GPIOB->IDR;   //数据输入  
#define LCD_GPIO_DATA_PORT              GPIOB 
#define LCD_GPIO_DATA_CLK               RCC_APB2Periph_GPIOB  
#define LCD_GPIO_DATA_PIN               GPIO_Pin_All    
 
 
 
#define Set_LED  {GPIO_SetBits(LCD_GPIO_LED_PORT,LCD_GPIO_LED_PIN);} 
#define Clr_LED  {GPIO_ResetBits(LCD_GPIO_LED_PORT,LCD_GPIO_LED_PIN);}  
 
//#define Set_Cs  GPIOD->BSRR  = 0x00001000; 
#define Set_Cs  {GPIO_SetBits(LCD_GPIO_CS_PORT,LCD_GPIO_CS_PIN);} 
//#define Clr_Cs  GPIOD->BRR   = 0x00001000; 
#define Clr_Cs  {GPIO_ResetBits(LCD_GPIO_CS_PORT,LCD_GPIO_CS_PIN);} 
 
//#define Set_Rs  GPIOD->BSRR  = 0x00002000; 
#define Set_Rs  {GPIO_SetBits(LCD_GPIO_RS_PORT,LCD_GPIO_RS_PIN);} 
//#define Clr_Rs  GPIOD->BRR   = 0x00002000; 
#define Clr_Rs  {GPIO_ResetBits(LCD_GPIO_RS_PORT,LCD_GPIO_RS_PIN);} 
 
//#define Set_nWr GPIOD->BSRR  = 0x00004000; 
#define Set_nWr  {GPIO_SetBits(LCD_GPIO_NWR_PORT,LCD_GPIO_NWR_PIN);} 
//#define Clr_nWr GPIOD->BRR   = 0x00004000; 
#define Clr_nWr  {GPIO_ResetBits(LCD_GPIO_NWR_PORT,LCD_GPIO_NWR_PIN);} 
 
//#define Set_nRd GPIOD->BSRR  = 0x00008000; 
#define Set_nRd  {GPIO_SetBits(LCD_GPIO_RD_PORT,LCD_GPIO_RD_PIN);} 
//#define Clr_nRd GPIOD->BRR   = 0x00008000; 
#define Clr_nRd  {GPIO_ResetBits(LCD_GPIO_RD_PORT,LCD_GPIO_RD_PIN);} 
 
 
//#define Write_Data(DataValue) GPIOE->ODR =(DataValue); 
#define Write_Data(DataValue) {GPIO_Write(LCD_GPIO_DATA_PORT,DataValue);} 
 
 
//#define Read_Data  (GPIOB->IDR) 
#define Read_Data  (GPIO_ReadInputData(LCD_GPIO_DATA_PORT)) 
 
/********************************************************************************/								     
   
//画笔颜色 
#define WHITE         	 0xFFFF 
#define BLACK         	 0x0000	   
#define BLUE         	 0x001F   
#define BRED             0XF81F 
#define GRED 			 0XFFE0 
#define GBLUE			 0X07FF 
#define RED           	 0xF800 
#define MAGENTA       	 0xF81F 
#define GREEN         	 0x07E0 
#define CYAN          	 0x7FFF 
#define YELLOW        	 0xFFE0 
#define BROWN 			 0XBC40 //棕色 
#define BRRED 			 0XFC07 //棕红色 
#define GRAY  			 0X8430 //灰色 
//GUI颜色 
 
#define DARKBLUE      	 0X01CF	//深蓝色 
#define LIGHTBLUE      	 0X7D7C	//浅蓝色   
#define GRAYBLUE       	 0X5458 //灰蓝色 
//以上三色为PANEL的颜色  
  
#define LIGHTGREEN     	 0X841F //浅绿色 
//#define LIGHTGRAY        0XEF5B //浅灰色(PANNEL) 
#define LGRAY 			 0XC618 //浅灰色(PANNEL),窗体背景色 
 
#define LGRAYBLUE        0XA651 //浅灰蓝色(中间层颜色) 
#define LBBLUE           0X2B12 //浅棕蓝色(选择条目的反色) 
	    															   
extern u16 BACK_COLOR, POINT_COLOR ;   
void LCD_Init(void); 
void LCD_DisplayOn(void); 
void LCD_DisplayOff(void); 
void LCD_Clear(u16 Color);	  
void LCD_SetCursor(u8 Xpos, u16 Ypos); 
void LCD_DrawPoint(u16 x,u16 y);//画点 
u16 LCD_ReadPoint(u16 x,u16 y); //读点 
void Draw_Circle(u8 x0,u16 y0,u8 r); 
void LCD_DrawLine(u16 x1, u16 y1, u16 x2, u16 y2); 
void LCD_DrawRectangle(u8 x1, u16 y1, u8 x2, u16 y2);		    
void LCD_Fill(u8 xsta,u16 ysta,u8 xend,u16 yend,u16 color); 
void LCD_ShowChar(u8 x,u16 y,u8 num,u8 size,u8 mode);//显示一个字符 
void LCD_ShowNum(u8 x,u16 y,u32 num,u8 len,u8 size);  //显示一个数字 
void LCD_Show2Num(u8 x,u16 y,u16 num,u8 len,u8 size,u8 mode);//显示2个数字 
void LCD_ShowString(u8 x,u16 y,const u8 *p);		 //显示一个字符串,16字体 
									     
//void Set_nWriteReg(u8 LCD_Reg, u16 LCD_RegValue); 
void LCD_WriteReg(u8 LCD_Reg, u16 LCD_RegValue); 
u16 LCD_ReadReg(u8 LCD_Reg); 
void LCD_WriteRAM_Prepare(void); 
void LCD_WriteRAM(u16 RGB_Code); 
u16 LCD_ReadRAM(void);		    
 
//写8位数据函数 
//用宏定义,提高速度. 
#define LCD_WR_DATA(data){\ 
Set_Rs;\ 
Clr_Cs;\ 
Write_Data(data);\ 
Clr_nWr;\ 
Set_nWr;\ 
Set_Cs;\ 
} 																					  
//9320/9325 LCD寄存器   
#define R0             0x00 
#define R1             0x01 
#define R2             0x02 
#define R3             0x03 
#define R4             0x04 
#define R5             0x05 
#define R6             0x06 
#define R7             0x07 
#define R8             0x08 
#define R9             0x09 
#define R10            0x0A 
#define R12            0x0C 
#define R13            0x0D 
#define R14            0x0E 
#define R15            0x0F 
#define R16            0x10 
#define R17            0x11 
#define R18            0x12 
#define R19            0x13 
#define R20            0x14 
#define R21            0x15 
#define R22            0x16 
#define R23            0x17 
#define R24            0x18 
#define R25            0x19 
#define R26            0x1A 
#define R27            0x1B 
#define R28            0x1C 
#define R29            0x1D 
#define R30            0x1E 
#define R31            0x1F 
#define R32            0x20 
#define R33            0x21 
#define R34            0x22 
#define R36            0x24 
#define R37            0x25 
#define R40            0x28 
#define R41            0x29 
#define R43            0x2B 
#define R45            0x2D 
#define R48            0x30 
#define R49            0x31 
#define R50            0x32 
#define R51            0x33 
#define R52            0x34 
#define R53            0x35 
#define R54            0x36 
#define R55            0x37 
#define R56            0x38 
#define R57            0x39 
#define R59            0x3B 
#define R60            0x3C 
#define R61            0x3D 
#define R62            0x3E 
#define R63            0x3F 
#define R64            0x40 
#define R65            0x41 
#define R66            0x42 
#define R67            0x43 
#define R68            0x44 
#define R69            0x45 
#define R70            0x46 
#define R71            0x47 
#define R72            0x48 
#define R73            0x49 
#define R74            0x4A 
#define R75            0x4B 
#define R76            0x4C 
#define R77            0x4D 
#define R78            0x4E 
#define R79            0x4F 
#define R80            0x50 
#define R81            0x51 
#define R82            0x52 
#define R83            0x53 
#define R96            0x60 
#define R97            0x61 
#define R106           0x6A 
#define R118           0x76 
#define R128           0x80 
#define R129           0x81 
#define R130           0x82 
#define R131           0x83 
#define R132           0x84 
#define R133           0x85 
#define R134           0x86 
#define R135           0x87 
#define R136           0x88 
#define R137           0x89 
#define R139           0x8B 
#define R140           0x8C 
#define R141           0x8D 
#define R143           0x8F 
#define R144           0x90 
#define R145           0x91 
#define R146           0x92 
#define R147           0x93 
#define R148           0x94 
#define R149           0x95 
#define R150           0x96 
#define R151           0x97 
#define R152           0x98 
#define R153           0x99 
#define R154           0x9A 
#define R157           0x9D 
#define R192           0xC0 
#define R193           0xC1 
#define R229           0xE5							  		  
#endif