PWM方波產(chǎn)生51程序
PWMDATA31H;PWM周期
COUNTERDATA32H
pwmhminDATA33H
ORG0000H
AJMPMAIN
;ORG 0003H
;AJMP INT_X0
;ORG 0013H
;AJMP INT_X1
ORG000BH
AJMPINT_T0
ORG0100H
MAIN:
MOVSP,#60H;給堆棧指針賦初值
mov ie,#87h
MOVPWMH,#02H;
MOVCOUNTER,#01H
MOVPWM,#14H
MOVTMOD,#02H;定時器0在模式2下工作
MOVTL0,#38H;定時器每200us產(chǎn)生一次溢出
MOVTH0,#38H;自動重裝的值
SETBET0;使能定時器0中斷
SETBEA;使能總中斷
SETBTR0
SETB IT0
SETB IT1
sjmp $
INT_X0:
MOV A,PWMH
CJNE A,PWM,INC1
SJMP EXIT1
INC1:
clr TR0
MOV A,PWMH
INC A
MOV PWMH,A
EXIT1:
setb TR0
RETI
INT_X1:
MOV A,PWMH
CJNE A,#01h,DEC1
SJMP EXIT2
DEC1:
clr TR0
MOV A,PWMH
DEC A
MOV PWMH,A
EXIT2:
setb TR0
RETI
INT_T0:
INCCOUNTER;計(jì)數(shù)值加1
MOVA,COUNTER
CJNEA,PWMH,INTT01;如果等于高電平脈沖數(shù)
CLRP1.0;P1.0變?yōu)榈碗娖?br />INTT01:CJNEA,PWM,INTT02;如果等于周期數(shù)
MOVCOUNTER,#01H;計(jì)數(shù)器復(fù)位
SETBP1.0;P1.0為高電平
INTT02:
RETI
END
評論