pwm_test.c

来自「IARSOURCECODE是基于LPC2478嵌入式软件IAR EWARM V4」· C语言 代码 · 共 56 行

C
56
字号
/*****************************************************************************
 *   pwmtest.c:  main C entry file for NXP LPC23xx/24xx Family Microprocessors
 *
 *   Copyright(C) 2006, NXP Semiconductor
 *   All rights reserved.
 *
 *   History
 *   2006.07.20  ver 1.00    Prelimnary version, first Release
 *
******************************************************************************/
#include "LPC2468.h"                        /* LPC23xx/24xx definitions */
#include "type.h"
#include "irq.h"
#include "pwm.h"

extern volatile DWORD pwm0_match_counter,pwm1_match_counter;

/******************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void)
{	
  DWORD cycle = PWM_CYCLE, offset = 0;

  /* The test is done on the Keil MCB2300 board, that all the PWM1 pins are
  laid out to the connector for probing. PWM0 is not not tested. */
  if ( PWM_Init( 1, 0 ) != TRUE )
  {
	while( 1 );			/* fatal error */
  }

  PWM_Set( 1, cycle, offset );          // PWM计数值初值和波形偏移设置
  PWM_Start( 1 );                       // 启动

  while ( 1 )
  {
	if ( pwm1_match_counter != 0 )
	{
	  pwm1_match_counter = 0;
	  if( offset <= PWM_CYCLE )
		offset += PWM_OFFSET;
	  else
		offset = 0;
	  PWM_Set( 1, cycle, offset );
	}
  }

  PWM_Stop( 1 );

  return 0;
}

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

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?