初级会员
- 积分
- 53
- 金钱
- 53
- 注册时间
- 2015-7-23
- 在线时间
- 0 小时
|
5金钱
具体情况就是,在串口助手给了1个00或者01电机反应不理想,电机不是单纯的开或者关,而是停留在刚给00或者01这个转速的瞬间,即是给了00或者01,电机转速不变了。以下是我的中断服务函数的代码和MAIN函数的代码。
//中断服务函数:
void USART1_IRQHandler(void) //
{
u16 a;
while(1)
{
while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET){}
//if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
a= USART_ReceiveData(USART1);
switch(a) /
{
case 0:a2=0;break;
case 1:a2=1;break;
};
USART_SendData(USART1,a2);
while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET){}
//USART_RX_STA=0;
}
}
//MAIN函数:
int a2=0;
int a3=100;
int main(void)
{
// u16 led0pwmval=0;
// u8 dir=1;
// u8 t=0;
int b=1;
//KEY_Init(); //????????°??ü??????????????
NVIC_Configuration();
delay_init(); //???±??????????
uart_init(9600); //?®??????????9600
delay_init(); //???±??????????
LED_Init(); //????????LED??????????????
TIM3_PWM_Init(200,720);//??·?????PWM????=72000/(899+1)=80Khz
delay_ms(1500);
delay_ms(1500);
delay_ms(1500);
TIM_SetCompare1(TIM3,100);
TIM_SetCompare2(TIM3,100);
TIM_SetCompare3(TIM3,100);
TIM_SetCompare4(TIM3,100);
while(1)
{
if(a2==0)
delay_ms(50);
if(b)a3++;
else a3--;
if(a3>199) b=0;
if(a3==100) b=1;
TIM_SetCompare1(TIM3,a3);
TIM_SetCompare2(TIM3,a3);
TIM_SetCompare3(TIM3,a3);
TIM_SetCompare4(TIM3,a3);
if(a2==1)
TIM_SetCompare1(TIM3,0);
TIM_SetCompare2(TIM3,0);
TIM_SetCompare3(TIM3,0);
TIM_SetCompare4(TIM3,0);
}
}
|
|