;learning to do pwm with tmro 12f675
list P=12f675
#include <p12f675.inc>
__config _INTRC_OSC_NOCLKOUT & _BODEN_OFF & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CPD_OFF & _CP_OFF
ERRORLEVEL -302
cblock 20h
pwmcounter, channel1, channel2, period
endc
ORG 0000h
goto setup
ORG 0004h
call pwm
BCF INTCON,2
RETFIE ;reset interrupt
setup
bsf STATUS,RP0 ;bank 1
movlw 0x3c
movwf ANSEL
movlw 0x3c
movwf TRISIO ;set I/O
movlw 0xd8
movwf OPTION_REG ;set tmr0
bcf STATUS,RP0
movlw 0x07 ;turn off comparitors
movwf CMCON
movlw 0xa0
movwf INTCON ;set interrupt
start
movlw 0x09
movwf ADCON0
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
bsf ADCON0,1
btfsc ADCON0,1
goto $-1
movf ADRESH,0
movwf channel1
movlw 0x0d
movwf ADCON0
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
bsf ADCON0,1
btfsc ADCON0,1
goto $-1
movf ADRESH,0
movwf channel2
goto start
pwm
incf period,1
btfss STATUS,Z
goto $+2
clrf period
movf channel1,0
addwf period,0
btfss STATUS,C
goto $+3
bsf GPIO,0
goto $+2
bcf GPIO,0
movf channel2,0
addwf period,0
btfss STATUS,C
goto $+3
bsf GPIO,1
return
bcf GPIO,1
return
end