步进电机内部有动静但是外部轴不转是怎么回事?(附程序)

2019-08-20 16:41发布

[mw_shl_code=c,true]#include "sys.h" #include "delay.h" #define PB0 PBout(0) #define PB1 PBout(1) #define PB2 PBout(2) #define PB3 PBout(3) #define key0 PAin(13) #define key1 PAin(15) #define pulse PCin(2) #define close { PB0=0; PB1=0B2=0B3=0;} #define A { PB0=1; PB1=0B2=0B3=0;} #define B { PB0=0; PB1=1B2=0B3=0;} #define C { PB0=0; PB1=0B2=1B3=0;} #define D { PB0=0; PB1=0B2=0B3=1;} void GPIO_init(); void NVIC_Configuration(); void EXTIX_Init(); void EXTI2_IRQHandler(); void EXTI15_10_IRQHandler(); void key_init(); void pulse_init(); int main(void) { SystemInit();//?????±???????? delay_init(72);//???±?????? NVIC_Configuration(); GPIO_init(); EXTIX_Init(); while(1) { delay_ms(10000); } } void GPIO_init() { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOB,&GPIO_InitStructure); GPIO_SetBits(GPIOB,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3); } void pulse_init() { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOA, &GPIO_InitStructure); } void key_init() { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOA, &GPIO_InitStructure); } void EXTIX_Init() { EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; key_init(); pulse_init(); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource2); EXTI_InitStructure.EXTI_Line=EXTI_Line2; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource13); EXTI_InitStructure.EXTI_Line=EXTI_Line13; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource15); EXTI_InitStructure.EXTI_Line=EXTI_Line15; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } void EXTI2_IRQHandler() { delay_ms(10); if(EXTI_GetITStatus(EXTI_Line2) != RESET) //?ì?é???¨??EXTI0???·??·????ó·??ú??·? { delay_ms(9999); } EXTI_ClearITPendingBit(EXTI_Line2); //????EXTI0???·?????? } void EXTI15_10_IRQHandler() { delay_ms(10); if(EXTI_GetITStatus(EXTI_Line13) != RESET) { int i=128; close while(i--) { A delay_ms(500); B delay_ms(500); C delay_ms(500); D delay_ms(500); } }else if(EXTI_GetITStatus(EXTI_Line15) != RESET) { int j=128; close while(j--) { D delay_ms(40); C delay_ms(40); B delay_ms(40); A delay_ms(40); } } EXTI_ClearITPendingBit(EXTI_Line13); EXTI_ClearITPendingBit(EXTI_Line15); }[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。