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

📄 main.c

📁 掏美元培训得来的某外国公司推广keil ARM 和LPC2100的源码。
💻 C
字号:
/************************************************************/
/* PROJECT NAME: PWM	                                    */
/* Project:      LPC2100 Training course                    */
/* Engineer:     T Martin                                   */
/* Filename:     main.c                                     */
/* Language:     C                      	                */
/* Compiler:     Keil Carm 2.00b		                    */
/* Assembler:    					                        */
/*                                                          */
/************************************************************/
/* Modification History:                                    */
/*                                                          */
/************************************************************/
/* Function:                                                */
/*                                                          */
/* Example PWM module program for LPC2100         			*/
/*															*/
/* Demonstrates dual edge PWM generation					*/
/*															*/	
/* Oscillator frequency 12.000 Mhz							*/
/* Target board Keil MCB2100								*/
/************************************************************/

#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

ADCR   = 0x00250601;    // Setup A/D: 10-bit AIN0 @ 3MHz 
ADCR  |= 0x01000000;    // Start A/D Conversion 

while(1)				// main loop
{
for (delay=0;delay < 0x100;delay++)
{
;
}
do
{
    val = ADDR;                   		// Read A/D Data Register 
}        
while ((val & 0x80000000) == 0);  		//Wait for the conversion to complete
val = ((val >> 8) & 0x00FF);  			//Extract the A/D result 

PWMMR1 = 0x00000000+val;				 //Modulate PWM
PWMMR2 = 0x000000FF-val;
PWMLER = 0x00000006;					 //set latch to update PWM registers next cycle
}


}



⌨️ 快捷键说明

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