亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? timer16.c

?? CortexM0上移植UCOS-II
?? C
字號:
/****************************************************************************
 *   $Id:: timer16.c 4071 2010-07-30 03:17:04Z usb00423                     $
 *   Project: NXP LPC11xx 16-bit timer example
 *
 *   Description:
 *     This file contains 16-bit timer code example which include timer 
 *     initialization, timer interrupt handler, and related APIs for 
 *     timer setup.
 *
 ****************************************************************************
 * Software that is described herein is for illustrative purposes only
 * which provides customers with programming information regarding the
 * products. This software is supplied "AS IS" without any warranties.
 * NXP Semiconductors assumes no responsibility or liability for the
 * use of the software, conveys no license or title under any patent,
 * copyright, or mask work right to the product. NXP Semiconductors
 * reserves the right to make changes in the software without
 * notification. NXP Semiconductors also make no representation or
 * warranty that such application will be suitable for the specified
 * use without further testing or modification.
****************************************************************************/
#include "LPC11xx.h"
#include "timer16.h"

volatile uint32_t timer16_0_counter = 0;
volatile uint32_t timer16_1_counter = 0;
volatile uint32_t timer16_0_capture = 0;
volatile uint32_t timer16_1_capture = 0;
volatile uint32_t timer16_0_period = 0;
volatile uint32_t timer16_1_period = 0;

/*****************************************************************************
** Function name:		delayMs
**
** Descriptions:		Start the timer delay in milo seconds
**						until elapsed
**
** parameters:			timer number, Delay value in milo second			 
** 						
** Returned value:		None
** 
*****************************************************************************/
void delayMs(uint8_t timer_num, uint32_t delayInMs)
{
  if (timer_num == 0)
  {
    /*
    * setup timer #0 for delay
    */
    LPC_TMR16B0->TCR = 0x02;		/* reset timer */
    LPC_TMR16B0->PR  = 0x00;		/* set prescaler to zero */
    LPC_TMR16B0->MR0 = delayInMs * (SystemAHBFrequency / 1000);
    LPC_TMR16B0->IR  = 0xff;		/* reset all interrrupts */
    LPC_TMR16B0->MCR = 0x04;		/* stop timer on match */
    LPC_TMR16B0->TCR = 0x01;		/* start timer */
    /* wait until delay time has elapsed */
    while (LPC_TMR16B0->TCR & 0x01);
  }
  else if (timer_num == 1)
  {
    /*
    * setup timer #1 for delay
    */
    LPC_TMR16B1->TCR = 0x02;		/* reset timer */
    LPC_TMR16B1->PR  = 0x00;		/* set prescaler to zero */
    LPC_TMR16B1->MR0 = delayInMs * (SystemAHBFrequency / 1000);
    LPC_TMR16B1->IR  = 0xff;		/* reset all interrrupts */
    LPC_TMR16B1->MCR = 0x04;		/* stop timer on match */
    LPC_TMR16B1->TCR = 0x01;		/* start timer */
    /* wait until delay time has elapsed */
    while (LPC_TMR16B1->TCR & 0x01);
  }
  return;
}

/******************************************************************************
** Function name:		TIMER_0_IRQHandler
**
** Descriptions:		Timer/Counter 0 interrupt handler
**						executes each 10ms @ 60 MHz CPU Clock
**
** parameters:			None
** Returned value:		None
** 
******************************************************************************/
void TIMER16_0_IRQHandler(void)
{  
  if ( LPC_TMR16B0->IR & 0x1 )
  {
	LPC_TMR16B0->IR = 1;			/* clear interrupt flag */
	timer16_0_counter++;
  }
  if ( LPC_TMR16B0->IR & (0x1<<4) )
  {
	LPC_TMR16B0->IR = 0x1<<4;		/* clear interrupt flag */
	timer16_0_capture++;
  }
  return;
}

/******************************************************************************
** Function name:		TIMER_1_IRQHandler
**
** Descriptions:		Timer/Counter 1 interrupt handler
**						executes each 10ms @ 60 MHz CPU Clock
**
** parameters:			None
** Returned value:		None
** 
******************************************************************************/
void TIMER16_1_IRQHandler(void)
{
  if ( LPC_TMR16B1->IR & 0x1 )
  {  
	LPC_TMR16B1->IR = 1;			/* clear interrupt flag */
	timer16_1_counter++;
  }
  if ( LPC_TMR16B1->IR & (0x1<<4) )
  {
	LPC_TMR16B1->IR = 0x1<<4;		/* clear interrupt flag */
	timer16_1_capture++;
  }
  return;
}

