Hello Again,
I have another problem with wireless communication, this time with IR.
I am trying to setup stable IR communication between to PIC's but I cannot get it to work.
For the transmitter i am using the 16F628 because of its Hardware PWM and for the receiver i am using the 12F629 because i have a heap of them.
Below is the code for the PIC's, can anyone see anything wrong?
Reciever Code<code>
INCLUDE "modedefs.bas"
@ DEVICE PIC12f629, XT_OSC
@ DEVICE PIC12f629, WDT_OFF
@ DEVICE PIC12f629, PWRT_ON
@ DEVICE PIC12f629, MCLR_OFF
@ DEVICE PIC12f629, BOD_ON
@ DEVICE PIC12f629, CPD_OFF
Define OSC 4
CMCON = 7
RXPIN Var GPIO.1 'Input PIN
TXPIN VAR GPIO.2 'Output PIN
VALID VAR byte 'Valid Code
UTYPE VAR BYTE 'Unit Type
UID VAR BYTE 'Unit Identefier
VALID = 0
utype = 0
uid = 0
LOW 0
rx:
serin rxpin,n1200,[$66],VALID,UTYPE,UID
if VALID = 22 then hit
goto rx
hit:
high 0
pause 250
low 0
VALID = 0
goto rx
end
</code>
Transmitter Code<code>
INCLUDE "modedefs.bas"
@ DEVICE PIC16f628, XT_OSC
@ DEVICE PIC16f628, LVP_OFF
@ DEVICE PIC16f628, WDT_OFF
@ DEVICE PIC16f628, MCLR_OFF
DEFINE OSC 4 ' We're using a 4MHz oscillator
TXPIN Var PortB.1 ' Output PIN
VALID CON 22 ' Valid Code
UTYPE CON 27 ' Unit Type
UID con 2550 ' Unit Identefier
' Initialize hardware PWM - IRLED 38KHz drive
PORTB = %00000000 ' PortB = 0 : IRLED On PortB.1 Off
TRISB = %00000000 ' PortB = all outputs
PR2 = 25 ' Set PWM for approximately 38KHz
CCPR1L = 13 ' Set PWM Duty-Cycle to 50%
CCP1CON = %00001100 ' Mode select = PWM
T2CON = %00000100 ' Timer2 ON + 1:1 prescale
IR_TX:
serout txpin,n1200,[$66,VALID,UTYPE,UID]
PAUSE 1000 ' 1sec delay
GOTO IR_TX
End
</code>
Thank Again,
Jeremy
Bookmarks