I'm not going to try to read your unformatted code or write the entire application but here are code snippets that show you what you need to do. It sends 4 bits both "as is" and as bitwise complement using a variation of the NEC protocol. I've hardcoded the 4 bits of data as 1101. This is adapted from code I use to send and receive 2-4 bytes so the pins are the ones I used. There are more efficient ways to do things but I've tried to show it step-by-step so you see the logic.
Code:'-----Transmit----- SendRF: wb.0=data0 '00000001 wb.1=data1 '00000001 wb.2=data2 '00000101 wb.3=data3 '00001101 wb=~wb '11110010 wb=wb<<4 '00100000 wb.0=data0 '00100001 wb.1=data1 '00100001 wb.2=data2 '00100101 wb.3=data3 '00101101 'bits 0-3=data, bits 4-7=~data Low 4 For c=1 To Copies PulsOut 4, 500 PauseUs 2500 For i=0 To 7 PulsOut 4, 50 If wb.0=1 Then PauseUs 1500 Else PauseUs 500 EndIf wb=wb>>1 Next PulsOut 4, 50 Pause 20 Next '-----Receive----- DEFINE PULSIN_MAX = 550 RcvRF: PulsIn GPIO.1, 1, STX wb=0 If STX<450 Then RcvRF While GPIO.1=0:Wend For i = 0 To 7 PulsIn GPIO.1, 0, space If (space<40) Or (space>175) Then RcvRF If (space>75) Then wb.0=1 EndIf wb=wb<<1 Next i comp=wb>>4 wb=wb & 7 If wb + comp = 15 Then 'wb is good data Else 'wb is corrupt EndIf




Bookmarks