jhorsburgh
- 6th June 2008, 08:48
Hello Everyone,
As you will no doubt gather from the following question, i am very new to PIC's, PIC Programmers and their corresponding code. I have a question about two peices of code i found posted in the forum archives;
Exibit A
<code>
'-----PIC12F629-----
' Sends 2 bytes + their bitwise complements using a variation of the NEC IR protocol
' repeats every 15 seconds
' I've used this (and seen it used in commercial RF products) using 12-48 bits
' with lead-in pulses from 2.5-9.5mS and lead-in spaces from 2.5-4.5mS
@ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON & _CP_OFF & _CPD_OFF
RF VAR byte[4]
Copies VAR byte 'RF copies
c VAR byte 'loop index (RF copies)
b VAR byte 'loop index (RF[b])
i VAR byte 'bit index
wb VAR byte 'work byte
CMCON = 7
Copies = 4
'Put data in RF[0] & RF[2]
SendRF: RF[0]=80:RF[1]=~RF[0]:RF[2]=66:RF[3]=~RF[2]
Low 4
For c=1 To Copies
PulsOut 4, 880 '8.8mS lead-in pulse
PauseUs 4400 '4.4mS space
For b=0 To 3
wb=RF[b]
For i=0 To 7 'LSB first
PulsOut 4, 50 '0.5mS pulse
If wb.0=1 Then
PauseUs 1500 '1.5mS space
Else
PauseUs 500 '0.5mS space
EndIf
wb=wb>>1
Next
Next
PulsOut 4, 50 '0.5mS pulse
Pause 40: '40mS GAP
Next
Sleep 15 '15 SEC DELAY
GoTo SendRF
End
</code>
And Exibit B
<code>
'-----PIC12F629-----
'Receives 32 bits of NEC protocol
'RF with initial lead-in of 8.8mS
'sends codes via RS232 @ 9600bps on GPIO.2
@ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON & _CP_OFF & _CPD_OFF
DEFINE PULSIN_MAX 968 '>968 RETURNS 0
DEFINE DEBUG_REG GPIO
DEFINE DEBUG_BIT 2 'GPIO.2
DEFINE DEBUG_MODE 1 'Inverted
DEFINE DEBUG_BAUD 9600
DEFINE OSCCAL_1K 1
RF VAR byte[4]
space VAR byte
i VAR byte
bits VAR byte
stx VAR word 'start of transmission
CMCON = 7 'comparators off
init: RF[0]=0:RF[1]=0:RF[2]=0:RF[3]=0
bits=0:i=0
PulsIn GPIO.1, 1, stx
If (stx<792) Then init
While GPIO.1=0:Wend 'wait pulse
Repeat
PulsIn GPIO.1, 0, space
If (space<40) Or (space>175) Then init
If (space>75) Then
RF.0(i)=1 'set bit
EndIf
i=i+1
Until (i>31)
If RF[0]+RF[1]<>&HFF Then init
If RF[2]+RF[3]<>&HFF Then init
For i = 0 to 3
Debug (RF[i] REV 8)
Next
GoTo init
End
</code>
How would i wire up the two circuits or better yet does anyone have a wiring diagram for the two circuits? I am pretty sure i have all the components eg. the PIC12F629's, the wireless modules, RS232 plug, capacitors and a power supply.
Any help in this matter would be very much appreciated.
Thanks All,
Jeremy - Aspiring PIC Programmer
As you will no doubt gather from the following question, i am very new to PIC's, PIC Programmers and their corresponding code. I have a question about two peices of code i found posted in the forum archives;
Exibit A
<code>
'-----PIC12F629-----
' Sends 2 bytes + their bitwise complements using a variation of the NEC IR protocol
' repeats every 15 seconds
' I've used this (and seen it used in commercial RF products) using 12-48 bits
' with lead-in pulses from 2.5-9.5mS and lead-in spaces from 2.5-4.5mS
@ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON & _CP_OFF & _CPD_OFF
RF VAR byte[4]
Copies VAR byte 'RF copies
c VAR byte 'loop index (RF copies)
b VAR byte 'loop index (RF[b])
i VAR byte 'bit index
wb VAR byte 'work byte
CMCON = 7
Copies = 4
'Put data in RF[0] & RF[2]
SendRF: RF[0]=80:RF[1]=~RF[0]:RF[2]=66:RF[3]=~RF[2]
Low 4
For c=1 To Copies
PulsOut 4, 880 '8.8mS lead-in pulse
PauseUs 4400 '4.4mS space
For b=0 To 3
wb=RF[b]
For i=0 To 7 'LSB first
PulsOut 4, 50 '0.5mS pulse
If wb.0=1 Then
PauseUs 1500 '1.5mS space
Else
PauseUs 500 '0.5mS space
EndIf
wb=wb>>1
Next
Next
PulsOut 4, 50 '0.5mS pulse
Pause 40: '40mS GAP
Next
Sleep 15 '15 SEC DELAY
GoTo SendRF
End
</code>
And Exibit B
<code>
'-----PIC12F629-----
'Receives 32 bits of NEC protocol
'RF with initial lead-in of 8.8mS
'sends codes via RS232 @ 9600bps on GPIO.2
@ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON & _CP_OFF & _CPD_OFF
DEFINE PULSIN_MAX 968 '>968 RETURNS 0
DEFINE DEBUG_REG GPIO
DEFINE DEBUG_BIT 2 'GPIO.2
DEFINE DEBUG_MODE 1 'Inverted
DEFINE DEBUG_BAUD 9600
DEFINE OSCCAL_1K 1
RF VAR byte[4]
space VAR byte
i VAR byte
bits VAR byte
stx VAR word 'start of transmission
CMCON = 7 'comparators off
init: RF[0]=0:RF[1]=0:RF[2]=0:RF[3]=0
bits=0:i=0
PulsIn GPIO.1, 1, stx
If (stx<792) Then init
While GPIO.1=0:Wend 'wait pulse
Repeat
PulsIn GPIO.1, 0, space
If (space<40) Or (space>175) Then init
If (space>75) Then
RF.0(i)=1 'set bit
EndIf
i=i+1
Until (i>31)
If RF[0]+RF[1]<>&HFF Then init
If RF[2]+RF[3]<>&HFF Then init
For i = 0 to 3
Debug (RF[i] REV 8)
Next
GoTo init
End
</code>
How would i wire up the two circuits or better yet does anyone have a wiring diagram for the two circuits? I am pretty sure i have all the components eg. the PIC12F629's, the wireless modules, RS232 plug, capacitors and a power supply.
Any help in this matter would be very much appreciated.
Thanks All,
Jeremy - Aspiring PIC Programmer