Monday, March 29, 2010

Program for Receiver

#include <16f877a.h>
#use delay(clock=20000000)
#fuses hs,nowdt,protect
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,PARITY=N)

//initialize port
#byte PORTA=5
#byte PORTB=6
#byte PORTC=7
#byte PORTD=8

int receive1=0;
int receive2=0;
int receive3=0;

//receive data
#int_rda
void serial_isr()
{
receive1=getch();
receive2=getch();
receive3=getch();
}

void main()
{
//set io for pic
set_tris_a(0b11111111);
set_tris_b(0b00000000);
set_tris_c(0b10000000);
set_tris_d(0b00000000);
setup_port_a(NO_ANALOGS);
setup_adc(ADC_CLOCK_INTERNAL);

//set interrupt
enable_interrupts(int_rda);
enable_interrupts(GLOBAL);

//set pwm
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
setup_timer_2(T2_DIV_BY_1, 255, 1);

//test output
output_high(pin_d1);
output_high(pin_c4);
set_pwm1_duty(255);
set_pwm2_duty(255);
delay_ms(2000);
output_low(pin_d1);
output_low(pin_c4);
set_pwm1_duty(0);
set_pwm2_duty(0);

do
{
//blink led
output_high(pin_c4);
delay_ms(250);
output_low(pin_c4);
delay_ms(250);

if(receive1=='a') //on relay
{
output_high(pin_d1);
}
else if(receive1=='b') //off relay
{
output_low(pin_d1);
}

set_pwm1_duty(receive2);
set_pwm2_duty(receive3);

}while(1);


}
******************************************
Program above is about to make the fan, light and radio work.. The relay is about to on and off the radio.. while for pwm is to set the signal that will get from the transmitter is going to 255 (higher) and 0 (lower). This is the final program and will be test to the circuit by detect the LED first as an output.

Thursday, March 25, 2010

Suddenly SKXBee cannot be function..

My both SKXbee cannot function at all.. They don't want to communicate to each other.. I need to troubleshoot it? but how? So leave it to keep in view (KIV) for a moment.. So, I will continue in designing the transmitter circuit and program..

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..

Circuit for Transmitter



Figure above is receiver circuit. The power supply is connected to the 5v regulator to jot down the voltage from 9v to 5v because the PIC can only receive 5v of supply if not, the microcontroller will be damage. The supply also connect to the 3.3v regulator to jot down the 9v supply to 3.3v supply and connect it to the XBee chip. The XBee can only accept 3.3v of supply and if it not, the Xbee chip will be burn or damage. But, if you using the XBee module, you no need to connect it to the 3.3v regulator, you can just directly connect the supply 5v at the PIC because the module it self already have the built-in circuit to jot down the supply.

As for the crystal, I'm using the 20MHz because it is the maximum speed that PIC can reach to read the program in one clock pulse. This crystal has no polarity and it always connect to the 13 and 14 pin of PIC because that pin have clock peripheral. And the two capacitor at each side of the crystal is to filter the noise.

The two variable resistor is to control the dimmer of the light and the speed of the fan and it is connected to the analog I/O port because analog data can receive the voltage between 0v to 5v range. So, the variable resistor is suitable to connect to the analog I/O port because to dim and bright the light and slow and fast the fan. If the voltage is lesser then 5v, the light will be more dim and it depends on the voltage that been receive from variable resistor to the PIC and the PIC will transmit the data to the receiver circuit. Same goes to the variable resistor that control the speed of the fan.

As for the push button, it is simply connect to the digital I/O port because it just function to ON and OFF the radio. The digital I/O port can only receive the 5v and 0v so it is suitable for the push button. And it can connect to which ever pin but make sure that the pin is digital I/O port.

The XBee module need to be connect to the receiver and transmitter port. Because the PIC will transmit and receive the data from that port. It is easy to use XBee because you can directly connect it to the PIC as simple as the circuit above. But, to connect the XBee module to PIC, the pin of receiver at the PIC must be connected to the transmitter of the XBee module and vise versa.

And finally, the all the LED inside this circuit is as the indicator when I construct this circuit. It is because to make sure that the circuit can be function and receive the data.

Friday, March 12, 2010

troubleshoot the circuit





The circuit that I construct have a problem. The signal that are sent to the receiver are not stable. For temporary, I replace the receiver board with the computer. And I need to troubleshoot it.

Friday, March 5, 2010

construct the circuit






this are the process of construct the circuit. I construct the transceiver circuit first. the, when the circuit can work properly, I design the PCB for this circuit.

Wednesday, March 3, 2010

Doing the poster..

Working in completing the poster for the demo day which is at 13th April 2010.. still need to edit a little bit more because my project not really finalize.. and the poster must get approval from my supervisor.. In the poster, you need to have a bit explanation about your project.. It must contains abstract, intoduction, methodology, result, and conclusion.. at the result, atleast there are some picture attached..