一、例程代碼:redis
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 SPI1_Configuration();//SPI1配置 47 48 Touch_GPIO();//觸摸屏GPIO配置 49 50 GUI_Init();//GUI初始化 51 GUI_SetBkColor(GUI_BLUE);//設置背景顏色爲藍色 52 GUI_Clear();//清屏 53 54 GUI_SetFont(&GUI_Font24_ASCII);//字體設置 55 GUI_SetColor(GUI_RED);//顏色 56 57 58 GUI_DispStringAt("liubo",40,150);//顯示字符 59 60 61 GUI_CURSOR_Show();//鼠標顯示,在觸屏上顯示鼠標箭頭 62 63 64 65 /*主程序,每次隔1s顯示不一樣的顏色*/ 66 while(1) 67 { 68 if(PEN==0)//若是有觸控 69 { 70 GUI_TOUCH_Exec(); 71 } 72 WM_Exec();//刷新整個窗體 73 delay_ms(20);//延時 74 } 75 } 76 77 78 79 80 81 /******************************************************************************** 82 * 83 * 函數名稱:RCC_Configuration(void) 84 * 函數功能:系統時鐘高初始化函數 85 * 86 ********************************************************************************/ 87 void RCC_Configuration(void)//系統時鐘高初始化函數 88 { 89 90 SystemInit();//系統初始化 91 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);//串口對應GPIO時鐘使能 92 RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);//串口時鐘使能 93 RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//引腳複用 94 95 /*LCD使用的引腳配置時鐘*/ 96 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); 97 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE); 98 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE); 99 100 101 /*觸摸屏使用的引腳時鐘配置*/ 102 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); 103 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); 104 RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1,ENABLE); 105 106 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC,ENABLE);//FSMC時鐘配置 107 108 109 } 110 111 112 113 /******************************************************************************* 114 * 115 * 函數名稱:GPIO_Configuration(void) 116 * 函數功能:GPIO初始化函數 117 * 118 ********************************************************************************/ 119 120 void GPIO_Configuration(void)//GPIO初始化函數 121 { 122 123 124 /*串口引腳配置*/ 125 GPIO_InitTypeDef GPIO_InitStructure;//定義一個GPIO設置的結構體變量 126 127 /*輸出引腳配置*/ 128 /*結構體變量賦值*/ 129 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;////引腳配置TX 130 GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;//配置頻率 131 GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;//發送要配置成複用推輓輸出 132 /*對應的GPIO初始化*/ 133 GPIO_Init(GPIOA,&GPIO_InitStructure); 134 135 136 /*輸入引腳配置*/ 137 /*結構體變量賦值*/ 138 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;////引腳配置RX 139 GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;//接收引腳配置成浮空輸入 140 /*對應的GPIO初始化*/ 141 GPIO_Init(GPIOA,&GPIO_InitStructure); 142 143 144 145 /*FSMC管腳初始化*/ 146 /*結構體變量賦值*/ 147 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_13;//引腳配置 148 GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;//頻率配置 149 GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;//輸出 150 /*對應的GPIO初始化*/ 151 GPIO_Init(GPIOD,&GPIO_InitStructure);//完成初始化 152 153 GPIO_SetBits(GPIOD,GPIO_Pin_13);//打開背光 154 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_1;//復位 155 GPIO_Init(GPIOE,&GPIO_InitStructure); 156 157 /*啓用fsmc複用功能,複用上拉模式*/ 158 GPIO_InitStructure.GPIO_Pin =GPIO_Pin_14 //D0 159 |GPIO_Pin_15 //D1 160 |GPIO_Pin_0 //D2 161 |GPIO_Pin_1 //D3 162 |GPIO_Pin_8 //D13 163 |GPIO_Pin_9 //D14 164 |GPIO_Pin_10;//D15 165 GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP; 166 GPIO_Init(GPIOD,&GPIO_InitStructure); 167 168 GPIO_InitStructure.GPIO_Pin =GPIO_Pin_7 //D4 169 |GPIO_Pin_8 //D5 170 |GPIO_Pin_9 //D6 171 |GPIO_Pin_10 //D7 172 |GPIO_Pin_11 //D8 173 |GPIO_Pin_12 //D9 174 |GPIO_Pin_13 //D10 175 |GPIO_Pin_14 //D11 176 |GPIO_Pin_15;//D12 177 GPIO_Init(GPIOE,&GPIO_InitStructure); 178 179 180 GPIO_InitStructure.GPIO_Pin =GPIO_Pin_11 //RS 181 |GPIO_Pin_4 //nOE 182 |GPIO_Pin_5; //nWE 183 GPIO_Init(GPIOD,&GPIO_InitStructure); 184 185 GPIO_InitStructure.GPIO_Pin =GPIO_Pin_7; //NE1 186 GPIO_Init(GPIOD,&GPIO_InitStructure); 187 188 189 190 191 } 192 193 194 195 196 197 /**************************************************************************** 198 * 199 * 函數名稱:NVIC_Configuration(void) 200 * 函數功能:配置中斷優先級 201 * 202 ****************************************************************************/ 203 204 void NVIC_Configuration(void) 205 { 206 NVIC_InitTypeDef NVIC_InitStructure; //定義一個優先級配置結構體變量 207 208 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//分組 209 210 NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; 211 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;//搶斷優先級 212 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;//響應優先級 213 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//使能 214 215 NVIC_Init(&NVIC_InitStructure);//初始化 216 } 217 218 219 /********************************************************************************* 220 * 221 * 函數名稱:USART_Configuration(void) 222 * 函數功能:串口配置函數 223 * 224 *********************************************************************************/ 225 void USART_Configuration(void) 226 { 227 /*定義串口配置結構體變量*/ 228 USART_InitTypeDef USART_InitStructure;//定義一個串口配置結構體變量 229 230 231 /*結構體變量賦值*/ 232 USART_InitStructure.USART_BaudRate = 9600;//波特率9600 233 USART_InitStructure.USART_WordLength = USART_WordLength_8b;//位寬,8位 234 USART_InitStructure.USART_StopBits = USART_StopBits_1;//中止位1 235 USART_InitStructure.USART_Parity = USART_Parity_No;//不奇偶校驗 236 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//流控禁止 237 USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;//發送使能 238 239 240 /*發送串口配置初始化*/ 241 USART_Init(USART1, &USART_InitStructure); 242 243 244 /*打開串口接收中斷*/ 245 USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);//當接收到數據時,會產生中斷 246 247 248 /*打開串口*/ 249 USART_Cmd(USART1,ENABLE);//串口使能,打開 250 251 /*清空中斷標誌位*/ 252 USART_ClearFlag(USART1,USART_FLAG_TC); 253 } 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
1 /**************************************************************************************************************** 2 * 3 * 文件名稱:pbdata.c 4 * 文件功能:自定義函數或者全局變量的初始化 5 * 6 ****************************************************************************************************************/ 7 8 /*頭文件聲明*/ 9 #include "pbdata.h" 10 11 12 13 14 /******************************************************************************************** 15 * 16 * 自定義全局變量 17 * 18 ********************************************************************************************/ 19 u8 dt=0; 20 u16 touch_x=0; 21 u16 touch_y=0; 22 23 24 25 26 /****************************************************************************************** 27 * 28 * 自定義函數 29 * 30 ******************************************************************************************/ 31 32 /************************************* 33 * 34 * 時鐘配置 35 * HSE做爲PLL時鐘 36 * PLL做爲SYSCLK 37 * 38 **************************************/ 39 void RCC_HSE_Configuration(void) 40 { 41 RCC_DeInit(); //將外設RCC寄存器重設爲缺省值 42 RCC_HSEConfig(RCC_HSE_ON); //設置外部高速晶振HSE,HSE晶振打開ON 43 44 if(RCC_WaitForHSEStartUp() == SUCCESS)//等待HSE起震,SUCCESS:HSE晶振穩定且就緒 45 { 46 47 RCC_HCLKConfig(RCC_SYSCLK_Div1);//設置AHB時鐘 48 RCC_PCLK2Config(RCC_HCLK_Div1); //設置高速AHB時鐘 49 RCC_PCLK1Config(RCC_HCLK_Div2); //設置低速AHB時鐘 50 51 RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);///設置PLL時鐘源及倍頻係數 52 RCC_PLLCmd(ENABLE); //使能PLL 53 while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) ; ///檢查指定的RCC標誌位(PLL準備好標誌)設置是否 54 55 RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); //設置系統時鐘 56 while(RCC_GetSYSCLKSource() != 0x08); //0x08:PLL做爲系統時鐘 57 58 } 59 } 60 61 62 63 64 65 66 67 /************************************************** 68 * 69 * 普通延時函數 70 * 71 ***************************************************/ 72 void delay(u32 nCount) 73 { 74 for(;nCount!=0;nCount--); 75 } 76 77 78 79 80 /************************************************** 81 * 82 * 函數名稱:delay_us(u32 nus) 83 * 函數功能:微秒延時函數 84 * 輸入參數:輸入值爲延時us 85 * 86 ***************************************************/ 87 void delay_us(u32 nus) 88 { 89 u32 temp; 90 SysTick->LOAD = 9*nus;//載入初值,72M/8=9M,也就是1/9us,9*1/9us,因此是執行9次 91 SysTick->VAL=0X00;//清空計數器,清空後,就自動設置本身設定的計數器的值 92 SysTick->CTRL=0X01;//使能,減到零動做(不發生中斷),採用外部時鐘 93 94 do 95 { 96 temp=SysTick->CTRL;//標誌位,等到一直減到0 97 }while((temp&0x01)&&(!(temp&(1<<16))));//等待時間到達 98 99 SysTick->CTRL=0x00; //關閉計數器 100 SysTick->VAL =0X00; //清空計數器 101 } 102 103 104 105 106 107 108 109 /*************************************************** 110 * 111 * 函數名稱:delay_ms(u16 nms) 112 * 函數功能:毫秒級延時 113 * 輸入參數:輸入值位延時ms 114 * 115 ****************************************************/ 116 void delay_ms(u16 nms) 117 { 118 u32 temp; 119 SysTick->LOAD = 9000*nms;//載入初值,72M/8=9M,也就是1/9us,9*1/9us,因此是執行9000次 120 SysTick->VAL=0X00;//清空計數器,清空後,就自動設置本身設定的計數器的值 121 SysTick->CTRL=0X01;//使能,減到零動做(不發生中斷),採用外部時鐘 122 123 do 124 { 125 temp=SysTick->CTRL;//標誌位,等到一直減到0 126 }while((temp&0x01)&&(!(temp&(1<<16))));//等待時間到達 127 128 SysTick->CTRL=0x00; //關閉計數器 129 SysTick->VAL =0X00; //清空計數器 130 } 131 132 133 134 /**************************************************** 135 * 136 * 重定義printf函數部分 137 * 138 ****************************************************/ 139 int fputc(int ch,FILE *F) 140 { 141 142 USART_SendData(USART1,(u8)ch); 143 144 while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);//等待發送完成,判斷標誌位 145 146 return ch; 147 }
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 #include "stm32_spi.h" 57 #include "stm32_touch.h" 58 59 60 61 /******************************************************************** 62 * 63 * 自定義全局變量聲明 64 * 65 ********************************************************************/ 66 extern u8 dt; 67 extern u16 touch_x; 68 extern u16 touch_y; 69 70 71 72 73 /******************************************************************** 74 * 75 * 自定義全函數聲明 76 * 77 ********************************************************************/ 78 void delay(u32 nCount); 79 void delay_us(u32 nus); 80 void delay_ms(u16 nms); 81 int fputc(int ch,FILE *F); 82 83 84 85 #endif
1 /************************************************************************************************************************************* 2 * 3 * 文件名稱:stm32_spi.c 4 * 文件功能:SPI相關函數 5 * 6 ***************************************************************************************************************************************/ 7 8 9 10 #include "pbdata.h" 11 12 13 14 15 /********************************************************************************* 16 * 17 * 函數名稱:void SPI_Configuration(void) 18 * 函數功能:SPI配置函數 19 * 20 *********************************************************************************/ 21 22 void SPI1_Configuration(void) 23 { 24 25 /*定義一個SPI配置結構體變量*/ 26 SPI_InitTypeDef SPI_InitStructure; 27 28 /*定義一個SPI的GPIO配置結構體變量*/ 29 GPIO_InitTypeDef GPIO_InitStructure; 30 31 /*配置GPIO*/ 32 /*GPIO配置結構體變量賦值*/ 33 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;////引腳配置 34 GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;//配置頻率 35 GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;//發送要配置成複用推輓輸出 36 /*對應的GPIO初始化*/ 37 GPIO_Init(GPIOA,&GPIO_InitStructure); 38 39 40 /*以太網片選配置*/ 41 /*以太網GPIO配置結構體變量賦值*/ 42 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7;//以太網引腳配置 43 GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;//配置頻率 44 GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;//發送配置 45 /*對應的GPIO初始化*/ 46 GPIO_Init(GPIOB,&GPIO_InitStructure); 47 48 49 /*觸摸屏片選配置*/ 50 /*以太網GPIO配置結構體變量賦值*/ 51 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4;//觸摸屏引腳配置 52 GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;//配置頻率 53 GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;//發送配置 54 /*對應的GPIO初始化*/ 55 GPIO_Init(GPIOC,&GPIO_InitStructure); 56 57 58 59 /*Flash片選配置*/ 60 /*FlashGPIO配置結構體變量賦值*/ 61 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6;//flash引腳配置 62 GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;//配置頻率 63 GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;//發送配置 64 /*對應的GPIO初始化*/ 65 GPIO_Init(GPIOE,&GPIO_InitStructure); 66 67 68 69 /*SPI1配置*/ 70 /*SPI1配置結構體變量賦值*/ 71 SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;//雙線雙向全雙工 72 SPI_InitStructure.SPI_Mode = SPI_Mode_Master;//CPU主模式 73 SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;//8位發送 74 SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;//懸空時爲低 75 SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;//第一個時鐘沿捕獲 76 SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;//內部管理 77 SPI_InitStructure.SPI_BaudRatePrescaler =SPI_BaudRatePrescaler_64;//864分頻 78 SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;//高位開始發送 79 SPI_InitStructure.SPI_CRCPolynomial = 7; 80 /*SPI1初始化*/ 81 SPI_Init(SPI1, &SPI_InitStructure); 82 83 SPI_Cmd(SPI1,ENABLE); //使能SPI 84 85 86 87 /*禁止片選*/ 88 GPIO_SetBits(GPIOB,GPIO_Pin_7);//禁止以太網 89 GPIO_SetBits(GPIOC,GPIO_Pin_4);//禁止觸摸屏 90 GPIO_SetBits(GPIOE,GPIO_Pin_6);//禁止flash 91 92 } 93 94 95 96 97 98 99 100 101 /********************************************************************************* 102 * 103 * 函數名稱:u8 SPI_SendByte(u8 byte) 104 * 函數功能:SPI發送數據函數 105 * 106 *********************************************************************************/ 107 108 u8 SPI1_SendByte(u8 byte) 109 { 110 while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE)==RESET);//判斷是否忙 111 112 SPI_I2S_SendData(SPI1,byte);//發送 113 114 while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_RXNE)==RESET);//判斷是否忙 115 116 return SPI_I2S_ReceiveData(SPI1); 117 118 }
1 #ifndef _STM32_SPI_H 2 #define _STM32_SPI_H 3 4 void SPI1_Configuration(void);//SPIÅäÖú¯Êý 5 u8 SPI1_SendByte(u8 byte);//SPI·¢ËÍÊý¾Ýº¯Êý 6 7 #endif
1 /************************************************************************************************************************************* 2 * 3 * 文件名稱:stm32_touch.c 4 * 文件功能:觸摸屏函數 5 * 6 ***************************************************************************************************************************************/ 7 #include "pbdata.h" 8 9 10 11 12 /******************************************************************************** 13 * 14 * 函數名稱:Touch_GPIO 15 * 函數功能:觸摸屏GPIO初始化 16 * 17 ********************************************************************************/ 18 void Touch_GPIO(void) 19 { 20 GPIO_InitTypeDef GPIO_InitStructure;//結構體變量定義 21 22 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6;//引腳配置 23 GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;//上拉輸入 24 25 GPIO_Init(GPIOB,&GPIO_InitStructure);//完成初始化 26 } 27 28 29 30 31 32 33 /******************************************************************************** 34 * 35 * 函數名稱:TPReadX 36 * 函數功能:讀取X軸 37 * 38 ********************************************************************************/ 39 u16 TPReadX(void) 40 { 41 u16 x=0; 42 43 TP_CS();//拉低 44 delay_us(5);//延時 45 SPI1_SendByte(0xD0);//發送命令 46 delay_us(5);//延時 47 x=SPI1_SendByte(0x00);//讀數據,8位到x,高8位 48 x<<=8;//移動到高8位 49 x+=SPI1_SendByte(0x00);//讀數據,低8位讀了後加到高位 50 delay_us(5);//延時 51 TP_DCS();//拉高 52 x>>=3;//16位,只有12位數,去除低3位 53 return x; 54 } 55 56 57 58 59 60 61 62 63 /******************************************************************************** 64 * 65 * 函數名稱:TPReadY 66 * 函數功能:讀取Y軸 67 * 68 ********************************************************************************/ 69 u16 TPReadY(void) 70 { 71 u16 y=0; 72 73 TP_CS();//拉低 74 delay_us(5);//延時 75 SPI1_SendByte(0x90);//發送命令 76 delay_us(5);//延時 77 y=SPI1_SendByte(0x00);//讀數據,8位到x,高8位 78 y<<=8;//移動到高8位 79 y+=SPI1_SendByte(0x00);//讀數據,低8位讀了後加到高位 80 delay_us(5);//延時 81 TP_DCS();//拉高 82 y>>=3;//16位,只有12位數,去除低3位 83 return y; 84 }
1 /************************************************************************************************************************************* 2 * 3 * 文件名稱:stm32_touch.h 4 * 文件功能:觸摸屏函數聲明 5 * 6 ***************************************************************************************************************************************/ 7 8 #ifndef _STM32_TOUCH_H 9 #define _STM32_TOUCH_H 10 11 #include "pbdata.h" 12 13 #define TP_CS() GPIO_ResetBits(GPIOC,GPIO_Pin_4)//低電平片選 14 #define TP_DCS() GPIO_ResetBits(GPIOC,GPIO_Pin_4)//高電平釋放 15 16 #define PEN GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_6) 17 18 19 void Touch_GPIO(void);//觸摸屏GPIO初始化 20 u16 TPReadX(void);//讀取X軸 21 u16 TPReadY(void);//讀取Y軸 22 23 24 25 #endif
1 /************************************************************************************************************************************* 2 * 3 * 文件名稱:LCDConf.h 4 * 文件功能:GUI配置文件 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 (240) 26 #define LCD_YSIZE (320) 27 28 #define LCD_BITSPERPIXEL (16)//像素 29 #define LCD_SWAP_RB (1) //紅藍轉換 30 #define LCD_CONTROLLER 9325//驅動 31 32 33 #endif /* LCDCONF_H */
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 (1) //觸摸屏支持定義,1打開,0關閉 19 #define GUI_SUPPORT_MOUSE (1) //鼠標支持,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
1 /* 2 ********************************************************************************************************* 3 * uC/GUI V3.98 4 * Universal graphic software for embedded applications 5 * 6 * (c) Copyright 2002, Micrium Inc., Weston, FL 7 * (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH 8 * 9 * µC/GUI is protected by international copyright laws. Knowledge of the 10 * source code may not be used to write a similar product. This file may 11 * only be used in accordance with a license and should not be redistributed 12 * in any way. We appreciate your understanding and fairness. 13 * 14 ---------------------------------------------------------------------- 15 File : GUITouch.Conf.h 16 Purpose : Configures touch screen module 17 ---------------------------------------------------------------------- 18 */ 19 20 21 #ifndef GUITOUCH_CONF_H 22 #define GUITOUCH_CONF_H 23 24 /*触摸AD*/ 25 #define GUI_TOUCH_AD_LEFT 0 26 #define GUI_TOUCH_AD_RIGHT 4095 27 #define GUI_TOUCH_AD_TOP 0 28 #define GUI_TOUCH_AD_BOTTOM 4095 29 30 31 /*é•œåƒï¼Œå¦‚果方å‘ä¸å¯¹ï¼Œå¯ä¿®æ」¹*/ 32 #define GUI_TOUCH_SWAP_XY 0 33 #define GUI_TOUCH_MIRROR_X 0 34 #define GUI_TOUCH_MIRROR_Y 1 35 36 #endif /* GUITOUCH_CONF_H */ 37
1 /************************************************************************************************************************************* 2 * 3 * 文件名稱:GUI_X_Touch.c 4 * 文件功能:主函數文件 5 * 6 ***************************************************************************************************************************************/ 7 #include "pbdata.h" 8 9 10 11 12 13 /********************************************************************************* 14 * 15 * 函數名稱:GUI_TOUCH_X_ActivateX 16 * 函數功能: 17 * 輸入參數: 18 * 輸出參數: 19 * 函數說明: 20 * 21 *********************************************************************************/ 22 /*void GUI_TOUCH_X_ActivateX(void) 23 { 24 } 25 */ 26 27 void GUI_TOUCH_X_ActivateX(void) 28 { 29 30 } 31 32 33 34 35 36 /********************************************************************************* 37 * 38 * 函數名稱:GUI_TOUCH_X_ActivateY 39 * 函數功能: 40 * 輸入參數: 41 * 輸出參數: 42 * 函數說明: 43 * 44 *********************************************************************************/ 45 /*void GUI_TOUCH_X_ActivateY(void) 46 { 47 }*/ 48 49 50 void GUI_TOUCH_X_ActivateY(void) 51 { 52 53 } 54 55 56 57 58 59 /********************************************************************************* 60 * 61 * 函數名稱:GUI_TOUCH_X_MeasureX 62 * 函數功能: 63 * 輸入參數: 64 * 輸出參數: 65 * 函數說明: 66 * 67 *********************************************************************************/ 68 /* 69 int GUI_TOUCH_X_MeasureX(void) 70 { 71 u16 count=0; 72 u16 buffer[10]={0}; 73 u32 tp_x=0; 74 75 do 76 { 77 buffer[count]=TPReadX();//保存X軸的值 78 count++; 79 } while((PEN==0)&&count<10); 80 81 if(count==10) 82 { 83 tp_x=0; 84 for(count=0;count<10;count++) 85 { 86 tp_x=tp_x+buffer[count];//X軸值累加 87 } 88 89 /這個是AD出來的值/ 90 touch_x=tp_x/10; 91 } 92 93 return touch_x; 94 95 } 96 */ 97 int GUI_TOUCH_X_MeasureX(void) 98 { 99 u16 count=0; 100 u16 buffer[10]={0}; 101 u32 tp_x=0; 102 103 do 104 { 105 buffer[count]=TPReadX(); 106 count++; 107 }while((PEN==0)&&count<10); 108 109 if(count==10) 110 { 111 tp_x=0; 112 for(count=0;count<10;count++) 113 { 114 tp_x=tp_x+buffer[count]; 115 } 116 117 touch_x=tp_x/10; 118 } 119 120 return touch_x; 121 } 122 123 124 125 126 127 128 129 130 /********************************************************************************* 131 * 132 * 函數名稱:GUI_TOUCH_X_MeasureY 133 * 函數功能: 134 * 輸入參數: 135 * 輸出參數: 136 * 函數說明: 137 * 138 *********************************************************************************/ 139 140 /* 141 int GUI_TOUCH_X_MeasureY(void) 142 { 143 u16 count=0; 144 u16 buffer[10]={0}; 145 u32 tp_y=0; 146 147 do 148 { 149 buffer[count]=TPReadY();//保存X軸的值 150 count++; 151 } while((PEN==0)&&count<10); 152 153 if(count==10) 154 { 155 tp_y=0; 156 for(count=0;count<10;count++) 157 { 158 tp_y=tp_y+buffer[count];//X軸值累加 159 } 160 161 /這個是AD出來的值/ 162 touch_y=tp_y/10; 163 } 164 165 return touch_y; 166 167 } 168 169 170 */ 171 172 173 174 int GUI_TOUCH_X_MeasureY(void) 175 { 176 u16 count=0; 177 u16 buffer[10]={0}; 178 u32 tp_y=0; 179 180 do 181 { 182 buffer[count]=TPReadY(); 183 count++; 184 }while((PEN==0)&&count<10); 185 186 if(count==10) 187 { 188 tp_y=0; 189 for(count=0;count<10;count++) 190 { 191 tp_y=tp_y+buffer[count]; 192 } 193 194 touch_y=tp_y/10; 195 } 196 197 return touch_y; 198 }
二、工程下載:app
http://yunpan.cn/cQD6Jw956PV48 (提取碼:8b1e)ide