单片机源程序如下:
- #include "stm32f10x.h"
- #include"duoji.h"
- #include<delay.h>
- #include"running.h"
- #include"ad.h"
- #include"infrared.h"
- #include<stdio.h>
- int main(void)
- {
- int u;
- short ad;
- delay_init();
- Adc_Init();
- duoji_Init(199,7199);
- TIM4_PWM_Init();
- running_Init(299);
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
- TIM_SetCompare2(TIM3,15);
- infrared_Init();
- while(1)
- {
- u=return1();
- ad=Get_adc1()-Get_adc1();
- if(u==3){
- running_Init(1000);
- }
-
- if(ad>-2&&ad<0)
- {
- TIM_SetCompare2(TIM3,20);
- delay_ms(1000);
-
- }
-
- if(ad>0&&ad<2)
- {
- TIM_SetCompare2(TIM3,10);
- delay_ms(2000);
-
- }
- if(ad<-2)
- {
- TIM_SetCompare2(TIM3,25);
- delay_ms(2000);
-
- }
- if(ad>2)
- {
- TIM_SetCompare2(TIM3,5);
- delay_ms(2000);
- }
- if(ad==0)
- {
- TIM_SetCompare2(TIM3,15);
- delay_ms(500);
- }
- }
- }
复制代码
所有资料51hei提供下载:
car.7z
(186.3 KB, 下载次数: 30)
|