Tải bản đầy đủ - 0 (trang)
3 Lưu đồ thuật toán

3 Lưu đồ thuật toán

Tải bản đầy đủ - 0trang

Đô an hê thông nhung



//khai bao bien luu khoang cach cam bien sieu am do duoc///

int truoc,trai,phai;

GPIO_InitTypeDef GPIO_InitStructure;

NVIC_InitTypeDef NVIC_InitStructure;

EXTI_InitTypeDef EXTI_InitStructure;

TIM_OCInitTypeDef TIM_OCInitStructure;

uint16_t CCR2_Val = 600;

int bien,bien1,x,y,ok;

static __IO uint32_t TimingDelay;

int khoangcach,trai,phai,giua;

void RCC_Configuration(void)

{

RCC_APB2PeriphClockCmd(



RCC_APB2Periph_GPIOB



RCC_APB2Periph_GPIOA |

RCC_APB2Periph_AFIO,

ENABLE);

}

//ham tao delay//

void Delay1(__IO uint32_t nTime)

{

TimingDelay = nTime;



|



Đô an hê thông nhung



while(TimingDelay != 0);

}

void TimingDelay_Decrement(void)

{

if (TimingDelay != 0x00)

{

TimingDelay--;



// giam bien TimingDelay mot don vi khi



xay ra ngat timer//

}

}



void InitTimer2()



// cai dat timer 2//



{

TIM_TimeBaseInitTypeDef



TIM_TimeBaseStructure;



RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

TIM_TimeBaseStructure.TIM_Period

TIM_TimeBaseStructure.TIM_Prescaler



= 1000 - 1;

= 1000-1;



TIM_TimeBaseStructure.TIM_ClockDivision = 0;

TIM_TimeBaseStructure.TIM_CounterMode

TIM_CounterMode_Up;



=



Đô an hê thông nhung

TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

TIM_ARRPreloadConfig(TIM2, ENABLE);

/* TIM2 enable counter */

TIM_Cmd(TIM2, ENABLE);

}

void InitTimer1()

{

NVIC_InitTypeDef

TIM_TimeBaseInitTypeDef



NVIC_InitStructure;

TIM_TimeBaseStructure;



RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);

TIM_TimeBaseStructure.TIM_Period

TIM_TimeBaseStructure.TIM_Prescaler



= 60000-1;

= 72;



TIM_TimeBaseStructure.TIM_ClockDivision = 0;

TIM_TimeBaseStructure.TIM_CounterMode

TIM_CounterMode_Up;

TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

/* TIM2 enable counter */

TIM_Cmd(TIM1, ENABLE);

}

void InitTimer3()

{

NVIC_InitTypeDef



NVIC_InitStructure;



=



Đô an hê thông nhung

TIM_TimeBaseInitTypeDef



TIM_TimeBaseStructure;



NVIC_InitStructure.NVIC_IRQChannel



= TIM3_IRQn;



NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;

NVIC_InitStructure.NVIC_IRQChannelSubPriority

NVIC_InitStructure.NVIC_IRQChannelCmd



= 2;

= ENABLE;



NVIC_Init(&NVIC_InitStructure);

/* TIM2 clock enable */

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

/* Time base configuration */

TIM_TimeBaseStructure.TIM_Period

TIM_TimeBaseStructure.TIM_Prescaler



= 10-1;

= 72;



TIM_TimeBaseStructure.TIM_ClockDivision = 0;

TIM_TimeBaseStructure.TIM_CounterMode

TIM_CounterMode_Up;

TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

/* TIM IT enable */

TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);

/* TIM2 enable counter */

TIM_Cmd(TIM3, ENABLE);

}



=



Đô an hê thông nhung



void Delay(__IO uint32_t num)

{

__IO uint32_t index = 0;

for(index = (72000 * num); index != 0; index--)

{

}

}

void init_exti(void)

{

/* -----------------------------------------Initialize Key Button mounted on

STM3210X-GEM3M board------------------------------------------- */

/* Configure PB.01 as input floating */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOB, &GPIO_InitStructure);

