📄 main.lst
字号:
210 RCC_PCLK2Config(RCC_HCLK_Div1);//APB2
211 RCC_PCLK1Config(RCC_HCLK_Div2);//APB1
212 RCC_HCLKConfig(RCC_SYSCLK_Div1);//AHB
213
214 #ifdef EMB_FLASH
215 // 5. Init Embedded Flash
216 // Zero wait state, if 0 < HCLK 24 MHz
217 // One wait state, if 24 MHz < HCLK 56 MHz
218 // Two wait states, if 56 MHz < HCLK 72 MHz
219 // Flash wait state
220 FLASH_SetLatency(FLASH_Latency_2);
221 // Half cycle access
222 FLASH_HalfCycleAccessCmd(FLASH_HalfCycleAccess_Disable);
223 // Prefetch buffer
224 FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
225 #endif // EMB_FLASH
226 // 5. Clock system from PLL
227 RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
228 }
229 /************************************************************************/
230 // Pos = (GetADC1Channel(ADC_Channel_15)*100);
231 /************************************************************************/
232 Int16U GetADC1Channel(Int8U chanel)
233 {
234 // Configure channel
235 ADC_RegularChannelConfig(ADC1, chanel, 1, ADC_SampleTime_55Cycles5);
236
237 // Start the conversion
238 ADC_SoftwareStartConvCmd(ADC1, ENABLE);
239
240 // Wait until conversion completion
241 while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
242
243 // Get the conversion value
244 return ADC_GetConversionValue(ADC1);
245 }
246 //////////////////////////////////////////////////////////////////
247 //////////////////////////////////////////////////////////////////
248 void InitADC1(void)
249 {
250 GPIO_InitTypeDef GPIO_InitStructure;
251 ADC_InitTypeDef ADC_InitStructure;
252
253 // ADC init
254 // ADC Deinit
255 RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
256 ADC_DeInit(ADC1);
257
258 // RC5 - analog input
259 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
260 GPIO_InitStructure.GPIO_Speed = (GPIOSpeed_TypeDef)0;
261 GPIO_InitStructure.GPIO_Mode = (GPIOMode_TypeDef)GPIO_Mode_AIN;
262 GPIO_Init (GPIOC, &GPIO_InitStructure);
263
264 // ADC Structure Initialization
265 ADC_StructInit(&ADC_InitStructure);
266
267 ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
268 ADC_InitStructure.ADC_ScanConvMode = DISABLE;
269 ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
270 ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
271 ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
272 ADC_InitStructure.ADC_NbrOfChannel = 1;
273 ADC_Init(ADC1, &ADC_InitStructure);
274
275 // Enable the ADC
276 ADC_Cmd(ADC1, ENABLE);
277
278 // ADC calibration
279 // Enable ADC1 reset calibaration register
280 ADC_ResetCalibration(ADC1);
281 // Check the end of ADC1 reset calibration register
282 while(ADC_GetResetCalibrationStatus(ADC1) == SET);
283
284 // Start ADC1 calibaration
285 ADC_StartCalibration(ADC1);
286 // Check the end of ADC1 calibration
287 while(ADC_GetCalibrationStatus(ADC1) == SET);
288
289 }
290
291
292
293 void ADC_TEMP(Int16U *p)
294 {
295 Int16U a,c;
296 Int32U b;
297 static Int16U ADC_COUNT;
298 static Int16U TAD[8];
299 a=GetADC1Channel(ADC_Channel_13);
300 TAD[7]=TAD[6];
301 TAD[6]=TAD[5];
302 TAD[5]=TAD[4];
303 TAD[4]=TAD[3];
304 TAD[3]=TAD[2];
305 TAD[2]=TAD[1];
306 TAD[1]=TAD[0];
307 TAD[0]=a;
308 if(++ADC_COUNT>=5)
309 {
310 ADC_COUNT=0;
311 b=0;
312 for(a=0;a<8;a++)
313 b+=TAD[a];
314 b=b/8;
315 b>>=4;
316 c=TEMP_TAB[0];
317 for(a=0;a<130&&(c>b);)
318 c=TEMP_TAB[++a];
319 *p=a;
320 if(b>=0xfa)*p=0xff;
321 }
322 }
323 /*************************************************************************
324 * Function Name: Dly100us
325 * Parameters: Int32U Dly
326 *
327 * Return: none
328 *
329 * Description: Delay Dly * 100us
330 *
331 *************************************************************************/
332 void delay(Int16U Dly)
333 {
334 Int16U i=0;
335 for(;i<Dly;i++);
336 }
337 void delay_nop(Int16U Dly)
338 {
339 Int16U i;
340 while(Dly--)
341 {
342 for(i=LOOP_DLY_100US; i; i--)WWDG_ClearFlag();
343 }
344 }
345
346 /*************************************************************************
347 * Function Name: InitADC1
348 * Parameters: none
349 * Return: none
350 *
351 * Description: ADC Init subroutine
352 *
353 *************************************************************************/
354 void InitGPIO(void)
355 {
356 GPIO_InitTypeDef GPIO_InitStructure;
357 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD|
358 RCC_APB2Periph_GPIOA,ENABLE);
359 GPIO_DeInit(GPIOA);
360 GPIO_DeInit(GPIOB);
361 GPIO_DeInit(GPIOC);
362 GPIO_DeInit(GPIOD);
363 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_2|GPIO_Pin_3|
364 GPIO_Pin_4|
365 GPIO_Pin_8|GPIO_Pin_11|GPIO_Pin_12;
366 GPIO_InitStructure.GPIO_Speed = (GPIOSpeed_TypeDef)3;
367 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
368 GPIO_Init (GPIOA, &GPIO_InitStructure); //setion output
369
370
371
372 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_1|GPIO_Pin_4|GPIO_Pin_5|
373 GPIO_Pin_6|GPIO_Pin_7;
374
375 GPIO_InitStructure.GPIO_Speed = (GPIOSpeed_TypeDef)0;
376 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
377 GPIO_Init (GPIOA, &GPIO_InitStructure); //setion pull-up input
378
379 GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0|GPIO_Pin_5|GPIO_Pin_11|GPIO_Pin_2|GPIO_Pin_9| GPIO_Pin_11;
380 GPIO_InitStructure.GPIO_Speed = (GPIOSpeed_TypeDef)0;
381 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
382 GPIO_Init (GPIOB, &GPIO_InitStructure);
383 GPIO_InitStructure.GPIO_Pin =GPIO_Pin_1|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_8|
384 GPIO_Pin_7|GPIO_Pin_10|
385 GPIO_Pin_12|GPIO_Pin_13|
386 GPIO_Pin_14|GPIO_Pin_15;
387 GPIO_InitStructure.GPIO_Speed = (GPIOSpeed_TypeDef)3;
388 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
389 GPIO_Init (GPIOB, &GPIO_InitStructure);
390 GPIO_Write(GPIOB,0xFE00);
391
392 GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0|GPIO_Pin_3|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|
393 GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|
394 GPIO_Pin_12|GPIO_Pin_11 ;
395 GPIO_InitStructure.GPIO_Speed = (GPIOSpeed_TypeDef)3;
396 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
397 GPIO_Init (GPIOC, &GPIO_InitStructure);
398
399 GPIO_InitStructure.GPIO_Pin =GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_4;
400 GPIO_InitStructure.GPIO_Speed = (GPIOSpeed_TypeDef)0;
401 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
402 GPIO_Init (GPIOC, &GPIO_InitStructure);
403
404
405 }
406 void InitTemperature()
407 {
408
409 TemRHA.IOD=GPIOC;
410 TemRHA.IO_D=12;
411 TemRHA.IOC=GPIOD;
412 TemRHA.IO_C=2;
413 //TemRHB->IOD=GPIOB,TemRHA->IOD=GPIO_Pin_2,TemRHA->IOC=GPIOB,TemRHA->IOC=GPIO_Pin_2;
414 }
415 void InitI2CFALSE()
416 {
417 GPIO_InitTypeDef GPIO_InitStructure;
418 GPIO_InitStructure.GPIO_Pin =GPIO_Pin_6|GPIO_Pin_7;
419 GPIO_InitStructure.GPIO_Speed = (GPIOSpeed_TypeDef)3;
420 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
421 GPIO_Init (GPIOB, &GPIO_InitStructure);
422
423 }
424 /*************************************************************************
425 *************************************************************************/
426 void TimInit(void)
427 {
428 TIM1_TimeBaseInitTypeDef TIM1_TimeBaseInitStruct;
429 TIM_TimeBaseInitTypeDef TIM2_TimeBaseInitStruct;
430 RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
431 //RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM1,DISABLE);
432 // Set timer period 0.2 sec
433 TIM1_TimeBaseInitStruct.TIM1_Prescaler = 720; // 10us resolution
434 TIM1_TimeBaseInitStruct.TIM1_CounterMode = TIM1_CounterMode_Up;
435 TIM1_TimeBaseInitStruct.TIM1_Period = 250; // 200 ms
436 TIM1_TimeBaseInitStruct.TIM1_ClockDivision = TIM1_CKD_DIV1;
437 TIM1_TimeBaseInitStruct.TIM1_RepetitionCounter = 0;
438 TIM1_TimeBaseInit(&TIM1_TimeBaseInitStruct);
439 // Clear update interrupt bit
440 TIM1_ClearITPendingBit(TIM1_FLAG_Update);//
441 // Enable update interrupt
442 TIM1_ITConfig(TIM1_FLAG_Update,ENABLE);
443 TIM1_Cmd(ENABLE);
444
445 TIM_DeInit(TIM2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -