码迷,mamicode.com
首页 > 其他好文 > 详细

lpc1788控制步进电机28BYJ-48

时间:2014-09-10 17:24:10      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   ar   2014   art   div   

bubuko.com,布布扣

下面直接上代码:

#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.

bubuko.com,布布扣 

bubuko.com,布布扣

lpc1788控制步进电机28BYJ-48

标签:style   blog   http   color   io   ar   2014   art   div   

原文地址:http://www.cnblogs.com/yibanshouxi/p/3964770.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!