/* SEL Button */

GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource1);

EXTI_ClearITPendingBit(KEY_BUTTON_EXTI_LINE);

EXTI_InitStructure.EXTI_Mode



= EXTI_Mode_Interrupt;



EXTI_InitStructure.EXTI_Line



= KEY_BUTTON_EXTI_LINE;



Đô an hê thông nhung

EXTI_InitStructure.EXTI_Trigger



=



EXTI_Trigger_Rising_Falling;

EXTI_InitStructure.EXTI_LineCmd



= ENABLE;



EXTI_Init(&EXTI_InitStructure);

/* Enable the EXTI1 Interrupt */

NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 15;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

}

void bat_pwm0()

{

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;

TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

TIM_OCInitStructure.TIM_Pulse = 506;

TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

// cai dat kenh ch1 timer 2//

TIM_OC1Init(TIM2, &TIM_OCInitStructure);

TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Enable);

}

void tat_pwm0()



Đô an hê thông nhung

{

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;

TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

TIM_OCInitStructure.TIM_Pulse = 1000;

TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

// cai dat kenh ch1 timer 2//

TIM_OC1Init(TIM2, &TIM_OCInitStructure);

TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Enable);

}

void bat_pwm1()

{

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;

TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

TIM_OCInitStructure.TIM_Pulse = 500;

TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

// cai dat kenh ch1 timer 2

TIM_OC2Init(TIM2, &TIM_OCInitStructure);

TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Enable);

}

void tat_pwm1()

{



Đô an hê thông nhung



TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;

TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

TIM_OCInitStructure.TIM_Pulse = 1000;

TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

TIM_OC2Init(TIM2, &TIM_OCInitStructure);

TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Enable);

}

void bat_pwm2()

{

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;

TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

TIM_OCInitStructure.TIM_Pulse = 500;

TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

TIM_OC3Init(TIM2, &TIM_OCInitStructure);

TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Enable);

}

void tat_pwm2()

{

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;

TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;



Đô an hê thông nhung

TIM_OCInitStructure.TIM_Pulse = 1000;

TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;



TIM_OC3Init(TIM2, &TIM_OCInitStructure);

TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Enable);

}

void bat_pwm3()

{

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;

TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

TIM_OCInitStructure.TIM_Pulse = 500;

TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

TIM_OC4Init(TIM2, &TIM_OCInitStructure);

TIM_OC4PreloadConfig(TIM2, TIM_OCPreload_Enable);

}

void tat_pwm3()

{

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;

TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

TIM_OCInitStructure.TIM_Pulse = 1000;

TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;



Đô an hê thông nhung

TIM_OC4Init(TIM2, &TIM_OCInitStructure);

TIM_OC4PreloadConfig(TIM2, TIM_OCPreload_Enable);

}



// cac ham dieu khien 2 banh dong co

// chan PA0, PA1, PA2 , PA3

//ham tien

void tien(void)

{

tat_pwm3();



//dk dong co ben phai quay ve phia truoc



bat_pwm2();

tat_pwm1();

bat_pwm0();

}

//ham dung xe

void dunglai(void)

{

tat_pwm3();

tat_pwm2();

tat_pwm1();

tat_pwm0();



//dk dong co ben phai quay ve phia truoc



Đô an hê thông nhung

}

//ham quay trai

void quaytrai(void)

{

bat_pwm3();



//dk dong co ben phai quay ve phia truoc



tat_pwm2();

tat_pwm1();



//dk dong co ben trai quay ve phia sau



bat_pwm0();

Delay(64);



//ham tao delay



tat_pwm3();



//dung ca hai banh



tat_pwm2();

tat_pwm1();

tat_pwm0();

}

// ham quay sang phai

void quayphai(void)

{

tat_pwm3();



//dk dong co ben phai quay ve phia sau



bat_pwm2();

bat_pwm1();

tat_pwm0();



//dk dong co ben trai quay ve phia sau



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

3 Lưu đồ thuật toán

Tải bản đầy đủ ngay(0 tr)

×