Thursday, March 18, 2010

Program for Transmitter

#include <16f877A.h> //use pic16f877A
#device adc=8 //use 8 bit adc function to read temperature
#use delay(clock = 20000000) //clock=20mhz
#fuses hs, noprotect, nowdt //default setting
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,PARITY=N)

#byte PORTA=5 //define PORT A address
#byte PORTB=6 //define PORT B address
#byte PORTC=7 //define PORT C address
#byte PORTD=8 //define PORT d address

void main()
{
int press1, press2;
int txdata1=0;
int txdata2=0;
int txdata3=0;
int myvr1, myvr2;

//set i/o for each pin
set_tris_a(0b11111111);
set_tris_b(0b00000000);
set_tris_c(0b10110000);
set_tris_d(0b00000000);
setup_port_a(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);

//test output
output_high(pin_d2);
delay_ms(1000);
output_low(pin_d2);
delay_ms(1000);

do
{
//if forward button pressed
if(input(pin_c4)==0 && press1==1)
{
txdata1='a';
press1=0;
}
else if(input(pin_c4)==1)
{
press1=1;
}

//if reverse button pressed
if(input(pin_c5)==0 && press2==1)
{
txdata1='b';
press2=0;
}
else if(input(pin_c5)==1)
{
press2=1;
}

set_adc_channel(0);
delay_ms(10);
myvr1=read_adc();
txdata2=myvr1;

set_adc_channel(1);
delay_ms(10);
myvr2=read_adc();
txdata3=myvr2;

if(input(pin_c4)==0 ||input(pin_c5)==0)
{
output_high(pin_d2);
}
else
{
output_low(pin_d2);
}

putc(txdata1);
putc(txdata2);
putc(txdata3);

delay_ms(250);

}while(1);
}
**********************************************
Program above is to another PIC in remote circuit that will transmit the data by using variable resister and push button as an input and LED as an output.. The variable resister is connected to the analog pin at the PIC. So, in the program, it need to setup all Pin A as an analog.. And the PIC will sent data 'a' to make the relay on, and data 'b' to make the relay off.. As for the variable resister, it need a ADC to read the signal and transmit it to another circuit.. And if it success in transmitting the data, each LED will light on as for the testing purpose..

1 comment:

  1. ASSALAMU ALAIKUM.

    I am interested to implement a network with the ZigBee Protocol. It is really encouraging to see your different projects and programs using ZigBee Protocol. Is it possible to contact to you via Email for your wise expertise? My Email Address : kamrulbaf@gmail.com.

    Please let me know as soon as possible.

    Kazi Kamrul Alam
    Bangladesh

    ReplyDelete