pwm.c

来自「lpc2138 using a pwm coding」· C语言 代码 · 共 37 行

C
37
字号
#include <LPC21XX.H>
int main(void)
{
unsigned int val,delay;

PINSEL0 |= 0x00028000;	//Enable pin 0.7   as PWM2 
PWMPR 	 = 0x00000001;	//Load prescaler

PWMPCR = 0x0000404;		//PWM channel 2 double edge control, output enabled
PWMMCR = 0x00000003;	//On match with timer reset the counter
PWMMR0 = 0x000000ff;	//set cycle rate to sixteen ticks
PWMMR1 = 0x00000080;	//set rising edge of PWM2 to 2 ticks
PWMMR2 = 0x00000080;	//set falling edge of PWM2 to 8 ticks
PWMLER = 0x00000007;	//enable shadow latch for match 0 - 2 
//PWMEMR = 0x00000280;	//Match 1 and Match 2 outputs set high
PWMTCR = 0x00000002;	//Reset counter and prescaler 
PWMTCR = 0x00000009;	//enable counter and PWM, release counter from reset



while(1)				
{
for (delay=0;delay<0x100;delay++)
{
;
}
       

PWMMR1 = 10;				 //Modulate PWM
PWMMR2 = 150;
PWMLER = 0x00000006;					 //set latch to update PWM registers next cycle
}
}



⌨️ 快捷键说明

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