1、移植UCGUI操作系统到LY-STM32开发板上

1、

 

 

 

 

 

 

2、程序例程:

  1 /*************************************************************************************************************************************
  2 *  
  3 *  文件名称:main.c
  4 *  文件功能:主函数文件
  5 *
  6 ***************************************************************************************************************************************/
  7 
  8 #include "pbdata.h"//调用自定义公共函数库
  9 
 10 
 11 /*********************************************************************************
 12 *
 13 * 初始化操作
 14 *
 15 *********************************************************************************/
 16 void RCC_Configuration(void);//系统时钟初始化函数声明
 17 void GPIO_Configuration(void);//GPIO初始化函数声明
 18 void NVIC_Configuration(void);//中断优先级配置函数声明
 19 void USART_Configuration(void);//串口配置函数声明
 20 
 21 
 22 
 23 
 24 /********************************************************************************
 25 *
 26 *  函数名称:main(void)
 27 *  函数功能:主函数
 28 *  函数说明:不能用void定义主函数
 29 *
 30 ********************************************************************************/
 31 int main(void)//void不能void定义主函数
 32 {
 33         
 34     RCC_Configuration();    //系统时钟初始化
 35     
 36     GPIO_Configuration();//端口初始化
 37     
 38     USART_Configuration();//串口配置
 39     
 40     NVIC_Configuration();//中断优先级配置
 41     
 42     FSMC_Configuration();//FSMC配置
 43     
 44     ILI9325_Init();//LCD配置
 45     
 46     
 47     GUI_Init();//GUI初始化
 48   GUI_SetBkColor(GUI_BLUE);//设置背景颜色为蓝色
 49   GUI_Clear();//清屏
 50     GUI_DispStringAt("liubo",40,150);//显示字符
 51 
 52     
 53     
 54     /*主程序,每次隔1s显示不同的颜色*/
 55       while(1);
 56     
 57 }
 58     
 59     
 60 
 61 
 62 /********************************************************************************
 63 *
 64 *  函数名称:RCC_Configuration(void)
 65 *  函数功能:系统时钟高初始化函数
 66 *
 67 ********************************************************************************/
 68     void RCC_Configuration(void)//系统时钟高初始化函数
 69   {
 70         
 71     SystemInit();//系统初始化
 72     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);//串口对应GPIO时钟使能
 73         RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);//串口时钟使能
 74         RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//引脚复用
 75     
 76         /*LCD使用的引脚配置时钟*/
 77         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
 78       RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);
 79       RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);
 80         
 81         RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC,ENABLE);//FSMC时钟配置
 82         
 83         
 84     }
 85     
 86     
 87 
 88 /*******************************************************************************
 89 *
 90 * 函数名称:GPIO_Configuration(void)
 91 * 函数功能:GPIO初始化函数
 92 *
 93 ********************************************************************************/    
 94     
 95     void GPIO_Configuration(void)//GPIO初始化函数
 96   {
 97               
 98         
 99 /*串口引脚配置*/
100         GPIO_InitTypeDef GPIO_InitStructure;//定义一个GPIO设置的结构体变量
101 
102 /*输出引脚配置*/        
103         /*结构体变量赋值*/
104       GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;////引脚配置TX
105       GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;//配置频率
106         GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;//发送要配置成复用推挽输出
107         /*对应的GPIO初始化*/
108       GPIO_Init(GPIOA,&GPIO_InitStructure);
109         
110     
111 /*输入引脚配置*/        
112         /*结构体变量赋值*/
113       GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;////引脚配置RX
114         GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;//接收引脚配置成浮空输入
115         /*对应的GPIO初始化*/
116       GPIO_Init(GPIOA,&GPIO_InitStructure);        
117 
118         
119         
120 /*FSMC管脚初始化*/
121   /*结构体变量赋值*/
122     GPIO_InitStructure.GPIO_Pin=GPIO_Pin_13;//引脚配置
123     GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;//频率配置
124     GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;//输出
125     /*对应的GPIO初始化*/
126     GPIO_Init(GPIOD,&GPIO_InitStructure);//完成初始化
127     
128     GPIO_SetBits(GPIOD,GPIO_Pin_13);//打开背光
129     GPIO_InitStructure.GPIO_Pin=GPIO_Pin_1;//复位
130     GPIO_Init(GPIOE,&GPIO_InitStructure);    
131     
132 /*启用fsmc复用功能,复用上拉模式*/
133     GPIO_InitStructure.GPIO_Pin =GPIO_Pin_14 //D0
134                                 |GPIO_Pin_15 //D1
135                                 |GPIO_Pin_0     //D2
136                                 |GPIO_Pin_1     //D3
137                                 |GPIO_Pin_8     //D13
138                                 |GPIO_Pin_9     //D14
139                                 |GPIO_Pin_10;//D15
140     GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
141     GPIO_Init(GPIOD,&GPIO_InitStructure);
142 
143     GPIO_InitStructure.GPIO_Pin =GPIO_Pin_7     //D4
144                                 |GPIO_Pin_8     //D5
145                                 |GPIO_Pin_9     //D6
146                                 |GPIO_Pin_10 //D7
147                                 |GPIO_Pin_11 //D8
148                                 |GPIO_Pin_12 //D9
149                                 |GPIO_Pin_13 //D10
150                                 |GPIO_Pin_14 //D11
151                                 |GPIO_Pin_15;//D12
152     GPIO_Init(GPIOE,&GPIO_InitStructure);
153 
154 
155     GPIO_InitStructure.GPIO_Pin =GPIO_Pin_11 //RS
156                                 |GPIO_Pin_4     //nOE
157                                 |GPIO_Pin_5; //nWE
158     GPIO_Init(GPIOD,&GPIO_InitStructure);
159 
160     GPIO_InitStructure.GPIO_Pin =GPIO_Pin_7; //NE1
161     GPIO_Init(GPIOD,&GPIO_InitStructure);
162     
163     
164     
165     
166 }
167         
168         
169 
170     
171 
172 /****************************************************************************
173 *
174 *  函数名称:NVIC_Configuration(void)
175 *  函数功能:配置中断优先级
176 *
177 ****************************************************************************/
178     
179 void NVIC_Configuration(void)
180 {
181   NVIC_InitTypeDef NVIC_InitStructure; //定义一个优先级配置结构体变量
182     
183   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//分组
184 
185   NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
186   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;//抢断优先级
187   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;//响应优先级
188   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//使能
189     
190   NVIC_Init(&NVIC_InitStructure);//初始化
191 }
192     
193 
194 /*********************************************************************************
195 *
196 *  函数名称:USART_Configuration(void)
197 *  函数功能:串口配置函数
198 *
199 *********************************************************************************/
200 void USART_Configuration(void)
201 {
202 /*定义串口配置结构体变量*/
203         USART_InitTypeDef USART_InitStructure;//定义一个串口配置结构体变量
204     
205     
206 /*结构体变量赋值*/
207     USART_InitStructure.USART_BaudRate = 9600;//波特率9600
208     USART_InitStructure.USART_WordLength = USART_WordLength_8b;//位宽,8位
209     USART_InitStructure.USART_StopBits = USART_StopBits_1;//停止位1
210     USART_InitStructure.USART_Parity = USART_Parity_No;//不奇偶校验
211     USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//流控禁止
212     USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;//发送使能
213 
214     
215 /*发送串口配置初始化*/
216     USART_Init(USART1, &USART_InitStructure);
217     
218 
219 /*打开串口接收中断*/
220       USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);//当接收到数据时,会产生中断
221     
222     
223 /*打开串口*/
224     USART_Cmd(USART1,ENABLE);//串口使能,打开
225         
226 /*清空中断标志位*/
227     USART_ClearFlag(USART1,USART_FLAG_TC);
228 }
229     
230     
231     
232     
233     
234 
235     
236     
237 
238     
239 
240     
241     
242     
243     
244     
245     
246     
247     
248     
249     
250     
251     
252     
253     
254     
255     
256     
257     
258     
259     
260     
261     
262     
263     
264     
View Code
/****************************************************************************************************************
*
* 文件名称:pbdata.c
* 文件功能:自定义函数或者全局变量的初始化
*
****************************************************************************************************************/

