标签:中颖sh79f1616
//========pwm.h============================================= #ifndef _PWM_H_ #define _PWM_H_ #define EPWM0 (1<<0) //PWM0 输出允许 #define EPWM01 (1<<3) //PWM01 输出允许 //-----pwm 时钟分频---------- #define PWM_DIV PWM_DIV8 #define PWM_DIV2 0 #define PWM_DIV4 1 #define PWM_DIV8 2 #define PWM_DIV16 3 #define PwmOut_Enb PWMEN1 &= ~0X01 //PWM输出使能 #define PwmOut_Dis PWMEN1 |= 0X01 //PWM输出禁止 //======================================================= extern void Init_Pwm(uint16 Tcyc) ; extern void ToPwmValue(uint16 Invalue) ; #endif //========pwm.c============================================== #include "global.h" #include "pwm.h" //#define Init_Pwm_CALL //#define ToPwmValue_CALL //************************************* // 函数名称:Init_Pwm // 函数功能:PWM初始化 // 入口参数:无 // 出口参数:无 //*************************************** #ifdef Init_Pwm_CALL void Init_Pwm(uint16 Tcyc) { PWMLO = 0X55 ; _nop_();_nop_();_nop_();_nop_();_nop_(); PWM0C = PWM_DIV ; //PWM高电平有效 无中断 设置PWM时钟分频 PWM0PL = Tcyc & 0xff ; //周期值 PWM0PH = (Tcyc>>8) ; PWM0DL = 0x00 ; //占空比值 PWM0DH = 0x00 ; PWMEN1 |= 0X01 ; //PWM输出禁止 PWMEN = EPWM0 ; //pwm0 模块允许 PWMLO = 0XAA ; } #endif //Init_Pwm_CALL //************************************* // 函数名称:ToPwmValue // 函数功能:设置PWM占空比值 // 入口参数:占空比值 // 出口参数:无 //*************************************** #ifdef ToPwmValue_CALL void ToPwmValue(uint16 Invalue) { PWMLO = 0X55 ; PWM0DL = Invalue & 0xff ; PWM0DH = (Invalue>>8) ; PWMLO = 0XAA ; } #endif //ToPwmValue_CALL
中颖SH79F1616 PWM初始化程序,布布扣,bubuko.com
标签:中颖sh79f1616
原文地址:http://blog.csdn.net/libiaojs/article/details/29410885