HARIS RASHID
Newbie level 4
hi
i need code which generate ir 38 khz pwm using pic12f675
i need code which generate ir 38 khz pwm using pic12f675
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
You do not normally need PWM for 38KHz IR, just square waves.hi
i need code which generate ir 38 khz pwm using pic12f675
;IRTX - use MPASM in relocatable mode
#include p12f675.inc ;with analogue
__CONFIG 0x0184
errorlevel -302 ;prevent bank select warnings
#define irout GPIO,4 ;pic pin 3 infra red output
;12f675 ram 20 to 5f hex
udata_shr
timer1 res 1 ;shared by delay routines
timer2 res 1 ;shared by delay routines
timer3 res 1 ;shared by delay routines
code 0 ;reset vector
;initilisation starts here
start
bcf STATUS,RP0 ;bank 0
clrf GPIO ;init GPIO
movlw 0x0f ;set I/O bits
movwf CMCON ;digital I/O
bsf STATUS,RP0 ;bank1
clrf ANSEL ;digital I/O (pic12f675 only)
movlw 0x2a ;set I/O bits, 1=input
movwf TRISIO ;note GP3 pin4 can only be input
movlw 0x28 ;set weak pullup bits
movwf WPU
bsf OPTION_REG,7 ;allow weak pullups
bcf STATUS,RP0 ;bank 0
bcf irout ;be sure to turn off IR to prevent burnout
;tx test loop
tloop
movlw d'175' ;4.5ms mark
call pulse_ir_w
movlw d'163' ;4.5ms space
call wait_ir_w
goto tloop
; send w pulses of 38 Khz to IR LED
pulse_ir_w
movwf timer3 ;save the value
movwf timer2
pulse_loop
bsf irout ;IR on
movlw 0x02
movwf timer1
pulse1
decfsz timer1,F ;.2us of 26ms
goto pulse1 ;.2us
nop
nop
nop
bcf irout ;IR off
movlw 0x04
movwf timer1
pulse2
decfsz timer1,F
goto pulse2
decfsz timer2,F
goto pulse_loop ;loop w times
movfw timer3 ;restore the value
return
;wait w times 38 KHz - no output, but same code as above to get same timing
wait_ir_w
movwf timer3 ;save the value
movwf timer2
wait_loop
bcf irout ;IR off
movlw 0x02
movwf timer1
wait1
decfsz timer1,F
goto wait1
nop
nop
nop
nop
bcf irout ;IR off
movlw 0x04
movwf timer1
wait2
decfsz timer1,F
goto wait2
decfsz timer2,F
goto wait_loop ;loop w times
movfw timer3 ;restore the value
return
end