/*头文件声明*/
#include "pbdata.h"




/********************************************************************************************
*
* 自定义全局变量
*
********************************************************************************************/
u8 dt=0;





/******************************************************************************************
*
* 自定义函数
*
******************************************************************************************/

/*************************************
*
*  时钟配置
*  HSE作为PLL时钟
*  PLL作为SYSCLK
*
**************************************/
void RCC_HSE_Configuration(void) 
{ 
   RCC_DeInit(); //将外设RCC寄存器重设为缺省值
   RCC_HSEConfig(RCC_HSE_ON); //设置外部高速晶振HSE,HSE晶振打开ON

   if(RCC_WaitForHSEStartUp() == SUCCESS)//等待HSE起震,SUCCESS:HSE晶振稳定且就绪
    { 

   RCC_HCLKConfig(RCC_SYSCLK_Div1);//设置AHB时钟
   RCC_PCLK2Config(RCC_HCLK_Div1); //设置高速AHB时钟  
   RCC_PCLK1Config(RCC_HCLK_Div2); //设置低速AHB时钟    

   RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);///设置PLL时钟源及倍频系数 
   RCC_PLLCmd(ENABLE); //使能PLL
   while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) ; ///检查指定的RCC标志位(PLL准备好标志)设置是否
    
   RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);  //设置系统时钟 
   while(RCC_GetSYSCLKSource() != 0x08);     //0x08:PLL作为系统时钟
    
 } 
} 







/**************************************************
*
*  普通延时函数
*
***************************************************/
void delay(u32 nCount)
{
    for(;nCount!=0;nCount--);
}




/**************************************************
*
*  函数名称:delay_us(u32 nus)
*  函数功能:微秒延时函数
*  输入参数:输入值为延时us
*
***************************************************/
void delay_us(u32 nus)
{
    u32 temp;
    SysTick->LOAD = 9*nus;//载入初值,72M/8=9M,也就是1/9us,9*1/9us,所以是执行9次
    SysTick->VAL=0X00;//清空计数器,清空后,就自动设置自己设定的计数器的值
    SysTick->CTRL=0X01;//使能,减到零动作(不发生中断),采用外部时钟
    
    do
    {
          temp=SysTick->CTRL;//标志位,等到一直减到0
         }while((temp&0x01)&&(!(temp&(1<<16))));//等待时间到达
    
    SysTick->CTRL=0x00; //关闭计数器
    SysTick->VAL =0X00; //清空计数器
}







/***************************************************
*
* 函数名称:delay_ms(u16 nms)
* 函数功能:毫秒级延时
* 输入参数:输入值位延时ms
*
****************************************************/
void delay_ms(u16 nms)
{
    u32 temp;
    SysTick->LOAD = 9000*nms;//载入初值,72M/8=9M,也就是1/9us,9*1/9us,所以是执行9000次
    SysTick->VAL=0X00;//清空计数器,清空后,就自动设置自己设定的计数器的值
    SysTick->CTRL=0X01;//使能,减到零动作(不发生中断),采用外部时钟
    
    do
    {
          temp=SysTick->CTRL;//标志位,等到一直减到0
         }while((temp&0x01)&&(!(temp&(1<<16))));//等待时间到达
    
    SysTick->CTRL=0x00; //关闭计数器
    SysTick->VAL =0X00; //清空计数器
}



/****************************************************
*
* 重定义printf函数部分
*
****************************************************/
int fputc(int ch,FILE *F)
{
    
    USART_SendData(USART1,(u8)ch);
    
    while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);//等待发送完成,判断标志位
    
    return ch;
}
View Code
 1 /*pbdata.h*/
 2 /***************************************************************************************************
 3 *
 4 * 文件名称:pbdata.h
 5 * 文件功能:自定义的函数和全局变量的声明头文件
 6 *
 7 ***************************************************************************************************/
 8 
 9 #ifndef _pbdata_H
10 #define _pbdata_H
11 
12 
13 
14 
15 
16 /********************************************************************
17 *
18 *  调用的头文件放在这里
19 *
20 ********************************************************************/
21 #include "stm32f10x.h"
22 
23 
24 #include "stm32f10x_rcc.h"
25 #include "stm32f10x_gpio.h"
26 #include "misc.h"
27 #include "stm32f10x_adc.h"
28 #include "stm32f10x_bkp.h"
29 #include "stm32f10x_can.h"
30 #include "stm32f10x_cec.h"
31 #include "stm32f10x_dac.h"
32 #include "stm32f10x_dbgmcu.h"
33 #include "stm32f10x_dma.h"
34 #include "stm32f10x_exti.h"
35 #include "stm32f10x_flash.h"
36 #include "stm32f10x_fsmc.h"
37 #include "stm32f10x_i2c.h"
38 #include "stm32f10x_iwdg.h"
39 #include "stm32f10x_pwr.h"
40 #include "stm32f10x_rtc.h"
41 #include "stm32f10x_sdio.h"
42 #include "stm32f10x_spi.h"
43 #include "stm32f10x_tim.h"
44 #include "stm32f10x_usart.h"
45 #include "stm32f10x_wwdg.h"
46 
47 
48 #include "lcd_ILI9325.h"//lcd配置
49 #include "stm32_fsmc.h"//fsmc通信
50 
51 #include "stdio.h"
52 
53 #include "GUI.h"
54 
55 
56 /********************************************************************
57 *
58 *  自定义全局变量声明
59 *
60 ********************************************************************/
61 extern u8 dt;
62 
63 
64 
65 
66 
67 /********************************************************************
68 *
69 *  自定义全函数声明
70 *
71 ********************************************************************/
72 void delay(u32 nCount);
73 void delay_us(u32 nus);
74 void delay_ms(u16 nms);
75 int fputc(int ch,FILE *F);
76 
77 
78 
79 #endif
View Code
 1 /*************************************************************************************************************************************
 2 *  
 3 *  文件名称:LCDConf.h
 4 *  文件功能:LCD配置文件
 5 *
 6 ***************************************************************************************************************************************/
 7 
 8 #ifndef LCDCONF_H
 9 #define LCDCONF_H