/******************************************************************************
** Function name:		enable_timer
**
** Descriptions:		Enable timer
**
** parameters:			timer number: 0 or 1
** Returned value:		None
** 
******************************************************************************/
void enable_timer16(uint8_t timer_num)
{
  if ( timer_num == 0 )
  {
    LPC_TMR16B0->TCR = 1;
  }
  else
  {
    LPC_TMR16B1->TCR = 1;
  }
  return;
}

/******************************************************************************
** Function name:		disable_timer
**
** Descriptions:		Disable timer
**
** parameters:			timer number: 0 or 1
** Returned value:		None
** 
******************************************************************************/
void disable_timer16(uint8_t timer_num)
{
  if ( timer_num == 0 )
  {
    LPC_TMR16B0->TCR = 0;
  }
  else
  {
    LPC_TMR16B1->TCR = 0;
  }
  return;
}

/******************************************************************************
** Function name:		reset_timer
**
** Descriptions:		Reset timer
**
** parameters:			timer number: 0 or 1
** Returned value:		None
** 
******************************************************************************/
void reset_timer16(uint8_t timer_num)
{
  uint32_t regVal;

  if ( timer_num == 0 )
  {
    regVal = LPC_TMR16B0->TCR;
    regVal |= 0x02;
    LPC_TMR16B0->TCR = regVal;
  }
  else
  {
    regVal = LPC_TMR16B1->TCR;
    regVal |= 0x02;
    LPC_TMR16B1->TCR = regVal;
  }
  return;
}

/******************************************************************************
** Function name:		init_timer
**
** Descriptions:		Initialize timer, set timer interval, reset timer,
**						install timer interrupt handler
**
** parameters:			timer number and timer interval
** Returned value:		None
** 
******************************************************************************/
void init_timer16(uint8_t timer_num, uint32_t TimerInterval) 
{
  if ( timer_num == 0 )
  {
    /* Some of the I/O pins need to be clearfully planned if
    you use below module because JTAG and TIMER CAP/MAT pins are muxed. */
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7);
    LPC_IOCON->PIO0_2           &= ~0x07;	/*  Timer0_16 I/O config */
    LPC_IOCON->PIO0_2           |= 0x02;		/* Timer0_16 CAP0 */
    LPC_IOCON->PIO0_8           &= ~0x07;	
    LPC_IOCON->PIO0_8           |= 0x02;		/* Timer0_16 MAT0 */
    LPC_IOCON->PIO0_9           &= ~0x07;
    LPC_IOCON->PIO0_9           |= 0x02;		/* Timer0_16 MAT1 */

#ifdef __JTAG_DISABLED
    LPC_IOCON->JTAG_TCK_PIO0_10 &= ~0x07;
    LPC_IOCON->JTAG_TCK_PIO0_10 |= 0x03;		/* Timer0_16 MAT2 */
#endif	
		
    timer16_0_counter = 0;
    timer16_0_capture = 0;
    LPC_TMR16B0->MR0 = TimerInterval;
#if TIMER_MATCH
    LPC_TMR16B0->EMR &= ~(0xFF<<4);
    LPC_TMR16B0->EMR |= ((0x3<<4)|(0x3<<6)|(0x3<<8));
#else
    /* Capture 0 on rising edge, interrupt enable. */
    LPC_TMR16B0->CCR = (0x1<<0)|(0x1<<2);
#endif
    LPC_TMR16B0->MCR = 3;				/* Interrupt and Reset on MR0 and MR1 */
		
    /* Enable the TIMER0 Interrupt */
    NVIC_EnableIRQ(TIMER_16_0_IRQn);
  }
  else if ( timer_num == 1 )
  {
    /* Some of the I/O pins need to be clearfully planned if
    you use below module because JTAG and TIMER CAP/MAT pins are muxed. */
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<8);
    LPC_IOCON->PIO1_8           &= ~0x07;	/*  Timer1_16 I/O config */
    LPC_IOCON->PIO1_8           |= 0x01;		/* Timer1_16 CAP0 */
    LPC_IOCON->PIO1_9           &= ~0x07;	
    LPC_IOCON->PIO1_9           |= 0x01;		/* Timer1_16 MAT0 */
    LPC_IOCON->PIO1_10          &= ~0x07;
    LPC_IOCON->PIO1_10          |= 0x02;		/* Timer1_16 MAT1 */	
		
    timer16_1_counter = 0;
    timer16_1_capture = 0;
    LPC_TMR16B1->MR0 = TimerInterval;
