还有没有办法更快一些?
高速模拟PWM程序(C51),可达1.114KHz,8bit分辨率@24MHz标准8051
#include <reg52.h>
sbit PWM = P3^7;
unsigned char pwm_count,pwm_value;
void main(void)
{
pwm_value=80;
while(1)
{
pwm_count++;
if(pwm_count==pwm_value)
{
PWM=0;
}
if(pwm_count==0)
{
PWM=1;
}
}
}
仅6行,编译后只有10字节的软件模拟PWM程序(ASM),42级5位半分辨率,[email=7.8125KHz@24MHz8051]7.8125KHz@24MHz8051[/email]
ORG 0000H
INIT: SETB TR0
MAIN: MOV A,#80 ;PWM值,0-255
SUBB A,TL0
MOV P3.7,C
SJMP MAIN
END
高速模拟PWM程序(ASM),可达1.558KHz,[email=8bit@24MHz]8bit@24MHz[/email]标准8051
ORG 0000H
MAIN: INC A
CJNE A,#10,BDY
SETB P3.7
SJMP MAIN
BDY: JNZ MAIN
CLR P3.7
SJMP MAIN
END |