首页 > 代码库 > lpc1788控制步进电机28BYJ-48
lpc1788控制步进电机28BYJ-48
下面直接上代码:
#include "lpc177x_8x.h"#include "lpc177x_8x_clkpwr.h"#include "lpc177x_8x_gpio.h"#include "debug_frmwrk.h"#include "led.h"volatile uint32_t cycleCounter;void DelayMs(uint32_t delay){ uint32_t startTime = cycleCounter; while ((uint32_t)(cycleCounter - startTime) <= delay);}void SysTick_Handler(void) //SysTick handler sub-routine (1ms) { cycleCounter++;}uint32_t a[8]={0xFF8FFFFF,0xFFCFFFFF,0xFF4FFFFF,0xFF6FFFFF,0xFF2FFFFF,0xFF3FFFFF,0xFF1FFFFF,0xFF9FFFFF}; int main(void){ SysTick_Config(CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU) / 1000); GPIO_Init();//ʹÄÜGPIO¿ÚµÄʱÖÓ GPIO_SetDir(4,1<<20, GPIO_DIRECTION_OUTPUT); GPIO_SetDir(4,1<<21, GPIO_DIRECTION_OUTPUT); GPIO_SetDir(4,1<<22, GPIO_DIRECTION_OUTPUT); GPIO_SetDir(4,1<<23, GPIO_DIRECTION_OUTPUT); while(1) { GPIO_SetValue(4, a[0]); DelayMs(1); GPIO_ClearValue(4,0xFFFFFFFF); GPIO_SetValue(4, a[1]); DelayMs(1); GPIO_ClearValue(4,0xFFFFFFFF); GPIO_SetValue(4, a[2]); DelayMs(1); GPIO_ClearValue(4,0xFFFFFFFF); GPIO_SetValue(4, a[3]); DelayMs(1); GPIO_ClearValue(4,0xFFFFFFFF); GPIO_SetValue(4, a[4]); DelayMs(1); GPIO_ClearValue(4,0xFFFFFFFF); GPIO_SetValue(4, a[5]); DelayMs(1); GPIO_ClearValue(4,0xFFFFFFFF); GPIO_SetValue(4, a[6]); DelayMs(1); GPIO_ClearValue(4,0xFFFFFFFF); GPIO_SetValue(4, a[7]); DelayMs(1); GPIO_ClearValue(4,0xFFFFFFFF); }}
其中GPIO_ClearValue(4,0xFFFFFFFF);这句代码非常重要。 因为如果有些位不清零的话,下次setvalue某些位为0是不行的,setvalue只能设置1.
lpc1788控制步进电机28BYJ-48
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。