[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=0
B2=0
B3=0;}
#define A { PB0=1; PB1=0
B2=0
B3=0;}
#define B { PB0=0; PB1=1
B2=0
B3=0;}
#define C { PB0=0; PB1=0
B2=1
B3=0;}
#define D { PB0=0; PB1=0
B2=0
B3=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]
---------------------------------
我的步进电机也是这种情况,只能用手感受到在转动,但是看不到转动。
请问你是怎么解决的?
一周热门 更多>