首页 > 代码库 > 中颖SH79F1616 PWM初始化程序
中颖SH79F1616 PWM初始化程序
//========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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。