keil_examples/PWM/pwm.c
/******************************************************************************
** Function name:		PWM_Init
**
** Descriptions:		PWM initialization, setup all GPIOs to PWM0~6,
**						reset counter, all latches are enabled, interrupt
**						on PWMMR0, install PWM interrupt to the VIC table.
**
** parameters:			ChannelNum, Duty cycle
** Returned value:		true or fase, if VIC table is full, return false
** 
******************************************************************************/
Function name:         PWM_Init
Descriptions:          PWM initialization, setup all GPIOs to PWM0~6,
reset counter, all latches are enabled, interrupt
on PWMMR0, install PWM interrupt to the VIC table.

ChannelNum, Duty cycle
Returned value:                true or fase, if VIC table is full, return false
Function name : PWM_Init Descriptions : PWM initialization setup all GPIOs to PWM0~6 reset counter all latches are enabled interrupt on PWMMR0 install PWM interrupt to the VIC table . ChannelNum Duty cycle Returned value : true or fase if VIC table is full return false
uint32_t PWM_Init( uint32_t ChannelNum, uint32_t cycle )
{
  if ( ChannelNum == 1 )
  {
	match_counter1 = 0;
	LPC_PINCON->PINSEL4 = 0x00001555;	
	LPC_PWM1->TCR = TCR_RESET;	 
	LPC_PWM1->PR = 0x00;		
	LPC_PWM1->MCR = PWMMR0I;					
	LPC_PWM1->MR0 = cycle;		
	LPC_PWM1->MR1 = cycle * 5/6;
	LPC_PWM1->MR2 = cycle * 2/3;
	LPC_PWM1->MR3 = cycle * 1/2;
	LPC_PWM1->MR4 = cycle * 1/3;
	LPC_PWM1->MR5 = cycle * 1/6;
	LPC_PWM1->MR6 = 0;	
	LPC_PWM1->LER = LER0_EN | LER1_EN | LER2_EN | LER3_EN | LER4_EN | LER5_EN | LER6_EN;
  }
  else
  {
	return ( FALSE );		
  }
  NVIC_EnableIRQ(PWM1_IRQn);
  return (TRUE);
}
uint32_t PWM_Init ( uint32_t ChannelNum , uint32_t cycle ) { if ( ChannelNum == 1 ) { match_counter1 = 0 ; LPC_PINCON -> PINSEL4 = 0x00001555 ; LPC_PWM1 -> TCR = TCR_RESET ; LPC_PWM1 -> PR = 0x00 ; LPC_PWM1 -> MCR = PWMMR0I ; LPC_PWM1 -> MR0 = cycle ; LPC_PWM1 -> MR1 = cycle * 5 / 6 ; LPC_PWM1 -> MR2 = cycle * 2 / 3 ; LPC_PWM1 -> MR3 = cycle * 1 / 2 ; LPC_PWM1 -> MR4 = cycle * 1 / 3 ; LPC_PWM1 -> MR5 = cycle * 1 / 6 ; LPC_PWM1 -> MR6 = 0 ; LPC_PWM1 -> LER = LER0_EN | LER1_EN | LER2_EN | LER3_EN | LER4_EN | LER5_EN | LER6_EN ; } else { return ( FALSE ) ; } NVIC_EnableIRQ ( PWM1_IRQn ) ; return ( TRUE ) ; }
Function name:         PWM_Init
Descriptions:          PWM initialization, setup all GPIOs to PWM0~6,
reset counter, all latches are enabled, interrupt
on PWMMR0, install PWM interrupt to the VIC table.
Function name : PWM_Init Descriptions : PWM initialization setup all GPIOs to PWM0~6 reset counter all latches are enabled interrupt on PWMMR0 install PWM interrupt to the VIC table .
/* set GPIOs for all PWM pins on PWM */ /* Counter Reset */ /* count frequency:Fpclk */ /* interrupt on PWMMR0, reset on PWMMR0, reset 
								TC if PWM matches */ /* set PWM cycle */ /* all PWM latch enabled */ /* Unknown channel number */