jeremygaughan
New Member
finally I got nigels code hacked. Better said would be butchered. But the cool thing is I can choose which light of the 4 I have on my board that I would like to light up. Here is the code if you have any suggestions or comments. Next step is ADC so I can use a potentiometer to change the byte. Then I will have a 1 channel IR airplane system.
Transmitter code
Receiver code
Transmitter code
Code:
;transmitter for 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 0x20
count1, counta, countb, count, bits, data1
endc
bsf STATUS,RP0 ;bank 1
clrf ANSEL
movlw 0x30
movwf TRISIO ;make bit 4 and 5 inputs
bcf STATUS,RP0
movlw 0x00
movwf GPIO
movlw 0x07 ;turn off comparitors
movwf CMCON
readswitch
btfss GPIO,5
call switch1 ;check if switch one is pressed
btfss GPIO,4
call switch2 ;check switch two
goto readswitch
switch1
movlw 0x01 ;send a one to the receiver
call xmit
retlw 0x00
switch2
movlw 0x02 ;send a two to the receiver
call xmit
retlw 0x00
startbit
movlw d'92' ;start bit
call irpulse
movlw d'23'
call nopulse
retlw 0x00
xmit
movwf data1 ;transmit byte assigned by the switch that was pressed
movlw 0x07
movwf bits
call startbit
loopsendcode
rrf data1,1 ;send a bit then rotate
btfsc STATUS,C ;keep sending bits until a byte is sent
call xmit1
btfss STATUS,C
call xmit0
decfsz bits,f
goto loopsendcode
retlw 0x00
xmit1
movlw d'46' ;send a one
call irpulse
movlw d'23'
call nopulse
retlw 0x00
xmit0
movlw d'23' ;send a zero
call irpulse
movlw d'23'
call nopulse
retlw 0x00
irpulse ;38Khz signal on
movwf count
irloop
bsf GPIO,1
nop
nop
nop
nop
nop
nop
nop
bcf GPIO,1
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
decfsz count,1
goto irloop
retlw 0x00
nopulse
movwf count ;38Khz signal off
irloop2
bcf GPIO,1
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
decfsz count,1
goto irloop2
retlw 0x00
delay27 ;delays that I'm not using
movlw d'27'
movwf count1
d1
movlw 0c7
movwf counta
movlw 0x01
movwf countb
delay1
decfsz counta,1
goto $+2
decfsz countb,1
goto delay1
decfsz count1,1
goto d1
retlw 0x00
end
Code:
;receiver 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
BH,BL,wait,del_clk1,del_clk2,run,runn,PWM,startcounter
startcounter2,zcounter,zcounter1,zcounter2,usefuldata,timer
endc
bsf STATUS,RP0 ;bank 1
clrf ANSEL
movlw 0x04
movwf TRISIO ;make bit 2 an input
bcf STATUS,RP0
movlw 0x07 ;turn off comparitors
movwf CMCON
main
movlw 0xff ;set PWM timer
movwf timer
clrf PWM
clrf usefuldata ;clear usefull data file and outputs
movlw 0x00
movwf GPIO
call prestartbit ;get the IR information
call dosomething ;use the IR information
goto main
dosomething
movf usefuldata,0 ;turn on a led that corresponds to bits send by IR
movwf GPIO
decfsz timer,1
goto dosomething
retlw 0x00
; movf usefuldata,0 ;PWM not currently in use
; movwf PWM
;bithigh
; bsf GPIO,0
; decfsz PWM,1
; goto bithigh
; bcf GPIO,0
; movf usefuldata,0
; movwf PWM
;bitlow
; incfsz PWM,1
; goto bitlow
; decfsz timer,1
; goto dosomething
; retlw 0x00
prestartbit
btfss GPIO,2 ;wait for high
goto prestartbit
prestartbit2
movlw 0x03
movwf startcounter2
btfsc GPIO,2
goto prestartbit2 ;wait for low
reset
movlw 0xbf
movwf startcounter
startbit
decfsz startcounter,1
goto startbit
btfss GPIO,2
goto $+2
goto prestartbit2
decfsz startcounter2,1 ;wait for start bit to finish
goto startbit ;keep starting over if not a start bit
readdata
btfss GPIO,2 ;wait to finish left over low
goto readdata
waitfordata
btfsc GPIO,2 ;wait for high between pulses to end
goto waitfordata
writedata
movlw 0xb0 ;cound down then see if it was long enough to be a 1
movwf zcounter
movwf zcounter1
movwf zcounter2
writebit0
decfsz zcounter,1
decfsz zcounter1,1
decfsz zcounter2,1
goto writebit0
btfsc GPIO,2 ;if not a 1 then go to wait for high to finish
goto bit0wait2 ;if a 1 then set that bit and continue
bsf usefuldata,0
bit0wait
btfss GPIO,2 ;wait for low to finish
goto bit0wait
bit0wait2
btfsc GPIO,2 ;wait for high to finish
goto bit0wait2
movlw 0xb0 ;continue until all bits in the
movwf zcounter ;usefull data file have been written
movwf zcounter1
movwf zcounter2
writebit1
decfsz zcounter,1
decfsz zcounter1,1
decfsz zcounter2,1
goto writebit1
btfsc GPIO,2
goto bit1wait2
bsf usefuldata,1
bit1wait
btfss GPIO,2 ;change to btfss
goto bit1wait
bit1wait2
btfsc GPIO,2
goto bit1wait2
movlw 0xb0
movwf zcounter
movwf zcounter1
movwf zcounter2
writebit2
decfsz zcounter,1
decfsz zcounter1,1
decfsz zcounter2,1
goto writebit2
btfsc GPIO,2
goto bit2wait2
bsf usefuldata,2
bit2wait
btfss GPIO,2 ;change to btfss
goto bit2wait
bit2wait2
btfsc GPIO,2
goto bit2wait2
movlw 0xb0
movwf zcounter
movwf zcounter1
movwf zcounter2
writebit3
decfsz zcounter,1
decfsz zcounter1,1
decfsz zcounter2,1
goto writebit3
btfsc GPIO,2
goto bit3wait2
bsf usefuldata,3
bit3wait
btfss GPIO,2 ;change to btfss
goto bit3wait
bit3wait2
btfsc GPIO,2
goto bit3wait2
movlw 0xb0
movwf zcounter
movwf zcounter1
movwf zcounter2
writebit4
decfsz zcounter,1
decfsz zcounter1,1
decfsz zcounter2,1
goto writebit4
btfsc GPIO,2
goto bit4wait2
bsf usefuldata,4
bit4wait
btfss GPIO,2 ;change to btfss
goto bit4wait
bit4wait2
btfsc GPIO,2
goto bit4wait2
movlw 0xb0
movwf zcounter
movwf zcounter1
movwf zcounter2
writebit5
decfsz zcounter,1
decfsz zcounter1,1
decfsz zcounter2,1
goto writebit5
btfsc GPIO,2
goto bit5wait2
bsf usefuldata,5
bit5wait
btfss GPIO,2 ;change to btfss
goto bit5wait
bit5wait2
btfsc GPIO,2
goto bit5wait2
movlw 0xb0
movwf zcounter
movwf zcounter1
movwf zcounter2
writebit6
decfsz zcounter,1
decfsz zcounter1,1
decfsz zcounter2,1
goto writebit6
btfsc GPIO,2
goto bit6wait2
bsf usefuldata,6
bit6wait
btfss GPIO,2 ;change to btfss
goto bit6wait
bit6wait2
btfsc GPIO,2
goto bit6wait2
movlw 0xb0
movwf zcounter
movwf zcounter1
movwf zcounter2
writebit7
decfsz zcounter,1
decfsz zcounter1,1
decfsz zcounter2,1
goto writebit7
btfss GPIO,2
bsf usefuldata,7
nop
retlw 0x00
end