⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pwm.c

📁 lpc2138 using a pwm coding
💻 C
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -