本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
PULSE_WIDTH_MAX EQU 0F0H
PULSE_WIDTH_MIN EQU 10H
STEP EQU 38H
PULSE_WIDTH EQU 30H
ORG 0000H
AJMP MAIN
ORG 0050H
MAIN: MOV SP,#0E0H
ACALL PCA_INIT
MAIN_LOOP: ACALL PWM
SJMP MAIN_LOOP
PCA_INIT: MOV CMOD,#80H
MOV CCON,#00H
MOV CL,#00H
MOV CH,#00H
MOV CCAPM0,#42H
MOV PCA_PWM0,#00H
MOV PCA_PWM0,#03H
MOV CCAPM1,#42H
MOV PCA_PWM1,#00H
MOV PCA_PWM1,#03H
SETB EPCA_LVD
SETB EA
SETB CR
RET
PWM: MOV A,#PULSE_WIDTH_MIN
MOV PULSE_WIDTH,A
PWM_LOOP1: MOV A,PULSE_WIDTH
CLR C
SUBB A,#PULSE_WIDTH_MAX
JNC PWM_A
MOV A,PULSE_WIDTH
MOV CCAP0,A
MOV CCAP1,A
CPL A
MOV P1,A
MOV A,PULSE_WIDTH
ADD A,#STEP
MOV PULSE_WIDTH,A
ACALL DELAY
SJMP PWM_LOOP1
PWM_A: MOV A,#PULSE_WIDTH_MAX
MOV PULSE_WIDTH,A
PWM_LOOP2: MOV A,PULSE_WIDTH
CLR C
SUBB A,#PULSE_WIDTH_MIN
JC PWM_B
JZ PWM_B
MOV A,PULSE_WIDTH
MOV CCAP0,A
MOV CCAP1,A
CPL A
MOV P1,A
MOV A,PULSE_WIDTH
CLR C
SUBB A,#STEP
MOV PULSE_WIDTH,A
CALL DELAY
SJMP PWM_LOOP2
PWM_B: RET
DELAY: CLR A
MOV R1,A
MOV R2,A
MOV R3,#80H
DELAY_LOOP: NOP
NOP
NOP
DJNZ R1,DELAY_LOOP
DJNZ R2,DELAY_LOOP
DJNZ R3,DELAY-LOOP
RET
END
|