合泰單片機(jī)PWM輸出程序
;完整源碼下載:http://www.51hei.com/f/htpwm.rar
#INCLUDEHT66F50.INC
ORG00H
MOVA,08H
MOVCP0C,A;設(shè)置管腳不為比較器腳
MOVCP1C,A;設(shè)置管腳不為比較器腳
CLRACERL;設(shè)置管家部位AD腳
MOVA,00010000B
MOVTMPC0,A;T1BCP1置1使能TP1B_0
CLRTM1C0;fINT=fSYS/4
MOVA,10101001B;設(shè)置為PWM模式PWM輸出高有效同相T1CCLR=1
MOVTM1C1,A;CCRA控制TP1B PWM 周期,CCRB 控制TP1B PWM 占空比
MOVA,10101000B;置為PWM模式PWM輸出高有效同相邊沿對(duì)齊
MOVTM1C2,A;
MOVA,LOW 1024-1
MOVTM1AL,A;設(shè)置TP1B PWM 周期 CCRA=1024uS
MOVA,HIGH 1024-1
MOVTM1AH,A;設(shè)置PC.0為輸出
CLRPCC.0
CLRPC.0;pc.0輸出低電平
MOVA,5
SETT1ON;PWM開始工作
MOVA,0FFH;設(shè)置占空比初始值
MOV[80H],A
MOVA,3;
MOV[81H],A
a2:
CALLM001;延時(shí)
SZ[80H];判斷占空比低位是否為0
JMP$+2
JMPA3
DEC[80H];否低位減1
JMPA5
A3:
SZ[81H];是則判斷高位是否為0
JMPA4
MOVA,0FFH;是低位存0FFH
MOV[80H],A;
MOVA,3;高位存3
MOV[81H],A;不能大于周期
JMPA2
A4:
DEC[81H];否則高位減1
MOVA,0FFH;
MOV[80H],A;低位存0FFH
A5:
mova,[80H];將占空比的數(shù)存到CCRB中
movTM1BL,A;
MOVA,[81H];
MOVTM1BH,A;
jmpA2
M001:MOVA,2
MOV[85H],A
M002:MOVA,20
MOV[86H],A
M003:MOVA,250
MOV[87H],A
M004:SDZ[87H]
JMPM004
SDZ[86H]
JMPM003
SDZ[85H]
JMPM002
RET
end
評(píng)論