To adapt for the crystal that you need
4 Mhz: Glitch = 52 ; Ok = 50
8 Mhz: Glitch = 104 ; Ok = 100
12 Mhz: Glitch = 156 ; Ok = 150
16 Mhz: Glitch = 208 ; Ok = 200
20 Mhz: Glitch = 260 ; Ok = 250
Code to receive:
Code: Select all
'Programa receptor de codigos PHILIPS RC5***************************************
'Receptor de codigos IR con protocolo Philips RC5 para Mikrobasic 5.0.0.0
'Codigo original extraido de: http://www.picbasic.nl
'Modificado y verificado por: Julio Montagut
'Web: http://www.jvmbots.com
'
'-HARDWARE:
' MCU: PIC 16F84A
' Cristal: 4 Mhz
' 8- Diodos LED conectados a PORTB
' 1- Receptor IR TSOP1736 conectado a PORTA.0
'*******************************************************************************
const Glitch = 52
const Ok = 50
Dim BD1 as Byte
Dim Inicio_Bit_1 as Byte
Dim Inicio_Bit_2 as Byte
Dim Toggle_Bit as Byte
Dim ComandoAnt as Byte
Dim Comando as Byte
Dim SistemaAnt as Byte
Dim Sistema as Byte
'Rutina de lectura del Receptor IR (PORTC.0)
Sub function Bit_IR as Byte
result = PORTA.0
BD1 = 0
WHILE PORTA.0 = result And (BD1 < Ok)
Inc(BD1)
WEND
IF Ok = BD1 THEN
GOSUB ErrorReceive
End if
Delay_us(1100)
exit
ErrorReceive:
Delay_ms(10)
Comando = ComandoAnt 'Restauramos el Comando que habia antes del error
Sistema = SistemaAnt 'Restauramos el Sistema que habia antes del error
End sub
Main:
TRISA.0 = 1
PORTA.0 = 0
TRISB = 0
PORTB = 0
'Reset de variables
Inicio_Bit_1=0
Inicio_Bit_2=0
Toggle_Bit=0
Comando=0
Sistema=0
Inicio:
While true
BD1 = 0
WHILE PORTA.0 = 1
Comando=0
Sistema=0
WEND
WHILE (PORTA.0=0) And (BD1 <Glitch> Glitch THEN
Delay_ms(100)
GOTO Inicio
End if
ComandoAnt = Comando 'Guarda los valores anteriores por si hay algun error
SistemaAnt = Sistema
Delay_us(200) '200us de respiro para el procesamiento del primer dato
Inicio_Bit_1.0=Bit_IR 'Bits de inicio
Inicio_Bit_2.0=Bit_IR
Sistema.4=Bit_IR 'Bits de Sistema
Sistema.3=Bit_IR
Sistema.2=Bit_IR
Sistema.1=Bit_IR
Sistema.0=Bit_IR
Comando.5=Bit_IR 'Bits de comando
Comando.4=Bit_IR
Comando.3=Bit_IR
Comando.2=Bit_IR
Comando.1=Bit_IR
Comando.0=Bit_IR
'Bit de Toggle
Toggle_Bit = Toggle_Bit xor 1
'Presentamos la informacion de comando recibida
PORTB=Comando
Delay_ms(10)
Wend
End.