Hi
Here is a TV, video, etc. remote control repeater Pascal code. It just
get the signal arrived from up to 4 sources (4 places where you can put a TSOP receiver). When there is detection it makes pwm pin = a out pin. When there is not, it makes pwm pin=tristate. The lR led is near the TV, video, etc. receivers in order to control them. So, from another room you can control them. There is an extra plain led in the board so you can see it brlinking when you press your remote control.
While it don't use usart (serial interface), can be of some use in order to see reception and transmission of IR at 38Kz.. There is also I used a 16F628, internal clock, 4MHz, in a weekend when I was bored to go back and forth to control a remote device...
PortA0 and portA1 must receive 38Khz sensors. PortA2 and portA3 must receive 36Khz sensors. You can use
only the sensors you intend to use. You can put the sensors in 2 distinct ambients.
Good Luck
Jose
*ps: this is a good program to extend in order to record the pulse sequence of any remote control, and, convert it to another set of commands, like making a universal remote control. Some kind of "recorder" where the guy would giving a sequence key presses.
Code: Select all
program RemoteRepeat_v1;
{ this program is a repeater for remote controls. It can operate with 38Khz and 36Khz remote controls.
The main loop verifies if there is any of the 4 sensors receiving signal. If yes, it starts pwm at
38 or 36 Hkz and stays in a loop until the sensors does not detect any more the signal. So, it inhibits
pwm output. Pwm output goes to a IR led.
Jose Lavaquial - march 2009.
PortA0 and portA1 must receive 38Khz sensors. PortA2 and portA3 must receive 36Khz sensors. You can use
only the sensors you intend to use. You can put the sensors in 2 distinct ambients.
}
Var sensors: byte; absolute $05; volatile; register; {map sensors IR over PortA}
Const maskSensors= %00001111; // up to 4 sensors can be connected , but just one used at each time
SensorsAt38KzOn= %00000011; // sensors for 38Khz (bit 0 and 1)
SensorsAt36KzOn= %00001100; // sensors for 36Khz (bit 2 and 3)
Var maskedSensors: byte;
k:byte;
procedure pwm38Kz;
begin
// PWM: 38.4KHz, 50% duty , clock=4MHz
PR2:= %00011001 ; //25=Set PR2 for 38.4kHz PWM [26uS period]
T2CON := %00000100 ; //Turn on Timer2, Prescale = 1
CCPR1L := 12 ; //Set PWM Duty-Cycle to 50%
CCP1CON := 60 ; //Set CCP1 to PWM
TrisB.3:= 0; //enable pwm output
portB.7:=1;
end;
procedure pwm36Kz;
begin
// PWM: 35.7KHz, 50% duty , clock=4MHz
PR2:= %00000110 ;
T2CON:= %00000101 ;
CCPR1L:= %00000011 ;
CCP1CON:= %00011100 ;
TrisB.3:= 0; //enable pwm output
portB.7:=1;
end;
procedure initSetup;
begin
// sets TrisA,TrisB and other registers
IntCon:= 0; // no interrupts
CMCON:= 7; // comparador off
OPTION_REG:= %00001111; //ATIVA Timer0 (lido como semente p nros. randomicos)
//ativa postscaler máximo (128 vezes) p/ watchdog (perto de 2 segundos)
trisA:= %11111111 ; // faz portas serem IN=1/OUT=0
trisB:= %01111111 ; //PWM out as tristate (led will no blink) and B.7 = 0 (blinking led)
portA:= $ff;
portB:= $7f;
trisB.3:=1;
// delay_ms(300);
end;
begin
delay_ms(1500); //just wait power to stabilize
initSetup;
while true do //loop checks if sensor detected any remote control sending commands
begin
TrisB.3:= 1; //pwm pin=tristate => stops 38.4/36KhzKhz to IR Led
portB.7:= 0; //visual blinking led off
if sensors.0 = 0 then //if IR sensor1 is receiving signal...
begin
pwm38Kz; //.. starts pwm for 38.4Khz, that goes to IR Led
while sensors.0=0 do //.. and while it's receiving signal..
begin end; //.....just wait for signal end.
continue; //.. goes to the next
end;
if sensors.1 = 0 then //if IR sensor 2 is receiving signal...
begin
pwm38Kz; //.. starts pwm for 38.4Khz, that goes to IR Led
while sensors.1=0 do //.. and while it's receiving signal..
begin end; //.....just wait for signal end.
continue; //.. goes to the next
end;
if sensors.2 = 0 then //if IR sensor 3 is receiving signal...
begin
pwm36Kz; //.. starts pwm for 36KKhz, that goes to IR Led
while sensors.2=0 do //.. and while it's receiving signal..
begin end; //.....just wait for signal end.
continue; //.. goes to the next
end;
if sensors.3 = 0 then //if IR sensor 3 is receiving signal...
begin
pwm36Kz; //.. starts pwm for 36KKhz, that goes to IR Led
while sensors.3=0 do //.. and while it's receiving signal..
begin end; //.....just wait for signal end.
continue; //.. goes to the next
end;
end;
end.