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.

1 comment:

  1. Which software do you use for interfacing pic microcontroller with zigbee....Please tell me its urgent

    ReplyDelete