;Drive an infra-red LED cathode with digital output pin GP2.
;LED anode goes to +5V thru small series resistor, at 38000 Hz.
;23 cycles of 38 kHz, lasting about 600 microseconds
;turn IRLED off (high), lasting about 900 microseconds.
;Repeat this sequence forever.
;Default internal clock speed is 4MHz: instruction rate is 1000000/sec.
;All timing depends on 1MHz instruction rate!
;DON'T FORGET TO PULL notMCLR to LOGIC HIGH, else nothing runs!! Don't let it float.
;If you pull notMCLR low, IRLED goes off, until notMCLR goes high again.
;Watchdog timer is active - code resets it.
;By default, internal comparator is disabled from interfering with GP2 output pin.
;December2018
;
#include p10f200.inc ;register names defined here
;Macros:
#define ledon bcf GPIO,GP2 ;turn IRLED on by dragging cathode low.
#define ledoff bsf GPIO,GP2 ;turn IRLED off by dragging cathode high.
__CONFIG _MCLRE_ON ;GP3/MCLR pin functions as MCLR input..pull it high with
;a resistor to light up LED. Pull it low to turn LED off.
cnt equ 0x10 ;first available RAM location
burstcnt equ 0x11 ;a counter for burst length
;---------------------------------------------------------------
;
ORG 0000h ;start address from power-up or watchdog
andlw 0xFE ;reset to zero least sig bit: disable FOSC/4 output on GP2
movwf OSCCAL ;write oscillator calibration byte.
b setup ;go configure this simple environment...
;
setup:
movlw 0xDF ;make GP2 available as programable I/O pin rather
OPTION ;than TMR0 clk...write it to OPTION register
mainloop:
movlw 0x0b ;make GPIO 2 an output (not input) for driving IRLED
tris GPIO
movlw .23 ; init counter for six-hundred microsecond loop timer
movwf burstcnt ;it will be decremented to zero later.
shloop:
ledon ;macro to turn on IRLED
movlw 3 ;now waste some time....about 13us.
movwf cnt
decfsz cnt,f ;a short time-wasting loop
b $-1 ;loop for LED off period.
clrwdt ;clear the watchdog so it doesn't disturb us.
ledoff ;macro to turn off IRLED
movlw 3 ;now waste some time....about 13us.
movwf cnt
decfsz cnt,f
b $-1 ;time-wasting loop for LED on.
decfsz burstcnt,f ;done with 600 us burst?
b shloop ;no, complete this burst with more 38 kHz. cycles
;--------------------------------------------------------
ledoff ;turn IRLED off for remaining 900 microseconds
movlw .149 ;time-wasting counter for 900 us.
movwf cnt ;initialize off period count
nhloop:
nop
nop
nop
decfsz cnt,f
b nhloop ;countdown loop for LED off period.
b mainloop ;start again....600:on, 900:off loop forever
;--------------------------------------------------------
END ;finish assembler code.