#include "stm32f10x.h"
#define STEP_PIN GPIO_Pin_0
#define DIRECTION_PIN GPIO_Pin_1
#define ENABLE_PIN GPIO_Pin_2
void Delay(__IO uint32_t nCount) {
while(nCount--) {
}
}
void GPIO_Configuration(void) {
GPIO_InitTypeDef GPIO_InitStructure;
// Enable the GPIO Clock for Port A
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
// Configure STEP_PIN, DIRECTION_PIN, and ENABLE_PIN as output
GPIO_InitStructure.GPIO_Pin = STEP_PIN | DIRECTION_PIN | ENABLE_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
int main(void) {
GPIO_Configuration();
while(1) {
// Set the direction (0 or 1) using DIRECTION_PIN
GPIO_SetBits(GPIOA, DIRECTION_PIN);
// Enable the motor using ENABLE_PIN
GPIO_ResetBits(GPIOA, ENABLE_PIN);
// Generate a series of pulses to STEP_PIN to make the motor move
for (int i = 0; i < 200; i++) {
GPIO_SetBits(GPIOA, STEP_PIN);
Delay(10000); // Adjust this delay to control motor speed
GPIO_ResetBits(GPIOA, STEP_PIN);
Delay(10000); // Adjust this delay to control motor speed
}
// Disable the motor using ENABLE_PIN
GPIO_SetBits(GPIOA, ENABLE_PIN);
// Reverse direction
GPIO_ResetBits(GPIOA, DIRECTION_PIN);
// Enable the motor using ENABLE_PIN
GPIO_ResetBits(GPIOA, ENABLE_PIN);
// Generate a series of pulses to STEP_PIN to make the motor move in the reverse direction
for (int i = 0; i < 200; i++) {
GPIO_SetBits(GPIOA, STEP_PIN);
Delay(10000); // Adjust this delay to control motor speed
GPIO_ResetBits(GPIOA, STEP_PIN);
Delay(10000); // Adjust this delay to control motor speed
}
// Disable the motor using ENABLE_PIN
GPIO_SetBits(GPIOA, ENABLE_PIN);
}
}