#include "led.h"
#include "delay.h"
#include "sys.h"
#include "pwm.h"
#include "usart.h"
#include "string.h"
char cmd[200];
int main(void)
{
u8 t;
u8 len;
//u8 dir=1;
delay_init();
LED_Init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
uart_init(115200);
while(1)
{
TIM1_PWM_Init(199,7199);
if(USART_RX_STA&0x8000)
{
len=USART_RX_STA&0x3FFF;
for(t=0;t<len;t++)
{
cmd[t]=USART_RX_BUF[t];
while((USART1->SR&0X40)==0);
}
printf("\r\n receive successful \r\n");
USART_RX_STA=0;
if(!(strcmp(cmd,"1")))
{
TIM_SetCompare1(TIM1,37);
memset(cmd,0,strlen(cmd));
} //0度
else if(!(strcmp(cmd,"2")))
{
TIM_SetCompare1(TIM1,60);
memset(cmd,0,strlen(cmd));
} //45度
else if(!(strcmp(cmd,"3")))
{
TIM_SetCompare1(TIM1,93);
memset(cmd,0,strlen(cmd));
} //90度
else if(!(strcmp(cmd,"4")))
{
TIM_SetCompare1(TIM1,125);
memset(cmd,0,strlen(cmd));
} //135度
else if(!(strcmp(cmd,"5")))
{
TIM_SetCompare1(TIM1,160);
memset(cmd,0,strlen(cmd));
} //180度
else
printf("\r\n input error");
memset(cmd,0,strlen(cmd));
}
}
}
|