#if TIMER_MATCH
    LPC_TMR16B1->EMR &= ~(0xFF<<4);
    LPC_TMR16B1->EMR |= ((0x3<<4)|(0x3<<6)|(0x3<<8));
#else
    /* Capture 0 on rising edge, interrupt enable. */
    LPC_TMR16B1->CCR = (0x1<<0)|(0x1<<2);
#endif
    LPC_TMR16B1->MCR = 3;				/* Interrupt and Reset on MR0 and MR1 */
		
    /* Enable the TIMER1 Interrupt */
    NVIC_EnableIRQ(TIMER_16_1_IRQn);
  }
  return;
}

/******************************************************************************
** Function name:		init_timer16PWM
**
** Descriptions:		Initialize timer as PWM
**
** parameters:			timer number, period and match enable:
**						match_enable[0] = PWM for MAT0 
**						match_enable[1] = PWM for MAT1
**						match_enable[2] = PWM for MAT2
**			
** Returned value:	None
** 
******************************************************************************/
void init_timer16PWM(uint8_t timer_num, uint32_t period, uint8_t match_enable, uint8_t cap_enabled)
{	
  disable_timer16(timer_num);

  if (timer_num == 1)
  {
    /* Some of the I/O pins need to be clearfully planned if
    you use below module because JTAG and TIMER CAP/MAT pins are muxed. */
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<8);
		
    /* Setup the external match register */
    LPC_TMR16B1->EMR = (1<<EMC3)|(1<<EMC2)|(1<<EMC1)|(2<<EMC0)|(1<<3)|(match_enable);
		
    /* Setup the outputs */
    /* If match0 is enabled, set the output */
    if (match_enable & 0x01)
    {
      LPC_IOCON->PIO1_9           &= ~0x07;	
      LPC_IOCON->PIO1_9           |= 0x01;		/* Timer1_16 MAT0 */
    }
    /* If match1 is enabled, set the output */
    if (match_enable & 0x02)
    {
      LPC_IOCON->PIO1_10          &= ~0x07;
      LPC_IOCON->PIO1_10          |= 0x02;		/* Timer1_16 MAT1 */
    }
		
    /* Enable the selected PWMs and enable Match3 */
    LPC_TMR16B1->PWMC = (1<<3)|(match_enable);
		
    /* Setup the match registers */
    /* set the period value to a global variable */
    timer16_1_period 	= period;
    LPC_TMR16B1->MR3 	= timer16_1_period;
    LPC_TMR16B1->MR0	= timer16_1_period/2;
    LPC_TMR16B1->MR1	= timer16_1_period/2;
    LPC_TMR16B1->MR2	= timer16_1_period/2;
		
    /* Set match control register */
    LPC_TMR16B1->MCR = 1<<10;// | 1<<9;				/* Reset on MR3 */
		
    if (cap_enabled)
    {
      LPC_IOCON->PIO1_8 &= ~0x07;						/*  Timer1_16 I/O config */
      LPC_IOCON->PIO1_8 |= 0x01 | (2<<3);				/* Timer1_16 CAP0 */
      LPC_GPIO1->DIR &= ~(1<<8); 
      LPC_TMR16B1->IR = 0xF;							/* clear interrupt flag */
			
      /* Set the capture control register */
      LPC_TMR16B1->CCR = 7;
			
    }
    /* Enable the TIMER1 Interrupt */
    NVIC_EnableIRQ(TIMER_16_1_IRQn);
  }
  else
  {
    /* Some of the I/O pins need to be clearfully planned if
    you use below module because JTAG and TIMER CAP/MAT pins are muxed. */
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7);
		
    /* Setup the external match register */
    LPC_TMR16B0->EMR = (1<<EMC3)|(1<<EMC2)|(1<<EMC1)|(1<<EMC0)|(1<<3)|(match_enable);
		
    /* Setup the outputs */
    /* If match0 is enabled, set the output */
    if (match_enable & 0x01)
    {
      LPC_IOCON->PIO0_8           &= ~0x07;	
      LPC_IOCON->PIO0_8           |= 0x02;		/* Timer0_16 MAT0 			*/
    }
    /* If match1 is enabled, set the output */
    if (match_enable & 0x02)
    {
      LPC_IOCON->PIO0_9           &= ~0x07;
      LPC_IOCON->PIO0_9           |= 0x02;		/* Timer0_16 MAT1 			*/
    }
    /* If match2 is enabled, set the output */
    if (match_enable & 0x04)
    {
      LPC_IOCON->SWCLK_PIO0_10 &= ~0x07;
      LPC_IOCON->SWCLK_PIO0_10 |= 0x03;		/* Timer0_16 MAT2 */
    }
		
    //	  PIO0_2           &= ~0x07;	/* Timer0_16 I/O config */
    //	  PIO0_2           |= 0x02;		/* Timer0_16 CAP0 			*/
    /* Enable the selected PWMs and enable Match3 */
    LPC_TMR16B0->PWMC = (1<<3)|(match_enable);
		
    /* Setup the match registers */
    /* set the period value to a global variable */
    timer16_0_period = period;
    LPC_TMR16B0->MR3 = timer16_0_period;
    LPC_TMR16B0->MR0	= timer16_0_period/2;
    LPC_TMR16B0->MR1	= timer16_0_period/2;
    LPC_TMR16B0->MR2	= timer16_0_period/2;
		
    /* Set the match control register */
    LPC_TMR16B0->MCR = 1<<10;				/* Reset on MR3 */
		
    /* Enable the TIMER1 Interrupt */
    NVIC_EnableIRQ(TIMER_16_0_IRQn);
  }
}

