Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
so a 3A+ relay should be perfect right? I need to order one so i want to make sure i get it right
The protocol uses bi-phase modulation (or so-called Manchester coding) of a
36kHz IR carrier frequency. All bits are of equal length of 1.778ms in this protocol,
with half of the bit time filled with a burst of the 36kHz carrier and the other half being
idle. A logical zero is represented by a burst in the first half of the bit time.
A logical one is represented by a burst in the second half of the bit time.
The pulse/pause ratio of the 36kHz carrier frequency is 1/3 or 1/4 which reduces
power consumption.
* Carrier frequency of 36kHz
* Constant bit time of 1.778ms (64 cycles of 36 kHz)
* The recommended carrier duty-cycle is 1/4 or 1/3.
All bits are of equal length of 1.778ms in this protocol, with half of the bit time filled with
a burst of the 36kHz carrier and the other half being idle.
32x loop:
9.256uS = pin high
18.513uS = pin low
32x loop
27.77uS = pin low
MainApp:
MainAdd = ReadEE(0x00);
MainCmd = ReadEE(0x01);
while(1){
GetSIRC(&MyAdd,&MyCmd);
if(MyAdd == 0x01)
if(MyCmd == 0x00){
if(IsSet == 0){
RelayPin = 1;
IsSet = 1;
} else {
RelayPin = 0;
IsSet = 0;
}
}
delay_ms(250);
delay_ms(250);
}
if(MyCmd == 0x00)
if(MyCmd == MainCmd)
#include <p18cxxx.h>
#include <delays.h>
#pragma config WDT = OFF, LVP = OFF, OSC = HS, DEBUG = OFF
#define keypadPort PORTB // Keypad attached with PORT
#define keypad_DA PORTBbits.RB4 // Data Enable pin of Keypad Encoder
#define irPin LATBbits.LATB7
void main(void);
void ReadKeypad(void);
void SendSIRC(unsigned char Dev, unsigned char Cmd);
void PulseIt(unsigned char time);
ram unsigned int keypress_count = 0;
ram unsigned int keypad_loop_flag = 0;
ram unsigned char keyNum;
void main(void){
unsigned long i = 0;
ADCON1 = 0xFF;
TRISA = 0x00;
TRISB = 0b01111111;
while(1)
{
for(i = 0; i < 1000; i++)
{
SendSIRC(i,i);
Delay10KTCYx(100);
PORTA = i;
}
// ReadKeypad();
// PORTA = keyNum;
}
}
void SendSIRC(unsigned char Dev, unsigned char Cmd)
{
char x;
PulseIt(4); //Logic Start
for(x=0;x<7;x++){
if(Cmd & 0x01)
PulseIt(2); //Logic 1
else
PulseIt(1); //Logic 0
Cmd <<= 1;
}
for(x=0;x<5;x++){
if(Dev & 0x01)
PulseIt(2); //Logic 1
else
PulseIt(1); //Logic 0
Dev <<= 1;
}
Delay10KTCYx(90); //45mS Delay
}
void PulseIt(unsigned char time){
unsigned char x,y,z;
for(y = 0; y < time; y++)
{
for(x=0;x<24;x++) //600uS worth
{
irPin = 1;
Delay10TCY();
Nop();
Nop();
Nop(); //About 7uS
irPin = 0;
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Delay10TCY();
Delay10TCY(); //About 18uS
}
}
for(x=0;x<24;x++) //600uS worth
{
irPin = 0;
Delay10TCY();
Nop();
Nop();
Nop(); //About 7uS
irPin = 0;
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Delay10TCY();
Delay10TCY(); //About 18uS
}
}
void ReadKeypad()
{
if(keypad_DA != 1){keypad_loop_flag = 0;return;}
keyNum = keypadPort & 0x0F; // Stripping keypad related bits (Change to 0xF0 if keypad connected with MSB of PORT)
//keyNum >>= 4; // Shifting keypad bits to make them decimal equivalent (use in case keypad connected with MSB of PORT)
switch(keyNum)
{
case 0:
SendSIRC(1,0);
break;
case 1:
SendSIRC(2,0);
break;
case 2:
SendSIRC(3,0);
break;
case 3:
SendSIRC(1,4);
break;
case 4:
SendSIRC(1,5);
break;
case 5:
SendSIRC(1,6);
break;
case 6:
SendSIRC(1,7);
break;
case 7:
SendSIRC(1,8);
break;
case 8:
SendSIRC(1,9);
break;
case 9:
SendSIRC(1,10);
break;
case 10:
SendSIRC(1,11);
break;
case 11:
SendSIRC(1,12);
break;
case 12:
SendSIRC(1,13);
break;
case 13:
SendSIRC(1,14);
break;
case 14:
SendSIRC(1,15);
break;
case 15:
SendSIRC(1,16);
break;
default:
break;
}
Delay10KTCYx(1);
}
void lock_key(void)
{
while(keypad_DA == 1);
}
#include <p18cxxx.h>
#include <delays.h>
#include <string.h>
#pragma config WDT = OFF, LVP = OFF, OSC = HS, DEBUG = OFF
unsigned char lTime;
unsigned char MyAdd;
unsigned char MyCmd;
#define irPin PORTBbits.RB0
#define Led_6 LATBbits.LATB1
#define Led_5 LATBbits.LATB2
#define Led_4 LATBbits.LATB3
#define Led_3 LATBbits.LATB4
#define Led_2 LATBbits.LATB5
#define Led_1 LATBbits.LATB6
#define Led_0 LATBbits.LATB7
void main(void);
void GetSIRC(unsigned char *address, unsigned char *command);
void main(void){
TRISB = 0x01;
TRISA = 0x00;
ADCON1 = 0xFF;
PORTB = 0;
PORTA = 0;
while(1){
GetSIRC(&MyAdd,&MyCmd);
Led_0 = 0;
Led_1 = 0;
Led_2 = 0;
Led_3 = 0;
Led_4 = 0;
Led_5 = 0;
Led_6 = 0;
PORTA = MyCmd;
switch(MyCmd){
case 0:
Led_0 = 1;
break;
case 1:
Led_1 = 1;
break;
case 2:
Led_2 = 1;
break;
case 3:
Led_3 = 1;
break;
case 4:
Led_4 = 1;
break;
case 5:
Led_5 = 1;
break;
case 6:
Led_6 = 1;
break;
}
}
}
void GetSIRC(unsigned char *address, unsigned char *command){
unsigned char ir_add;
unsigned char ir_cmd;
char x;
StartLook:
ir_add = ir_cmd = 0;
while(irPin); //wait for it to be low
lTime = 0; //reset the counter
while(irPin == 0){ //while the pin is low which is our pulse count
lTime++; //increment every 200uS until pin is high
Delay100TCYx(4); //200uS delay
}
if(lTime <= 10) //Start too short
goto StartLook; //Restart
if(lTime >= 14) //Start too long
goto StartLook; //Restart
lTime = 0;
for(x=0;x<7;x++){ //repeat 7 times for command
ir_cmd >>= 1; //if it was skipped or is done ORing then shift over the 1
while(irPin); //wait for it to be low
lTime = 0; //reset the counter
while(irPin == 0){ //while the pin is low which is our pulse count
lTime++; //increment every 200uS until pin is high
Delay100TCYx(4); //200uS delay
}
if(lTime >= 6) //If its high then OR a 1 in else skip
ir_cmd |= 0x40; //if its less than 6 its a 0 so dont OR it
}
for(x=0;x<5;x++){ //repeat 5 times for address/device
ir_add >>= 1; //if it was skipped or is done ORing then shift over the 1
while(irPin); //wait for it to be low
lTime = 0; //reset the counter
while(irPin == 0){ //while the pin is low which is our pulse count
lTime++; //increment every 200uS until pin is high
Delay100TCYx(4); //200uS delay
}
if(lTime >= 6) //If its high then OR a 1 in else skip
ir_add |= 0x10; //if its less than 6 its a 0 so dont OR it
}
*address = ir_add;
*command = ir_cmd;
}