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

📄 pwmmain.c

📁 这里是LPC系统的PWM发生程序
💻 C
字号:
/*------------------------------------------------------------------------------
pwmMain.c : Sample Program that demonstrates the pulse width modulator for the
following microcontrollers

Philips 87LPC768

Copyright (c) 1988-2001 Keil Elektronik GmbH and Keil Software, Inc.
All rights reserved.
--------------------------------------------------------------------------*/

sfr P0    = 0x80;
sfr P1    = 0x90;
sfr P0M1    = 0x84;
sfr P0M2    = 0x85;
sfr P1M1    = 0x91;
sfr P1M2    = 0x92;

sfr CNSW0   = 0xD1;
sfr CNSW1   = 0xD2;
sfr CPSW0   = 0xD3;
sfr CPSW1   = 0xD4;
sfr CPSW2   = 0xD5;
sfr CPSW3   = 0xD6;
sfr CPSW4   = 0xD7;
sfr PWMCON0 = 0xDA;
sfr PWMCON1 = 0xDB;



/*------------------------------------------------------------------------------
main() : Runs a while loop as the PWM automatically loops 
------------------------------------------------------------------------------*/
void main( void )
{
	CNSW0 = 0xFF;					//PWM Clock Count set to Maximum. 
	CNSW1 = 0X03;

	CPSW0 = 0xCC;					//Setting duty cycle of channel 0 to 80%
	CPSW1 = 0x98;					//Setting duty cycle of channel 1 to 60%
	CPSW2 = 0x64;					//Setting duty cycle of channel 2 to 40%	
	CPSW3 = 0x30;					//Setting duty cycle of channel 3 to 20%
	
	CPSW4 = 0xE4;					//Setting 8-9 bits of output registers
	
	PWMCON0 |= 0x40;				//Setting all channels to non-iverted.
	
	PWMCON1 &= 0x00;				//Braking disabled  Shadow Memory transfered.

	PWMCON0 |= 0x80;				//RUN PWM.

	while(1);						

}

⌨️ 快捷键说明

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