/******************************************************************************
** Function name:		pwm16_setMatch
**
** Descriptions:		Set the pwm16 match values
**
** parameters:			timer number, match numner and the value
**
** Returned value:		None
** 
******************************************************************************/
void setMatch_timer16PWM (uint8_t timer_num, uint8_t match_nr, uint32_t value)
{
  if (timer_num)
  {
    switch (match_nr)
    {
      case 0:
        LPC_TMR16B1->MR0 = value;
      break;
      case 1: 
        LPC_TMR16B1->MR1 = value;
      break;
      case 2:
        LPC_TMR16B1->MR2 = value;
      break;
      case 3: 
        LPC_TMR16B1->MR3 = value;
      break;
      default:
        break;
    }	
  }
  else 
  {
    switch (match_nr)
    {
      case 0:
        LPC_TMR16B0->MR0 = value;
      break;
      case 1: 
        LPC_TMR16B0->MR1 = value;
      break;
      case 2:
        LPC_TMR16B0->MR2 = value;
      break;
      case 3: 
        LPC_TMR16B0->MR3 = value;
      break;
      default:
      break;
    }	
  }
}

/******************************************************************************
**                            End Of File
******************************************************************************/

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲人成亚洲人成在线观看图片 | 国产亚洲女人久久久久毛片| 日韩激情中文字幕| 欧美精三区欧美精三区| 日韩国产在线观看| 精品成人a区在线观看| 国产乱子轮精品视频| 久久久.com| 色偷偷久久一区二区三区| 午夜影视日本亚洲欧洲精品| 91精品久久久久久蜜臀| 国产精品正在播放| 1024国产精品| 欧美一区三区二区| 大尺度一区二区| 亚洲与欧洲av电影| 日韩免费高清av| 国产成人欧美日韩在线电影| 中文字幕欧美一| 777久久久精品| 国产精品888| 亚洲在线中文字幕| 欧美成人三级在线| 成人黄色在线看| 午夜久久久久久久久久一区二区| 午夜视频一区二区三区| 欧美一区二区三区在线视频| 成人精品一区二区三区中文字幕| 亚洲一区自拍偷拍| 久久精品男人天堂av| 欧美日韩午夜影院| 国产成a人无v码亚洲福利| 一区二区三区视频在线观看| 精品欧美一区二区在线观看| 波波电影院一区二区三区| 日日欢夜夜爽一区| 亚洲人成精品久久久久久 | 日韩一区二区三区电影 | 亚洲午夜精品17c| 国产亚洲女人久久久久毛片| 欧美日韩成人在线一区| 成人a级免费电影| 蜜桃久久久久久久| 亚洲精品大片www| 国产欧美一区二区在线| 欧美丰满嫩嫩电影| 91在线高清观看| 国产精品一区在线| 日韩高清一区在线| 一区二区三区四区中文字幕| 久久精品一二三| 欧美变态tickle挠乳网站| 欧美亚洲一区三区| 99久久精品国产毛片| 国内精品伊人久久久久影院对白| 午夜精品视频一区| 亚洲精品va在线观看| 中文字幕一区二区在线观看| 精品日韩一区二区| 日韩天堂在线观看| 69p69国产精品| 欧美网站大全在线观看| 欧美在线综合视频| 91免费看视频| 99re热这里只有精品视频| 国产乱码精品1区2区3区| 久久国产免费看| 蜜臀va亚洲va欧美va天堂 | 26uuuu精品一区二区| 欧美一二三四在线| 日韩一区二区三区四区五区六区| 欧美午夜理伦三级在线观看| 色噜噜狠狠成人网p站| 一本久久a久久免费精品不卡| 成人a级免费电影| 成人av网站免费观看| av不卡免费电影| 97aⅴ精品视频一二三区| 91女厕偷拍女厕偷拍高清| 91啪九色porn原创视频在线观看| 91小视频在线观看| 色婷婷久久久久swag精品| 一本大道久久a久久精二百| 色综合网站在线| 欧美午夜不卡视频| 欧美一二三区在线观看| 久久先锋资源网| 国产精品久久久久9999吃药| 亚洲欧洲日韩女同| 亚洲国产一区二区三区| 日韩中文字幕1| 精品一区精品二区高清| 国产美女主播视频一区| 成人性生交大合| 一本色道久久综合亚洲91| 欧美日韩另类国产亚洲欧美一级| 欧美精品18+| 久久夜色精品国产噜噜av | 91福利视频网站| 91精品国产综合久久国产大片| 欧美xxxxxxxxx| 欧美国产一区在线| 一区二区三区色| 久久成人免费电影| 成人97人人超碰人人99| 欧美日韩你懂得| 欧美精品一区二区三区蜜桃视频| 国产清纯在线一区二区www| 一区二区三区在线播放| 日本美女一区二区| 成人网在线播放| 欧美日韩色一区| 欧美国产日韩a欧美在线观看 | 日本一区二区成人| 亚洲综合一区二区三区| 日本成人中文字幕| 高清国产一区二区| 91美女片黄在线观看| 精品久久久久香蕉网| 一区二区三区在线视频观看 | 国产成人精品1024| 欧美日韩一本到| 国产色91在线| 日韩激情在线观看| 成人av电影免费观看| 欧美精品一二三| 精品久久国产字幕高潮| 亚洲在线视频网站| 国产精品88av| 日韩视频免费观看高清完整版 | 亚洲自拍偷拍av| 成人性生交大合| 日韩精品最新网址| 亚洲综合图片区| 成人国产一区二区三区精品| 欧美一区二区三区免费| 亚洲精品免费在线观看| 国产传媒日韩欧美成人| 在线成人午夜影院| 亚洲欧洲精品一区二区三区| 国产主播一区二区| 91精品婷婷国产综合久久性色| 亚洲色图第一区| 国产jizzjizz一区二区| 日韩色在线观看| 视频一区二区三区中文字幕| 91日韩一区二区三区| 国产精品久久久久久久蜜臀 | 中文字幕精品一区二区精品绿巨人| 日韩精品一区第一页| 色婷婷香蕉在线一区二区| 亚洲欧洲精品天堂一级| 国产成人小视频| 久久久久久久久久久久久女国产乱| 日本sm残虐另类| 678五月天丁香亚洲综合网| 亚洲国产精品久久久久秋霞影院| 色综合天天综合网国产成人综合天| 久久免费视频一区| 国产老肥熟一区二区三区| 日韩免费观看2025年上映的电影 | 国产一区欧美一区| 欧美va在线播放| 日韩av二区在线播放| 欧美顶级少妇做爰| 亚洲高清在线精品| 欧美日韩国产电影| 亚洲sss视频在线视频| 欧美探花视频资源| 婷婷丁香久久五月婷婷| 欧美二区三区91| 蜜桃久久久久久| 日韩欧美国产午夜精品| 久久91精品久久久久久秒播| 欧美tickling网站挠脚心| 久久精品国产在热久久| 欧美精品一区二区精品网| 国产在线国偷精品免费看| 2023国产一二三区日本精品2022| 狠狠色狠狠色综合系列| 国产片一区二区| 94-欧美-setu| 视频一区免费在线观看| 精品国产污网站| 成人综合在线观看| 亚洲激情一二三区| 日韩一区二区三区免费看 | 日韩av在线发布| 欧美tickling网站挠脚心| 国产盗摄一区二区三区| 自拍偷自拍亚洲精品播放| 欧美性生交片4| 麻豆中文一区二区| 国产欧美日韩三级| 欧美在线观看一二区| 毛片基地黄久久久久久天堂| 国产精品不卡视频| 欧美日韩电影在线播放| 国模套图日韩精品一区二区| 亚洲色欲色欲www在线观看|