10 
11 
12 
13 
14 
15 
16 
17 
18 /*********************************************************************
19 *
20 *  LCD基本配置
21 *
22 **********************************************************************/
23 
24 /*触摸屏大小设置,3.2寸:240*320*/
25 #define LCD_XSIZE      (320)   
26 #define LCD_YSIZE      (240)   
27 
28 #define LCD_BITSPERPIXEL (16)//像素
29 #define LCD_SWAP_RB   (1) //红蓝转换
30 #define LCD_CONTROLLER  9325//驱动
31 
32 
33 #endif /* LCDCONF_H */
View Code
 1 /*************************************************************************************************************************************
 2 *  
 3 *  文件名称:GUIConf.h
 4 *  文件功能:GUI配置文件
 5 *
 6 ***************************************************************************************************************************************/
 7 
 8 /*********************************************************************************
 9 *
10 * 宏定义部分
11 *
12 *********************************************************************************/
13 
14 #ifndef GUICONF_H
15 #define GUICONF_H
16 
17 #define GUI_OS                    (0)  //UCOS操作系统支持定义,1打开,0关闭
18 #define GUI_SUPPORT_TOUCH         (0)  //触摸屏支持定义,1打开,0关闭
19 #define GUI_SUPPORT_MOUSE         (0)  //鼠标支持,1打开,0关闭
20 #define GUI_SUPPORT_UNICODE       (0)  //字符显示支持,1打开,0关闭
21 
22 
23 
24 #define GUI_DEFAULT_FONT          &GUI_Font6x8   //字体设置
25 #define GUI_ALLOC_SIZE            12500  //动态内存管理
26 
27 
28 
29 #define GUI_WINSUPPORT            1  //视窗管理,1打开,0关闭
30 #define GUI_SUPPORT_MEMDEV        1  //内存管理,1打开,0关闭
31 #define GUI_SUPPORT_AA            1  //抗锯齿,1打开,0关闭
32 
33 
34 
35 
36 #undef GUIDEMO_EN
37 #undef APPLICATION_EN
38 #define GUIDEMO_EN                   1 /* DemoTask */
39 #define APPLICATION_EN   !(GUIDEMO_EN) /* AppTask */ 
40 
41 
42 
43 #endif  /* Avoid multiple inclusion */
44 
45 
46                                                                                                                                                                                                                                                                                                                                                                                                                                                              
View Code
  1 /*************************************************************************************************************************************
  2 *  
  3 *  文件名称:main.c
  4 *  文件功能:主函数文件
  5 *
  6 ***************************************************************************************************************************************/
  7 
  8 
  9 
 10 
 11 
 12 #include <stddef.h>
 13 #include "LCD_Private.h"      /* private modul definitions & config */
 14 #include "GUI_Private.h"
 15 #include "GUIDebug.h"
 16 #include "pbdata.h"
 17 
 18 
 19 
 20 
 21 
 22 /*********************************************************************************
 23 *
 24 *  函数名称:LCD_L0_SetPixelIndex(int x,int y,int PixelIndex) 
 25 *  函数功能:设置点的颜色
 26 *
 27 *********************************************************************************/
 28 
 29 void LCD_L0_SetPixelIndex(int x,int y,int PixelIndex) 
 30 {
 31     LCD_SetPoint(x,y,PixelIndex);
 32 }
 33 
 34 
 35 
 36 
 37 
 38 
 39 
 40 
 41 /*********************************************************************************
 42 *
 43 *  函数名称:LCD_L0_GetPixelIndex(int x,int y)
 44 *  函数功能:获得一个点
 45 *
 46 *********************************************************************************/
 47 unsigned int LCD_L0_GetPixelIndex(int x,int y) 
 48 {
 49     return LCD_GetPoint(x,y);
 50 }
 51 
 52 
 53 
 54 
 55 
 56 
 57 
 58 
 59 /*********************************************************************************
 60 *
 61 *  函数名称:LCD_L0_Init(void)  
 62 *  函数功能:LCD初始化驱动
 63 *
 64 *********************************************************************************/
 65 int LCD_L0_Init(void) 
 66 {
 67     ILI9325_Init();
 68     return 0;
 69 }
 70 
 71 
 72 
 73 
 74 
 75 
 76 
 77 /*********************************************************************************
 78 *
 79 *  函数名称:LCD_L0_XorPixel(int x,int y) 
 80 *  函数功能:
 81 *
 82 *********************************************************************************/
 83 void LCD_L0_XorPixel(int x,int y) 
 84 {
 85     LCD_PIXELINDEX Index = LCD_GetPoint(x,y);
 86     LCD_SetPoint(x,y,LCD_NUM_COLORS-1-Index);
 87 }
 88 
 89 
 90 
 91 
 92 
 93 
 94 
 95 /*********************************************************************************
 96 *
 97 *  函数名称:LCD_L0_DrawHLine(int x0,int y,int x1) 
 98 *  函数功能:画横线
 99 *
100 *********************************************************************************/
101 void LCD_L0_DrawHLine(int x0,int y,int x1)
102 {
103     GUI_Line(x0,y,x1,y,LCD_COLORINDEX);
104 }
105 
106 
107 
108 
109 
110 
111 
112 /*********************************************************************************
113 *
114 *  函数名称:LCD_L0_DrawVLine(int x,int y0,int y1) 
115 *  函数功能:画竖线
116 *
117 *********************************************************************************/
118 void LCD_L0_DrawVLine(int x,int y0,int y1)
119 {
120     GUI_Line(x,y0,x,y1,LCD_COLORINDEX);
121 }
122 
123 
124 
125 
126 
127 
128 /*********************************************************************************
129 *
130 *  函数名称:LCD_L0_FillRect(int x0, int y0, int x1, int y1)  
131 *  函数功能:画矩形
132 *
133 *********************************************************************************/
134 
135 void LCD_L0_FillRect(int x0, int y0, int x1, int y1) 
136 {
137 #if !LCD_SWAP_XY
138   for (; y0 <= y1; y0++) {
139     LCD_L0_DrawHLine(x0,y0, x1);
140   }
141 #else
142   for (; x0 <= x1; x0++) {
143     LCD_L0_DrawVLine(x0,y0, y1);
144   }
145 #endif
146 }
147 
148 
149 
150 
151 
152 
153 
154 /*********************************************************************************
155 *
156 *  函数名称:DrawBitLine1BPP 
157 *  函数功能:位图
158 *
159 *********************************************************************************/
160 void DrawBitLine1BPP(int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans)
161 {
162   LCD_PIXELINDEX pixels;
163   LCD_PIXELINDEX Index0 = *(pTrans+0);
164   LCD_PIXELINDEX Index1 = *(pTrans+1);
165 /*
166 // Jump to right entry point
167 */
168   pixels = *p;
169   switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS|LCD_DRAWMODE_XOR)) {
170   case 0:
171     #if defined (SETNEXTPIXEL)   /* Optimization ! */
172       x+=Diff;
173       LCD_SetCursor(x,y);
174     #endif
175     switch (Diff&7) {
176     case 0:   
177       goto WriteBit0;
178     case 1:   
179       goto WriteBit1;
180     case 2:
181       goto WriteBit2;
182     case 3:
183       goto WriteBit3;
184     case 4:
185       goto WriteBit4;
186     case 5:   
187       goto WriteBit5;
188     case 6:   
189       goto WriteBit6;
190     case 7:   
191       goto WriteBit7;
192     }
193     break;
194   case LCD_DRAWMODE_TRANS:
195     switch (Diff&7) {
196     case 0:
197       goto WriteTBit0;
198     case 1:
199       goto WriteTBit1;
200     case 2:
201       goto WriteTBit2;
202     case 3:
203       goto WriteTBit3;
204     case 4:
205       goto WriteTBit4;
206     case 5:   
207       goto WriteTBit5;
208     case 6:   
209       goto WriteTBit6;
210     case 7:   
211       goto WriteTBit7;
212     }
213     break;
214   case LCD_DRAWMODE_XOR:
215     switch (Diff&7) {
216     case 0:   
217       goto WriteXBit0;
218     case 1:   
219       goto WriteXBit1;
220     case 2:
221       goto WriteXBit2;
222     case 3:
223       goto WriteXBit3;
224     case 4:
225       goto WriteXBit4;
226     case 5:   
227       goto WriteXBit5;
228     case 6:   
229       goto WriteXBit6;
230     case 7:   
231       goto WriteXBit7;
232     }
233   }
234 /*
235         Write with transparency
236 */
237   WriteTBit0:
238     if (pixels&(1<<7)) LCD_SetPoint(x+0, y, Index1);
239     if (!--xsize)
240       return;
241   WriteTBit1:
242     if (pixels&(1<<6)) LCD_SetPoint(x+1, y, Index1);
243     if (!--xsize)
244       return;
245   WriteTBit2:
246     if (pixels&(1<<5)) LCD_SetPoint(x+2, y, Index1);
247     if (!--xsize)
248       return;
249   WriteTBit3:
250     if (pixels&(1<<4)) LCD_SetPoint(x+3, y, Index1);
251     if (!--xsize)
252       return;
253   WriteTBit4:
254     if (pixels&(1<<3)) LCD_SetPoint(x+4, y, Index1);
255     if (!--xsize)
256       return;
257   WriteTBit5:
258     if (pixels&(1<<2)) LCD_SetPoint(x+5, y, Index1);
259     if (!--xsize)
260       return;
261   WriteTBit6:
262     if (pixels&(1<<1)) LCD_SetPoint(x+6, y, Index1);
263     if (!--xsize)
264       return;
265   WriteTBit7:
266     if (pixels&(1<<0)) LCD_SetPoint(x+7, y, Index1);
267     if (!--xsize)
268       return;
269     x+=8;
270     pixels = *(++p);
271     goto WriteTBit0;
272 
273 /*
274         Write without transparency
275 */
276 
277   WriteBit0:
278     LCD_SetPoint(x+0, y, (pixels&(1<<7)) ? Index1 : Index0);
279     if (!--xsize)
280       return;
281   WriteBit1:
282     LCD_SetPoint(x+1, y, (pixels&(1<<6)) ? Index1 : Index0);
283     if (!--xsize)
284       return;
285   WriteBit2:
286     LCD_SetPoint(x+2, y, (pixels&(1<<5)) ? Index1 : Index0);
287     if (!--xsize)
288       return;
289   WriteBit3:
290     LCD_SetPoint(x+3, y, (pixels&(1<<4)) ? Index1 : Index0);
291     if (!--xsize)
292       return;
293   WriteBit4:
294     LCD_SetPoint(x+4, y, (pixels&(1<<3)) ? Index1 : Index0);
295     if (!--xsize)
296       return;
297   WriteBit5:
298     LCD_SetPoint(x+5, y, (pixels&(1<<2)) ? Index1 : Index0);
299     if (!--xsize)
300       return;
301   WriteBit6:
302     LCD_SetPoint(x+6, y, (pixels&(1<<1)) ? Index1 : Index0);
303     if (!--xsize)
304       return;
305   WriteBit7:
306     LCD_SetPoint(x+7, y, (pixels&(1<<0)) ? Index1 : Index0);
307     if (!--xsize)
308       return;
309     x+=8;
310     pixels = *(++p);
311     goto WriteBit0;
312 
313 /*
314         Write XOR mode
315 */
316   WriteXBit0:
317     if (pixels&(1<<7))
318       LCD_L0_XorPixel(x+0, y);
319     if (!--xsize)
320       return;
321   WriteXBit1:
322     if (pixels&(1<<6))
323       LCD_L0_XorPixel(x+1, y);
324     if (!--xsize)
325       return;
326   WriteXBit2:
327     if (pixels&(1<<5))
328       LCD_L0_XorPixel(x+2, y);
329     if (!--xsize)
330       return;
331   WriteXBit3:
332     if (pixels&(1<<4))
333       LCD_L0_XorPixel(x+3, y);
334     if (!--xsize)
335       return;
336   WriteXBit4:
337     if (pixels&(1<<3))
338       LCD_L0_XorPixel(x+4, y);
339     if (!--xsize)
340       return;
341   WriteXBit5:
342     if (pixels&(1<<2))
343       LCD_L0_XorPixel(x+5, y);
344     if (!--xsize)
345       return;
346   WriteXBit6:
347     if (pixels&(1<<1))
348       LCD_L0_XorPixel(x+6, y);
349     if (!--xsize)
350       return;
351   WriteXBit7:
352     if (pixels&(1<<0))
353       LCD_L0_XorPixel(x+7, y);
354     if (!--xsize)
355       return;
356     x+=8;
357     pixels = *(++p);
358     goto WriteXBit0;
359 }
360 
361 
362 
363 
364 
365 
366 
367 
368 
369 
370 
371 
372 /*********************************************************************************
373 *
374 *  函数名称:DrawBitLine2BPP 
375 *  函数功能:
376 *
377 *********************************************************************************/
378 static void  DrawBitLine2BPP(int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans) 
379 {
380   LCD_PIXELINDEX pixels;
381 /*
382 // Jump to right entry point
383 */
384   pixels = *p;
385   if (pTrans) {
386     /*
387       with palette
388     */
389     if (GUI_Context.DrawMode & LCD_DRAWMODE_TRANS) switch (Diff&3) {
390     case 0:
391       goto WriteTBit0;
392     case 1:
393       goto WriteTBit1;
394     case 2:
395       goto WriteTBit2;
396     default:
397       goto WriteTBit3;
398     } else switch (Diff&3) {
399     case 0:
400       goto WriteBit0;
401     case 1:
402       goto WriteBit1;
403     case 2:
404       goto WriteBit2;
405     default:
406       goto WriteBit3;
407     }
408   /*
409           Write without transparency
410   */
411   WriteBit0:
412     LCD_SetPoint(x+0, y, *(pTrans+(pixels>>6)));
413     if (!--xsize)
414       return;
415   WriteBit1:
416     LCD_SetPoint(x+1, y, *(pTrans+(3&(pixels>>4))));
417     if (!--xsize)
418       return;
419   WriteBit2:
420     LCD_SetPoint(x+2, y, *(pTrans+(3&(pixels>>2))));
421     if (!--xsize)
422       return;
423   WriteBit3:
424     LCD_SetPoint(x+3, y, *(pTrans+(3&(pixels))));
425     if (!--xsize)
426       return;
427     pixels = *(++p);
428     x+=4;
429     goto WriteBit0;
430   /*
431           Write with transparency
432   */
433   WriteTBit0:
434     if (pixels&(3<<6))
435       LCD_SetPoint(x+0, y, *(pTrans+(pixels>>6)));
436     if (!--xsize)
437       return;
438   WriteTBit1:
439     if (pixels&(3<<4))
440       LCD_SetPoint(x+1, y, *(pTrans+(3&(pixels>>4))));
441     if (!--xsize)
442       return;
443   WriteTBit2:
444     if (pixels&(3<<2))
445       LCD_SetPoint(x+2, y, *(pTrans+(3&(pixels>>2))));
446     if (!--xsize)
447       return;
448   WriteTBit3:
449     if (pixels&(3<<0))
450       LCD_SetPoint(x+3, y, *(pTrans+(3&(pixels))));
451     if (!--xsize)
452       return;
453     pixels = *(++p);
454     x+=4;
455     goto WriteTBit0;
456   } else { 
457     /* 
458       without palette 
459     */
460     if (GUI_Context.DrawMode & LCD_DRAWMODE_TRANS) switch (Diff&3) {
461     case 0:
462       goto WriteDDPTBit0;
463     case 1:
464       goto WriteDDPTBit1;
465     case 2:
466       goto WriteDDPTBit2;
467     default:
468       goto WriteDDPTBit3;
469     } else switch (Diff&3) {
470     case 0:
471       goto WriteDDPBit0;
472     case 1:
473       goto WriteDDPBit1;
474     case 2:
475       goto WriteDDPBit2;
476     default:
477       goto WriteDDPBit3;
478     }
479   /*
480           Write without transparency
481   */
482   WriteDDPBit0:
483     LCD_SetPoint(x+0, y, (pixels>>6));
484     if (!--xsize)
485       return;
486   WriteDDPBit1:
487     LCD_SetPoint(x+1, y, (3&(pixels>>4)));
488     if (!--xsize)
489       return;
490   WriteDDPBit2:
491     LCD_SetPoint(x+2, y, (3&(pixels>>2)));
492     if (!--xsize)
493       return;
494   WriteDDPBit3:
495     LCD_SetPoint(x+3, y, (3&(pixels)));
496     if (!--xsize)
497       return;
498     pixels = *(++p);
499     x+=4;
500     goto WriteDDPBit0;
501   /*
502           Write with transparency
503   */
504   WriteDDPTBit0:
505     if (pixels&(3<<6))
506       LCD_SetPoint(x+0, y, (pixels>>6));
507     if (!--xsize)
508       return;
509   WriteDDPTBit1:
510     if (pixels&(3<<4))
511       LCD_SetPoint(x+1, y, (3&(pixels>>4)));
512     if (!--xsize)
513       return;
514   WriteDDPTBit2:
515     if (pixels&(3<<2))
516       LCD_SetPoint(x+2, y, (3&(pixels>>2)));
517     if (!--xsize)
518       return;
519   WriteDDPTBit3:
520     if (pixels&(3<<0))
521       LCD_SetPoint(x+3, y, (3&(pixels)));
522     if (!--xsize)
523       return;
524     pixels = *(++p);
525     x+=4;
526     goto WriteDDPTBit0;
527   }
528 }
529 
530 
531 
532 
533 
534 
535 
536 
537 /*********************************************************************************
538 *
539 *  函数名称:DrawBitLine4BPP
540 *  函数功能:
541 *
542 *********************************************************************************/
543 static void  DrawBitLine4BPP(int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans)
544 {
545   LCD_PIXELINDEX pixels;
546 
547   pixels = *p;
548   if (pTrans)
549   {
550     if (GUI_Context.DrawMode & LCD_DRAWMODE_TRANS)
551     {
552       if ((Diff&1) ==0)
553         goto WriteTBit0;
554         goto WriteTBit1;
555     }
556     else
557     {
558       if ((Diff&1) ==0)
559         goto WriteBit0;
560         goto WriteBit1;
561     }
562 
563   WriteBit0:
564     LCD_SetPoint(x+0, y, *(pTrans+(pixels>>4)));
565     if (!--xsize)
566       return;
567   WriteBit1:
568     LCD_SetPoint(x+1, y, *(pTrans+(pixels&0xf)));
569     if (!--xsize)
570       return;
571     x+=2;
572     pixels = *(++p);
573     goto WriteBit0;
574   /*
575           Write with transparency
576   */
577   WriteTBit0:
578     if (pixels>>4)
579       LCD_SetPoint(x+0, y, *(pTrans+(pixels>>4)));
580     if (!--xsize)
581       return;
582   WriteTBit1:
583     if (pixels&0xf)
584       LCD_SetPoint(x+1, y, *(pTrans+(pixels&0xf)));
585     if (!--xsize)
586       return;
587     x+=2;
588     pixels = *(++p);
589     goto WriteTBit0;
590   } else {
591     /*
592       without palette
593     */
594     if (GUI_Context.DrawMode & LCD_DRAWMODE_TRANS) {
595       if ((Diff&1) ==0)
596         goto WriteDDPTBit0;
597       goto WriteDDPTBit1;
598     } else {
599       if ((Diff&1) ==0)
600         goto WriteDDPBit0;
601       goto WriteDDPBit1;
602     }
603   /*
604           Write without transparency
605   */
606   WriteDDPBit0:
607     LCD_SetPoint(x+0, y, (pixels>>4));
608     if (!--xsize)
609       return;
610   WriteDDPBit1:
611     LCD_SetPoint(x+1, y, (pixels&0xf));
612     if (!--xsize)
613       return;
614     x+=2;
615     pixels = *(++p);
616     goto WriteDDPBit0;
617   /*
618           Write with transparency
619   */
620   WriteDDPTBit0:
621     if (pixels>>4)
622       LCD_SetPoint(x+0, y, (pixels>>4));
623     if (!--xsize)
624       return;
625   WriteDDPTBit1:
626     if (pixels&0xf)
627       LCD_SetPoint(x+1, y, (pixels&0xf));
628     if (!--xsize)
629       return;
630     x+=2;
631     pixels = *(++p);
632     goto WriteDDPTBit0;
633   }
634 }
635 
636 
637 
638 
639 
640 
641 
642 /*********************************************************************************
643 *
644 *  函数名称:DrawBitLine8BPP 
645 *  函数功能:
646 *
647 *********************************************************************************/
648 void DrawBitLine8BPP(int x, int y, U8 const*p, int xsize, const LCD_PIXELINDEX*pTrans) 
649 {
650   LCD_PIXELINDEX pixel;
651   if ((GUI_Context.DrawMode & LCD_DRAWMODE_TRANS)==0) {
652     if (pTrans) {
653       for (;xsize > 0; xsize--,x++,p++) {
654         pixel = *p;
655         LCD_SetPoint(x, y, *(pTrans+pixel));
656       }
657     } else {
658       for (;xsize > 0; xsize--,x++,p++) {
659         LCD_SetPoint(x, y, *p);
660       }
661     }
662   } else {   /* Handle transparent bitmap */
663     if (pTrans) {
664       for (; xsize > 0; xsize--, x++, p++) {
665         pixel = *p;
666         if (pixel) {
667           LCD_SetPoint(x+0, y, *(pTrans+pixel));
668         }
669       }
670     } else {
671       for (; xsize > 0; xsize--, x++, p++) {
672         pixel = *p;
673         if (pixel) {
674           LCD_SetPoint(x+0, y, pixel);
675         }
676       }
677     }
678   }
679 }
680 
681 
682 
683 
684 
685 
686 
687 
688 
689 /*********************************************************************************
690 *
691 *  函数名称:DrawBitLine16BPP
692 *  函数功能:
693 *
694 *********************************************************************************/
695 void DrawBitLine16BPP(int x, int y, U16 const*p, int xsize)
696 {
697   LCD_PIXELINDEX Index;
698   if ((GUI_Context.DrawMode & LCD_DRAWMODE_TRANS)==0)
699   {
700     
701         
702         *(__IO uint16_t *) (Bank1_LCD_C)= 32;    
703         *(__IO uint16_t *) (Bank1_LCD_D)= x;
704 
705         *(__IO uint16_t *) (Bank1_LCD_C)= 33;    
706         *(__IO uint16_t *) (Bank1_LCD_D)= y;
707 
708         *(__IO uint16_t *) (Bank1_LCD_C)= 34;
709 
710     for (;xsize > 0; xsize--,x++,p++)
711     {
712       *(__IO uint16_t *) (Bank1_LCD_D)= *p;
713     }    
714   }
715   else
716   {   /* Handle transparent bitmap */
717     for (; xsize > 0; xsize--, x++, p++)
718     {
719       Index = *p;
720       if (Index)
721       {
722         LCD_SetPoint(x+0, y, Index);
723       }
724     }
725   }
726 }
727 
728 
729 
730 
731 
732 
733 
734 
735 
736 /*********************************************************************************
737 *
738 *  函数名称:LCD_L0_DrawBitmap
739 *  函数功能:
740 *
741 *********************************************************************************/
742 void LCD_L0_DrawBitmap   (int x0, int y0,
743                        int xsize, int ysize,
744                        int BitsPerPixel, 
745                        int BytesPerLine,
746                        const U8* pData, int Diff,
747                        const LCD_PIXELINDEX* pTrans)
748 {
749   int i;
750   switch (BitsPerPixel)
751   {
752   case 1:
753     for (i=0; i<ysize; i++)
754     {
755       DrawBitLine1BPP(x0, i+y0, pData, Diff, xsize, pTrans);
756       pData += BytesPerLine;
757     }
758     break;
759   case 2:
760     for (i=0; i<ysize; i++)
761     {
762       DrawBitLine2BPP(x0, i+y0, pData, Diff, xsize, pTrans);
763       pData += BytesPerLine;
764     }
765     break;
766   case 4:
767     for (i=0; i<ysize; i++)
768     {
769       DrawBitLine4BPP(x0, i+y0, pData, Diff, xsize, pTrans);
770       pData += BytesPerLine;
771     }
772     break;
773   case 8:
774     for (i=0; i<ysize; i++)
775     {
776       DrawBitLine8BPP(x0, i+y0, pData, xsize, pTrans);
777       pData += BytesPerLine;
778     }
779     break;
780   case 16:
781     for (i=0; i<ysize; i++)
782     {
783       DrawBitLine16BPP(x0, i+y0, (U16*)pData, xsize);
784       pData += BytesPerLine;
785     }
786     break;
787   }
788 }
789 
790 
791 
792 
793 
794 
795 
796 
797 
798 
799 
800 
801 /*********************************************************************************
802 *
803 *  函数名称:LCD_L0_SetOrg
804 *  函数功能:
805 *
806 *********************************************************************************/
807 void LCD_L0_SetOrg(int x, int y) 
808 {
809   GUI_USE_PARA(x);
810   GUI_USE_PARA(y);
811 }
812 
813 
814 
815 
816 
817 
818 
819 
820 
821 
822 
823 
824 
825 
826 
827 /*********************************************************************************
828 *
829 *  函数名称:LCD_L0_XorPixel(int x,int y) 
830 *  函数功能:
831 *
832 *********************************************************************************/
833 void LCD_On (void) {}
834 void LCD_Off(void) {}
835 
836 
837     
838     
839     
840     
841     
842     
843 /*********************************************************************************
844 *
845 *  函数名称:LCD_L0_XorPixel(int x,int y) 
846 *  函数功能:
847 *
848 *********************************************************************************/
849 void LCD_L0_SetLUTEntry(U8 Pos, LCD_COLOR Color) 
850 {
851   GUI_USE_PARA(Pos);
852   GUI_USE_PARA(Color);
853 }
854 
855 
856 
857 
858 
859 
860 
861 
862 
863 
864 
865 
866 
867 
868 
869 /*********************************************************************************
870 *
871 *  函数名称:LCD_L0_XorPixel(int x,int y) 
872 *  函数功能:
873 *
874 *********************************************************************************/
875 void * LCD_L0_GetDevFunc(int Index) 
876 {
877   GUI_USE_PARA(Index);
878   return NULL;
879 }
View Code
 1 /*************************************************************************************************************************************
 2 *  
 3 *  文件名称:stm32_fsmc.c
 4 *  文件功能:fsmc配置函数文件
 5 *
 6 ***************************************************************************************************************************************/
 7 
 8 
 9 #include "pbdata.h"
10 
11 void FSMC_Configuration(void)
12 {
13     
14   FSMC_NORSRAMInitTypeDef  FSMC_NORSRAMInitStructure;
15   FSMC_NORSRAMTimingInitTypeDef  p;  
16 
17   p.FSMC_AddressSetupTime = 0x02;//地址建立时间
18   p.FSMC_AddressHoldTime = 0x00;//地址保持时间
19   p.FSMC_DataSetupTime = 0x05;//数据建立时间
20   p.FSMC_BusTurnAroundDuration = 0x00;//总线恢复时间
21   p.FSMC_CLKDivision = 0x00;//时钟分频
22   p.FSMC_DataLatency = 0x00;//数据保持时间
23   p.FSMC_AccessMode = FSMC_AccessMode_B;
24 
25   
26   FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;//NOR FLASH的 BANK1
27 
28   FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;//数据线与地址线不复用
29   
30   FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR;//存储类型NOR FLASH
31 
32   FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;//数据宽度为16位
33 
34   FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;//使用异步写模式,禁止突发模式
35 
36   FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;//本成员的配置只在突发模式下有效,等效型号极性为低
37 
38   FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;//禁止非对其突发模式
39 
40   FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;//本成员配置仅在突发模式下有效,NWAIT信号在什么时期
41 
42   FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;//禁止突发写操作
43 
44   FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;//禁止突发写操作
45 
46   FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;//写使能
47 
48   FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;//禁止扩展模式,扩展模式可以使用独立的读、写模式
49 
50   FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;//配置读写时序
51 
52   FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;//配置写时序
53 
54 
55   FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); //初始化FSMC
56 
57   FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);  //使能FSMC  BANK1_SRAM
58     
59 }
View Code
  1 /*************************************************************************************************************************************
  2 *  
  3 *  文件名称:lcd_ILI9325.h
  4 *  文件功能:LCD初始化头文件
  5 *
  6 ***************************************************************************************************************************************/
  7 
  8 
  9 #include "pbdata.h"
 10 
 11 
 12 
 13 
 14 
 15 /*********************************************
 16 *  
 17 *  写命令子函数
 18 *
 19 **********************************************/
 20 void LCD_WR_REG(u16 index)
 21 {
 22     *(__IO u16 *)(Bank1_LCD_C)=index;//把我们定义的数据读写首地址转化为指针,指向LCD真实的扩展地址
 23 }
 24 
 25 
 26 
 27 
 28 /*********************************************
 29 *  
 30 *  写数据子函数
 31 *
 32 **********************************************/
 33 void LCD_WR_Data(u16 val)
 34 {
 35    *(__IO u16 *)(Bank1_LCD_D)=val;//把我们定义的命令读写首地址转换为指针,指向LCD真实扩展地址
 36 }
 37 
 38 
 39 
 40 
 41 /*********************************************
 42 *  
 43 *  同时写命令和数据
 44 *
 45 **********************************************/
 46 
 47 void LCD_WR_CMD(u16 index,u16 val)
 48 {
 49    *(__IO u16 *)(Bank1_LCD_C)=index;  
 50    *(__IO u16 *)(Bank1_LCD_D)=val;
 51 }
 52 
 53 
 54 
 55 
 56 
 57 
 58 
 59 
 60 
 61 /*********************************************
 62 *  
 63 *  LCD初始化函数,出厂配置好
 64 *
 65 **********************************************/
 66 void ILI9325_Init(void)
 67 {   
 68     GPIO_SetBits(GPIOE, GPIO_Pin_1 );         //V7     
 69     delay_ms(1);
 70     GPIO_ResetBits(GPIOE, GPIO_Pin_1);
 71     delay_ms(10);
 72     GPIO_SetBits(GPIOE, GPIO_Pin_1 );         //V7     
 73     delay_ms(50);    
 74 
 75     //************* Start Initial Sequence **********// 
 76     LCD_WR_CMD(0x0001, 0x0100);     // set SS and SM bit 
 77     LCD_WR_CMD(0x0002, 0x0700);     // set 1 line inversion 
 78     LCD_WR_CMD(0x0003, 0x1030);     // set GRAM write direction and BGR=1.  
 79     LCD_WR_CMD(0x0004, 0x0000);     // Resize register 
 80     LCD_WR_CMD(0x0008, 0x0202);        // set the back porch and front porch 
 81     LCD_WR_CMD(0x0009, 0x0000);     // set non-display area refresh cycle ISC[3:0] 
 82     LCD_WR_CMD(0x000A, 0x0000);     // FMARK function 
 83     LCD_WR_CMD(0x000C, 0x0000);        // RGB interface setting
 84     LCD_WR_CMD(0x000D, 0x0000);     // Frame marker Position 
 85     LCD_WR_CMD(0x000F, 0x0000);         // RGB interface polarity 
 86     //*************Power On sequence ****************// 
 87     LCD_WR_CMD(0x0010, 0x0000);      // SAP, BT[3:0], AP, DSTB, SLP, STB 
 88     LCD_WR_CMD(0x0011, 0x0007);      // DC1[2:0], DC0[2:0], VC[2:0] 
 89     LCD_WR_CMD(0x0012, 0x0000);      // VREG1OUT voltage 
 90     LCD_WR_CMD(0x0013, 0x0000);      // VDV[4:0] for VCOM amplitude 
 91     LCD_WR_CMD(0x0007, 0x0001);  
 92     delay_ms(500);    
 93     delay_ms(500);    
 94     delay_ms(500);    
 95 
 96     LCD_WR_CMD(0x0010, 0x1690);      // SAP, BT[3:0], AP, DSTB, SLP, STB 
 97     LCD_WR_CMD(0x0011, 0x0227);      // DC1[2:0], DC0[2:0], VC[2:0]     
 98     delay_ms(50);
 99 
100     LCD_WR_CMD(0x0012, 0x009D);      // Internal reference voltage= Vci;     
101     delay_ms(50);
102 
103     LCD_WR_CMD(0x0013, 0x1900);      // Set VDV[4:0] for VCOM amplitude 
104     LCD_WR_CMD(0x0029, 0x0025);      // Set VCM[5:0] for VCOMH 
105     LCD_WR_CMD(0x002B, 0x000D);      // Set Frame Rate          
106     delay_ms(50);
107 
108     LCD_WR_CMD(0x0020, 0x0000);      // GRAM horizontal Address 
109     LCD_WR_CMD(0x0021, 0x0000);      // GRAM Vertical Address
110     // ----------- Adjust the Gamma    Curve ----------// 
111     LCD_WR_CMD(0x0030, 0x0007); 
112     LCD_WR_CMD(0x0031, 0x0303); 
113     LCD_WR_CMD(0x0032, 0x0003); 
114     LCD_WR_CMD(0x0035, 0x0206); 
115     LCD_WR_CMD(0x0036, 0x0008); 
116     LCD_WR_CMD(0x0037, 0x0406); 
117     LCD_WR_CMD(0x0038, 0x0304); 
118     LCD_WR_CMD(0x0039, 0x0007); 
119     LCD_WR_CMD(0x003C, 0x0602); 
120     LCD_WR_CMD(0x003D, 0x0008); 
121     //------------------ Set GRAM area ---------------// 
122     LCD_WR_CMD(0x0050, 0x0000);      // Horizontal GRAM Start Address 
123     LCD_WR_CMD(0x0051, 0x00EF);      // Horizontal GRAM End Address 
124     LCD_WR_CMD(0x0052, 0x0000);      // Vertical GRAM Start Address 
125     LCD_WR_CMD(0x0053, 0x013F);      // Vertical GRAM Start Address 
126     LCD_WR_CMD(0x0060, 0xA700);      // Gate Scan Line 
127     LCD_WR_CMD(0x0061, 0x0001);      // NDL,VLE, REV
128     LCD_WR_CMD(0x006A, 0x0000);      // set scrolling line 
129     //-------------- Partial Display Control ---------// 
130     LCD_WR_CMD(0x0080, 0x0000); 
131     LCD_WR_CMD(0x0081, 0x0000); 
132     LCD_WR_CMD(0x0082, 0x0000); 
133     LCD_WR_CMD(0x0083, 0x0000); 
134     LCD_WR_CMD(0x0084, 0x0000); 
135     LCD_WR_CMD(0x0085, 0x0000); 
136     //-------------- Panel Control -------------------// 
137     LCD_WR_CMD(0x0090, 0x0010); 
138     LCD_WR_CMD(0x0092, 0x0600);     
139     LCD_WR_CMD(0x0007, 0x0133);      // 262K color and display ON 
140 }
141 
142 
143 
144 
145 
146 
147 
148 /*********************************************
149 *  
150 *  204*320,向触摸屏送数据,一个点一个点都要扫描到
151 *
152 **********************************************/
153 void ILI_9325_Draw_Point(u8 x,u16 y,u16 color)
154 {
155     LCD_WR_CMD(0x50,x);    //x起始
156     LCD_WR_CMD(0x51,x);    //x结束
157     LCD_WR_CMD(0x52,y);    //y起始
158     LCD_WR_CMD(0x53,y);    //y结束
159 
160     LCD_WR_CMD(0x20,x);
161     LCD_WR_CMD(0x21,y);
162     LCD_WR_REG(0x22);
163     LCD_WR_Data(color);
164 }
165 
166 
167 
168 
169 
170 /*********************************************
171 *  
172 *  同时写命令和数据
173 *
174 **********************************************/
175 
176 void ILI_9325_CLEAR(u16 color)
177 {
178     u16 i=0,j=0;
179 
180     for(i=0;i<240;i++)
181     {
182         for(j=0;j<320;j++)
183         {
184             ILI_9325_Draw_Point(i,j,color);
185         }
186     }
187 }
188 
189 
190 
191 
192 
193 
194 
195 
196 /*********************************************
197 *  
198 *  读数据
199 *
200 **********************************************/
201 u16 LCD_RD_data(void)
202 {
203     u16 a=0;
204     a=*(__IO uint16_t *) (Bank1_LCD_D);   //空操作
205     a=*(__IO uint16_t *) (Bank1_LCD_D);   //读出的实际16位像素数据      
206     return(a);    
207 }
208 
209 
210 
211 
212 
213 
214 
215 
216 /*********************************************
217 *  
218 *  设置一个点
219 *
220 **********************************************/
221 void LCD_SetPoint(u16 x,u16 y,u16 color)
222 {
223     *(__IO uint16_t *) (Bank1_LCD_C)= 32;    
224     *(__IO uint16_t *) (Bank1_LCD_D)= y;
225     
226     *(__IO uint16_t *) (Bank1_LCD_C)= 33;    
227     *(__IO uint16_t *) (Bank1_LCD_D)= 319-x;
228     
229     *(__IO uint16_t *) (Bank1_LCD_C)= 34;    
230     *(__IO uint16_t *) (Bank1_LCD_D)= color;
231 }
232 
233 
234 
235 
236 
237 
238 
239 /*********************************************
240 *  
241 *  设置点的位置
242 *
243 **********************************************/
244 
245 void LCD_SetCursor(u16 x,u16 y)
246 {                   
247   *(__IO uint16_t *) (Bank1_LCD_C)= 32;          //设置X坐标
248   *(__IO uint16_t *) (Bank1_LCD_D)= y;
249 
250   *(__IO uint16_t *) (Bank1_LCD_C)= 33;          //设置Y坐标
251   *(__IO uint16_t *) (Bank1_LCD_D)= 319-x;
252 }
253 
254 
255 
256 
257 
258 
259 
260 
261 /*********************************************
262 *  
263 *  获取一个点
264 *
265 **********************************************/
266 u16 LCD_GetPoint(u16 x,u16 y)
267 { 
268     LCD_SetCursor(x,y);
269     *(__IO uint16_t *) (Bank1_LCD_C)= 34;
270     
271 
272     //花屏处理方法--如果花屏请先屏蔽掉现在的模式改另一种模式
273     //return (LCD_BGR2RGB(LCD_RD_data())); //模式1
274     return (LCD_RD_data());                  //模式2
275 }
276 
277 
278 
279 
280 
281 
282 /*********************************************
283 *  
284 *  颜色配置
285 *
286 **********************************************/
287 u16 LCD_BGR2RGB(u16 c)
288 {
289   u16  r, g, b;
290 
291   b = (c>>0)  & 0x1f;
292   g = (c>>5)  & 0x3f;
293   r = (c>>11) & 0x1f;
294   
295   return( (b<<11) + (g<<5) + (r<<0) );
296 }
297 
298 
299 
300 
301 
302 
303 
304 
305 
306 
307 
308 /*********************************************
309 *  
310 *  GUI画线
311 *
312 **********************************************/
313 void GUI_Line(u16 x0, u16 y0, u16 x1, u16 y1,u16 color)
314 {
315      u16 x,y;
316      u16 dx;// = abs(x1 - x0);
317      u16 dy;// = abs(y1 - y0);
318 
319     if(y0==y1)
320     {
321         if(x0<=x1)
322         {
323             x=x0;
324         }
325         else
326         {
327             x=x1;
328             x1=x0;
329         }
330           while(x <= x1)
331           {
332                LCD_SetPoint(x,y0,color);
333                x++;
334           } 
335           return;
336     }
337     else if(y0>y1)
338     {
339         dy=y0-y1;
340     }
341     else
342     {
343         dy=y1-y0;
344     }
345  
346      if(x0==x1)
347     {
348         if(y0<=y1)
349         {
350             y=y0;
351         }
352         else
353         {
354             y=y1;
355             y1=y0;
356         }
357           while(y <= y1)
358           {
359                LCD_SetPoint(x0,y,color);
360                y++;
361           } 
362           return;
363     }
364     else if(x0 > x1)
365      {
366         dx=x0-x1;
367           x = x1;
368           x1 = x0;
369           y = y1;
370           y1 = y0;
371      }
372      else
373      {
374         dx=x1-x0;
375           x = x0;
376           y = y0;
377      }
378 
379      if(dx == dy)
380      {
381           while(x <= x1)
382           {
383 
384                x++;
385             if(y>y1)
386             {
387                 y--;
388             }
389             else
390             {
391                    y++;
392             }
393                LCD_SetPoint(x,y,color);
394           }
395      }
396      else
397      {
398          LCD_SetPoint(x, y, color);
399           if(y < y1)
400           {
401                if(dx > dy)
402                {
403                 s16 p = dy * 2 - dx;
404                 s16 twoDy = 2 * dy;
405                 s16 twoDyMinusDx = 2 * (dy - dx);
406                 while(x < x1)
407                 {
408                      x++;
409                      if(p < 0)
410                      {
411                           p += twoDy;
412                      }
413                      else
414                      {
415                           y++;
416                           p += twoDyMinusDx;
417                      }
418                      LCD_SetPoint(x, y,color);
419                 }
420                }
421                else
422                {
423                 s16 p = dx * 2 - dy;
424                 s16 twoDx = 2 * dx;
425                 s16 twoDxMinusDy = 2 * (dx - dy);
426                 while(y < y1)
427                 {
428                      y++;
429                      if(p < 0)
430                      {
431                           p += twoDx;
432                      }
433                      else
434                      {
435                           x++;
436                           p+= twoDxMinusDy;
437                      }
438                      LCD_SetPoint(x, y, color);
439                 }
440                }
441           }
442           else
443           {
444                if(dx > dy)
445                {
446                 s16 p = dy * 2 - dx;
447                 s16 twoDy = 2 * dy;
448                 s16 twoDyMinusDx = 2 * (dy - dx);
449                 while(x < x1)
450                 {
451                      x++;
452                      if(p < 0)
453                      {
454                           p += twoDy;
455                      }
456                      else
457                      {
458                           y--;
459                           p += twoDyMinusDx;
460                      }
461                      LCD_SetPoint(x, y,color);
462                 }
463                }
464                else
465                {
466                 s16 p = dx * 2 - dy;
467                 s16 twoDx = 2 * dx;
468                 s16 twoDxMinusDy = 2 * (dx - dy);
469                 while(y1 < y)
470                 {
471                      y--;
472                      if(p < 0)
473                      {
474                           p += twoDx;
475                      }
476                      else
477                      {
478                           x++;
479                           p+= twoDxMinusDy;
480                      }
481                      LCD_SetPoint(x, y,color);
482                 }
483                }
484           }
485      }
486 }
View Code
 1 /*************************************************************************************************************************************
 2 *  
 3 *  文件名称:lcd_ILI9325.h
 4 *  文件功能:LCD初始化头文件
 5 *
 6 ***************************************************************************************************************************************/
 7 
 8 
 9 #ifndef _LCD_ILI9325_H
