You are on page 1of 7

RF Railway Gate

Circuit Diagram: (Transmitter)

Circuit Diagram: (Receiver)

PCB Layout:

Main Code:
#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#include "LCD_8_BIT.c"
void main()
{
set_tris_a(0x01);
set_tris_c(0x30);
set_tris_d(0x00);
set_tris_e(0x01);
init();
delay_ms(500);
printf(data,"Automatic Railway");
delay_ms(1000);
cmd(0x01);
printf(data,"Gate Cntrl Systm");
delay_ms(1000);
cmd(0x01);
for(;;)
{
/**********************Receiver Code**********************/
printf(data,"waiting....");
while((!input(PIN_C4)) && (!input(PIN_A0)));
if(input(PIN_C4) && input(PIN_C5))
{
printf(data,"Train: Right");
output_high(PIN_C7);
// Right LED Indication ON
delay_ms(1000);
cmd(0x01);
printf(data,"Gate Closes:5sec");
delay_ms(1000);
cmd(0x01);
printf(data,"Gate Closes:4sec");
delay_ms(1000);
cmd(0x01);

printf(data,"Gate Closes:3sec");
delay_ms(1000);
cmd(0x01);
printf(data,"Gate Closes:2sec");
delay_ms(1000);
cmd(0x01);
printf(data,"Gate Closes:1sec");
delay_ms(1000);
cmd(0x01);
printf(data,"Gate Closing");
output_high(PIN_C6);
delay_ms(1000);
cmd(0x01);
output_low(PIN_C6);

// Motor Indication ON

// Motor Indication OFF

printf(data,"Gate Closed");
delay_ms(1000);
cmd(0x01);
printf(data,"Gate Opens: 5sec");
delay_ms(1000);
cmd(0x01);
printf(data,"Gate Opens: 4sec");
delay_ms(1000);
cmd(0x01);
printf(data,"Gate Opens: 3sec");
delay_ms(1000);
cmd(0x01);
printf(data,"Gate Opens: 2sec");
delay_ms(1000);
cmd(0x01);
printf(data,"Gate Opens: 1sec");
delay_ms(1000);
cmd(0x01);
printf(data,"Gate Opening");
output_high(PIN_C6);
delay_ms(1000);
cmd(0x01);

// Motor Indication ON

output_low(PIN_C6);

// Motor Indication OFF

printf(data,"Gate Opened");
delay_ms(1000);
cmd(0x01);
output_low(PIN_C7);
// Right LED Indication OFF
}
else if(input(PIN_A0) && input(PIN_E0))
{
printf(data,"Train: Left");
output_high(PIN_A1);
// Left LED Indication ON
delay_ms(1000);
cmd(0x01);
printf(data,"Gate Closes:5sec");
delay_ms(1000);
cmd(0x01);
printf(data,"Gate Closes:4sec");
delay_ms(1000);
cmd(0x01);
printf(data,"Gate Closes:3sec");
delay_ms(1000);
cmd(0x01);
printf(data,"Gate Closes:2sec");
delay_ms(1000);
cmd(0x01);
printf(data,"Gate Closes:1sec");
delay_ms(1000);
cmd(0x01);
printf(data,"Gate Closing");
output_high(PIN_C6);
delay_ms(1000);
cmd(0x01);
output_low(PIN_C6);

// Motor Indication ON

// Motor Indication OFF

printf(data,"Gate Closed");
delay_ms(1000);
cmd(0x01);
printf(data,"Gate Opens: 5sec");

delay_ms(1000);
cmd(0x01);
printf(data,"Gate Opens: 4sec");
delay_ms(1000);
cmd(0x01);
printf(data,"Gate Opens: 3sec");
delay_ms(1000);
cmd(0x01);
printf(data,"Gate Opens: 2sec");
delay_ms(1000);
cmd(0x01);
printf(data,"Gate Opens: 1sec");
delay_ms(1000);
cmd(0x01);
printf(data,"Gate Opening");
output_high(PIN_C6);
delay_ms(1000);
cmd(0x01);
output_low(PIN_C6);

// Motor Indication ON

// Motor Indication OFF

printf(data,"Gate Opened");
delay_ms(1000);
cmd(0x01);
output_low(PIN_A1);
}
else
{
printf(data,"Gate Opened");
delay_ms(1000);
cmd(0x01);
}
}
}

// Left LED Indication OFF

LCD_8_BIT Code:
#define EN_low OUTPUT_LOW(PIN_C2)
#define EN_high OUTPUT_HIGH(PIN_C2)
#define RW_low OUTPUT_LOW(PIN_C1)
#define RW_high OUTPUT_HIGH(PIN_C1)
#define RS_low OUTPUT_LOW(PIN_C0)
#define RS_high OUTPUT_HIGH(PIN_C0)

void cmd(int i)
{
OUTPUT_D(i);
RS_low;
RW_low;
EN_high;
EN_low;
delay_ms(10);
}
void data(int i)
{
OUTPUT_D(i);
RS_high;
RW_low;
EN_high;
EN_low;
delay_us(100);
}
void init()
{
cmd(0x38); delay_ms(2);
cmd(0x0F);
cmd(0x01);
cmd(0x06);
}

You might also like