LED灯循环左移代码(基于lpc1768)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include
volatile uint32_t msTicks; /* counts 1ms timeTicks */
/*----------------------------------------------------------------------------
SysTick_Handler
*----------------------------------------------------------------------------*/
/************************************************************************** ** Descriptions :SysTick interrupt handle
**
** parameters :None
** Returned value :None
*************************************************************************/ void SysTick_Handler(void)
{
msTicks++; /* increment counter necessary in Delay() */ }
/*------------------------------------------------------------------------------
delays number of tick Systicks (happens every 1 ms)
*------------------------------------------------------------------------------*/
__INLINE static void Delay (uint32_t dlyTicks)
{
uint32_t curTicks;
curTicks = msTicks; // 获取当前值
while ((msTicks - curTicks) < dlyTicks); //等待,即延时
}
/************************************************************************** ** Descriptions :Function that initializes LEDs
**
** parameters :None
** Returned value :None
*************************************************************************/ void DelayMs(unsigned int m)
{
int i,j;
for(i=m;i>0;i--)
{
for(j=3000;j>0;j--);
}
}
/************************************************************************** ** Descriptions :Function that initializes LEDs
**
** parameters :None
** Returned value :None
***********************************************************************/ void LedInit(void)
{
// PINSEL4,PINSEL5 设定P2.0 -- P2.32 端口功能(00,01,10,11)
LPC_PINCON->PINSEL4 = 0XFC000000; // p2.0--p2.13设置为IO
LPC_PINCON->PINMODE4 = 0XFC000000; // p2.0--p2.13设置为上拉电阻使能
LPC_GPIO2->FIODIR = 0X000000FF; // p2.0--p2.7设置为输出}
/************************************************************************** ** Descriptions :Function that LED on
**
** parameters :n , which led is on
** Returned value :None
*************************************************************************** /
void LedNOn(unsigned int n)
{
LPC_GPIO2->FIOSET = (1< } /************************************************************************** ** Descriptions :Function that LED off ** ** parameters :n , which led is 0ff ** Returned value :None *************************************************************************** / void LedNOff(unsigned int n) { LPC_GPIO2->FIOCLR = (1< } /*----------------------------------------------------------------------------