用PWM功能产生38kHz比使用T2更实用.
例子是使用SH88F2051或SH88F54MCU.
#define FOSC 16.6//11.0592 //
#define MACHINE_NUM 1 //定时器
#define M_NUM 1 //程序 SH88F2051 程序是1T,定时器1T/12T可选
#define GET_PWMP(F) MIN(MAX((FOSC*250/M_NUM/(F)),4),255)
#define PWM0_SET(d,p) do{PWM0D=(d);PWM0P=(p);PWM0CON=0x91;}while(0)
#define PWM0_ON() do{PWM0CON |= 0x80;}while(0)
#define PWM0_OFF() do{PWM0CON &= 0x7f;}while(0)
#define PWM1_SET(d,p) do{PWM1D=(d);PWM1P=(p);PWM1CON=0x91;}while(0)
#define PWM1_ON() do{PWM1CON |= 0x80;}while(0)
#define PWM1_OFF() do{PWM1CON &= 0x7f;}while(0)
#define PWM2_SET(d,p) do{PWM2D=(d);PWM2P=(p);PWM2CON=0x91;}while(0)
#define PWM2_ON() do{PWM2CON |= 0x80;}while(0)
#define PWM2_OFF() do{PWM2CON &= 0x7f;}while(0)
//PWM0_SET(GET_PWMP(38)/3,GET_PWMP(38));//pwm输出38kHz
#define GET_PWMP(F) MIN(MAX((FOSC*250/M_NUM/(F)),4),255)
#define PWM_SET(d,p) do{PWMD=(d);PWMP=(p);PWMCON=0x91;}while(0)
#define PWM_ON() do{PWMCON |= 0x80;}while(0)
#define PWM_OFF() do{PWMCON &= 0x7f;}while(0)
//PWM_SET(GET_PWMP(38)/3,GET_PWMP(38));//pwm输出38kHz
|