motion sensor with transeiver

Status
Not open for further replies.

aadebola5

Newbie level 4
Joined
Aug 12, 2013
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
87
pls i need help with this C code program for a wireless transceiver, the program is to send data received by transmitter to d receiver when a motion is detected (when a motion is detected the pin it is connected to turns low), then the transmitter pin turns high and send information to d receiver. please i need assistance the code is givin me errors.am working with rf 315Mhz transceiver..

transmitter section...


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//all these # below set up the PIC
#include <16F877A.h>
 
#FUSES NOWDT      //No Watch Dog Timer
#FUSES HS         //Highspeed Osc > 4mhz
#FUSES PUT        //Power Up Timer
#FUSES NOPROTECT  //Code not protected from reading
#FUSES NODEBUG    //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP      //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD      //No EE protection
#use delay(clock=20000000)              // Sets crystal oscillator at 20 megahertz
#use rs232(baud=4800, xmit=PIN_C6, rcv=PIN_C7) //Sets up serial port output pin & baud rate
#define PIR_SENSOR PIN_A0
#define TRS PIN_C6
#define sw PIN_A1
 
 
 
void uart_send(unsigned char data);
 
 
void main()
{
   BRGH = 0;
   SPBRG = 255;
   TX9 = 0;
   TXEN = 1;
   SYNC = 0;
   SPEN = 1;
 
  set_tris_a(0xff);
  set_tris_c(0x00);
 
 
   setup_adc_ports(AN0);
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
 
   while(true)
   {  set_adc_channel(0);
      delay_us(20);
 
 
      if(PIR_SENSOR==0 && sw==0){
      output_high(PIN_C6);
      }
      else{
         output_low(PIN_C6);
      }
 
 
}
}
 
void uart_send(unsigned char data)
{
   while(TXIF==0);
         TXREG=data;
}



Receiver section..



Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//all these # below set up the PIC
#include <16F877A.h>
 
#FUSES NOWDT      //No Watch Dog Timer
#FUSES HS         //Highspeed Osc > 4mhz
#FUSES PUT        //Power Up Timer
#FUSES NOPROTECT  //Code not protected from reading
#FUSES NODEBUG    //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP      //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD      //No EE protection
#use delay(clock=20000000)              // Sets crystal oscillator at 20 megahertz
#use rs232(baud=4800, xmit=PIN_C6, rcv=PIN_C7) //Sets up serial port output pin & baud rate
#define RCV PIN_C7
#define RED_LED PIN_B7
 
 
void uart_rec(void);
 
 
void main()
{
   BRGH = 0;
   SPBRG = 255;
   SPEN = 1;
   RX9 = 0;
   CREN = 1;
   
   set_tris_c(0xff);
  set_tris_b(0x00);
   
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   
    while(true)
   {  set_adc_channel(0);
      delay_us(20);
 
 
      if(RCV==0){
      output_high(PIN_B7);
      }
      else{
         output_low(PIN_B7);
      }
 
}
 
unsigned char uart_rec(void) {
 
         unsigned char rec_data;
         while (RCIF==0);
         rec_data = RCREG;
         return rec_data;
}

 
Last edited by a moderator:

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…