LPC1768之系统滴答定时器

        滴答定时器可作为实时系统的滴答时钟。MDK新建工程完成后,添加core_me.h到工程,static __INLINE uint32_t SysTick_Config(uint32_t ticks),在core_m3.h文件中。初始化时候调用即可。然后直接添加定时器中断处理函数即可。

/*************************************************************************************	  
*	main.c:  the main file 
*	NXP --> LPC1768
*
*   
*	Author	:	light					
*	Date	:	2012-4-16  
*
***************************************************************************************/

#include<LPC17XX.h>


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<<n);		
}
/********************************************************************************
** Descriptions			:Function that LED off
**
** parameters			:n , which led is 0ff
** Returned value		:None
*********************************************************************************/
void LedNOff(unsigned int n)
{
	LPC_GPIO2->FIOCLR = (1<<n);		
}

/*----------------------------------------------------------------------------
  The main Function 
 *----------------------------------------------------------------------------*/
int main(void)
{
	int loc;
	SystemInit();
	LedInit();	  
  	// SysTick定时器初始化
	if (SysTick_Config(0x05F5E100 / 1000))			/* Setup SysTick Timer for 1 msec interrupts  */
    {
		while (1);                                  /* Capture error */
  	}

	while(1)
	{
		for(loc=7;loc>=0;loc--)
		{
			LedNOn(loc);
			Delay(1000);

			LedNOff(loc);
			Delay(1000);
		}


	}

}


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值