I apologize for the delay. I have a spinal cord injury which incapacitates me when it acts up and it's been acting up for several days. What follows is revised slightly from the earlier code. I have not tested this with a terminal program (right now I'm working with Linux and do not have a terminal program handy) but I have looked at the GPIO.2 output with a 'scope and it appears to be a valid RS232 signal. Here's the transmit code:
Code:
'-----PIC12F629-----
' Sends 2 bytes + their bitwise complements using the NEC protocol
' repeats every 15 seconds
@ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
DEFINE OSCCAL_1K 1
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] & complement in RF[1] & RF[3]
SendRF: RF[0]=80:RF[1]=~RF[0]:RF[2]=66:RF[3]=~RF[2]
Low GPIO.2
For c=1 To Copies
PulsOut GPIO.2, 880 '8.8mS pulse
PauseUs 4400 '4.4mS space
For b=0 To 3
wb=RF[b]
For i=0 To 7 'LSB first
PulsOut GPIO.2, 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 GPIO.2, 50 '0.5mS pulse
Pause 40: '40mS GAP
Next
Pause 15000 '15 SEC DELAY
GoTo SendRF
End
and here is the receiver code:
Code:
'12F629
@ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_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
stx VAR word 'start of transmission
CMCON = 7 'comparators off
Debug "RF NEC PROTOCOL"
init: RF[0]=0:RF[1]=0:RF[2]=0:RF[3]=0:i=0
PulsIn GPIO.1, 1, stx
If (stx<792) Then init
'debug #stx
While GPIO.1=0:Wend 'wait pulse
Repeat
PulsIn GPIO.1, 0, space
If ((space<40) Or (space>180)) Then init
If (space>75) Then
RF.0(i)=1 'set bit
EndIf
i=i+1
Until (i>31)
If (RF[0]+RF[1]<$FF) Then init 'corrupt
If (RF[2]+RF[3]<$FF) Then init 'corrupt
RF[1]=RF[0] REV 8
RF[3]=RF[2] REV 8
Debug RF[1],32,RF[3]
GoTo init
End
Bookmarks