#include "stm32f4xx.h" #include "dd.h" #include "stm32f4xx_rcc.c" #include "stm32f4xx_gpio.c" #include "LCD2x16.c" int steps[4] = {BIT_6, BIT_7, BIT_8, BIT_9}; //int steps[4] = {BIT_6 | BIT_7, BIT_7 | BIT_8, BIT_8 | BIT_9, BIT_9 | BIT_6}; int ptr_steps = 0; // initialize port C (Stepper motor), Pin_6 to Pin_9, and Pin_11 as outputs void STEPPERinit (void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOC, &GPIO_InitStructure); } // initialize port E (switches), Gpio_Pin_3 to GPIO_Pin_6 as inputs void SWITCHinit (void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_Init(GPIOE, &GPIO_InitStructure); } void main (void) { // char switches = 0; STEPPERinit(); SWITCHinit(); LCD_init(); // init LCD LCD_string("Stepper motor", 0x01); // display title string GPIOC->ODR |= GPIO_Pin_11; // enable motor driver while (1) { // switches = GPIOE->IDR; if (switches & S370) ptr_steps++; // S370 = 0x0008 else LED_GR_OFF; if (switches & S371) ptr_steps--; // S370 = 0x0010 else LED_OR_OFF; GPIOC->ODR &= ~0x3c0; GPIOC->ODR |= steps[ptr_steps & 0x03]; LCD_sInt16(ptr_steps,0x40,0x05); // write to LCD, signed, 16 bits for (int i = 0; i<1000000; i++) {}; // waste some time }; }