www.pudn.com > RS485_USART-ok.rar > drv_pau.c, change:2007-09-29,size:2656b


//*---------------------------------------------------------------------------- 
//*      Shenzhen ANCHE Tech CO.,LTD 
//*---------------------------------------------------------------------------- 
//*---------------------------------------------------------------------------- 
//* File Name           : pwm.c 
//* Object              : pwm Library. 
//* Designer            : Tianlong Jing, at 2006 
//* 
//* 
//* Description : the system have 4ch PWM,there are PMM0-3 which attach with the PIN PB19-22 
//*                     
//*---------------------------------------------------------------------------- 
 
#include    "drv_pau.h" 
 
// PWM Init 
void PAU_Open(void) 
{ 
	// 设置PWM0-3功能 
	AT91F_PIO_CfgPeriph( AT91C_BASE_PIOB,  // PIO 控制器基地址 
#include <AT91SAM7X256.H> 
		         AT91C_PB19_PWM0 |  
		         AT91C_PB20_PWM1 | 
		         AT91C_PB21_PWM2 | 
		         AT91C_PB22_PWM3,	 //外设 A 
		         0);					// 外设B 
		          
    //2)为PWM0-3配置总时钟 
     AT91F_PWMC_CfgPMC (); 
 
     //3) 停止PWM0-3 
     AT91F_PWMC_StopChannel(AT91C_BASE_PWMC,0x0f<<0); 
 
    //4)PWMC 模式寄存器 
     AT91C_BASE_PWMC->PWMC_MR=0x0; 
 
    //5)设置PWM0通道 
     AT91F_PWMC_CfgChannel( AT91C_BASE_PWMC, // PWM基地址 
                            0,   // PWM通道ID 
                            AT91C_PWMC_CPRE_MCK,		// PWM0通道模式-- CLKA=MCK!! 
//                            AT91C_PWMC_CPOL,             	// The output waveform starts at a high level 
                            PWM_PAU_PERIOD,  			// PWM0周期---- 2000Hz, 	 
                                                                        	// 得到的结果相当于14位DA精度 
                            0   							// PWM0通道占空比--0                              
                           ); 
     AT91F_PWMC_CfgChannel( AT91C_BASE_PWMC, // PWM基地址 
                            1,   // PWM通道ID 
                            AT91C_PWMC_CPRE_MCK,   	// PWM0通道模式-- CLKA=MCK!! 
//                            AT91C_PWMC_CPOL,             // The output waveform starts at a high level 
                            PWM_PAU_PERIOD*2,  		  // PWM0周期---- 1000Hz, 	 
                                                                        // 得到的结果相当于14位DA精度 
                            0   // PWM0通道占空比--0                              
                           ); 
 
 
     //6)禁止PWM中断 
     AT91F_PWMC_InterruptDisable(AT91C_BASE_PWMC,0xFF); 
 
     //7)开启PWM0-3 
     AT91F_PWMC_StartChannel(AT91C_BASE_PWMC,0x0f<<0); 
	 
} 
 
void PAU_Write(INT8U ch, INT32U duty) 
{ 
	if (ch < 4) 
		AT91F_PWMC_UpdateChannel(AT91C_BASE_PWMC, ch, duty); 
}