10 #define _LCD_ILI9325_H
11 #include "pbdata.h"
12 
13 
14 //6000 0000
15 //A16  16位通讯
16 
17 #define Bank1_LCD_D (u32)0x60020000   //命令位是1,所以在16位通讯命令格式时地址为2000
18 #define Bank1_LCD_C (u32)0x60000000   //数据位是0,所以在16位通讯数据格式时地址为0
19 
20 #define RGB565(r, g, b) ((r >> 3) << 11 | (g >> 2) << 5 | (b >> 3))   //三色转换
21 
22 #define RED   RGB565(255,0,0)        //红色
23 #define GREEN RGB565(0,255,0)        //绿色
24 #define BLUE  RGB565(0,0,255)        //蓝色
25 #define BLACK RGB565(0,0,0)            //黑色
26 #define WHITE RGB565(255,255,255)    //白色
27 
28 
29 
30 
31 void ILI9325_Init(void);//LCD初始化函数
32 void  LCD_WR_REG(u16  index);//写命令函数
33 void  LCD_WR_Data(u16  val);//写数据函数
34 void  LCD_WR_CMD(u16  index,u16  val);//同时写命令和数据函数
35 void  ILI_9325_Draw_Point(u8 x,u16 y,u16 color);//一个点写入颜色
36 void ILI_9325_CLEAR(u16 color);//清屏
37 
38 u16 LCD_RD_data(void);//读数据
39 void LCD_SetPoint(u16 x,u16 y,u16 color);//设置一个点的颜色
40 u16 LCD_GetPoint(u16 x,u16 y);//获取一个点
41 u16 LCD_BGR2RGB(u16 c);//颜色配置
42 void GUI_Line(u16 x0, u16 y0, u16 x1, u16 y1,u16 color);//GUI画线
43 
44 
45 
46 
47 #endif
View Code

 

 

3、GUI下载:

http://yunpan.cn/cQbD5YZi5mKTH (提取码:61f1)

 

 

4、例程工程下载:

 http://yunpan.cn/cQba77LEzVycu (提取码:70ad)

posted @ 2015-07-01 17:50  如风轻逸  阅读(663)  评论(0编辑  收藏  举报