RF transmiiter & Receiver control by PIC16f877a

Discussion in 'Embedded Systems and Microcontrollers' started by ibnusabr, Jan 17, 2009.

  1. ibnusabr

    Thread Starter New Member

    Jan 17, 2009
    1
    0
    actually my project want to transmitter the data using RF module (www.cytron.com.my). i will fabricate 2 circuit(a & b). each circuit has RF transmitter, RF receiver,PIC16F877a, LCD display. after done the fabrication, the circuit a cannot send the data to the circuit b and vice versa. plZZ help me check this program..

    void ePulse ( void );
    void LCDInit ( void );
    void LCDAdd ( unsigned char );
    void LCDWrite ( unsigned char );
    void LCDStr ( unsigned char * );
    void LCDClr ( void );
    void LCDAdd ( unsigned char );
    void Usart_Write(unsigned short data);
    void usart(void);
    void Usart_Init(const unsigned long baud_rate);
    unsigned short Usart_Read(void);
    unsigned short Usart_Data_Ready(void);
    unsigned char msg_welcome0 [17] = "NEIGHBORHOOD";
    unsigned char msg_welcome1 [17] = "WARNING SYSTEM";
    unsigned char msg_0 [17] = "HOME A NEED HELP";
    unsigned char msg_1 [17] = "HOME B NEED HELP";
    unsigned char msg_2 [17] = "HOME C NEED HELP";
    unsigned char msg_3 [17] = "HOME D NEED HELP";
    unsigned short Button(unsigned short *port, unsigned short pin, unsigned short time,
    unsigned short active_state);
    unsigned char oldstate;
    int num;
    int main (void)
    {
    Delay_ms(1000);
    TRISB=0x0F;
    PORTB=0x00;
    TRISC = 0b10000000;
    PORTC = 0b10000000;
    LCDInit ();
    LCDClr ();
    LCDAdd ( 0x0 );
    LCDStr ( msg_welcome0 );
    LCDAdd ( 0x40 );
    LCDStr ( msg_welcome1 );
    PORTB=0x0f;
    Usart_Init(1200);
    do {
    if (Button(&PORTB, 0, 1, 1)) oldstate = 1;

    if (oldstate && Button(&PORTB, 0, 1, 0)) {
    num = 1;
    Usart_Write(num);
    LCDClr ();
    LCDAdd ( 0 );
    LCDStr ( msg_0 ); //LCD display "HOME A NEED HELP"
    oldstate = 0;
    PORTC = 0b10000001;
    if (Usart_Data_Ready()) { // If data is received
    num = Usart_Read(); // Read the received data
    if ((num==1) || (num==2)||(num==3)||(num==4)) ;
    {
    if (num==1)
    {
    LCDClr ();
    LCDAdd ( 0 );
    LCDStr ( msg_0 ); //LCD display " HOME A NEED HELP "
    PORTC = 0b10000001;
    }
    else if(num==2)
    {
    LCDClr ();
    LCDAdd ( 0 );
    LCDStr ( msg_1 ); //LCD display " HOME B NEED HELP’’
    PORTC = 0b10000001 ;
    }
    else if(num==3)
    {
    LCDClr ();
    LCDAdd ( 0 );
    LCDStr ( msg_2 ); //LCD display " HOME C NEED HELP "
    PORTC = 0b10000001;
    }
    else if (num==4)
    {
    LCDClr ();
    LCDAdd ( 0 );
    LCDStr ( msg_3 ); //LCD display " HOME D NEED HELP "
    PORTC = 0b10000001;
    }
    else
    PORTC = 0b10000001;
    }
    }
    }
    else if(Button(&PORTB, 1, 1, 1)) oldstate = 1;
    if (oldstate && Button(&PORTB, 1, 1, 0)) {
    num = 0x02;

    Usart_Write(num);
    LCDClr ();
    LCDAdd ( 0 );
    LCDStr ( msg_1 ); //LCD display " HOME B NEED HELP "
    oldstate = 0;
    PORTC = 0b10000001;
    if (Usart_Data_Ready()) { // If data is received
    num = Usart_Read();
    PORTC = 0b10000001;
    // Read the received data
    if ((num==1) || (num==2)||(num==3)||(num==4)) ;
    {
    if (num==1)
    {
    LCDClr ();
    LCDAdd ( 0 );
    LCDStr ( msg_0 ); //LCD display " HOME A NEED HELP "
    PORTC = 0b10000001;
    }
    else if(num==2)
    {
    LCDClr ();
    LCDAdd ( 0 );
    LCDStr ( msg_1 ); //LCD display " HOME B NEED HELP’’
    PORTC = 0b10000001 ;
    }
    else if(num==3)
    {
    LCDClr ();
    LCDAdd ( 0 );
    LCDStr ( msg_2 ); //LCD display " HOME C NEED HELP "
    PORTC = 0b10000001;
    }
    else if (num==4)
    {
    LCDClr ();
    LCDAdd ( 0 );
    LCDStr ( msg_3 ); //LCD display " HOME D NEED HELP "
    PORTC = 0b10000001;
    }
    else
    PORTC = 0b10000001;
    }
    }
    }
    else if(Button(&PORTB, 2, 1, 1)) oldstate = 1;
    if (oldstate && Button(&PORTB, 2, 1, 0)) {
    num = 3;

    Usart_Write(num);
    LCDClr ();
    LCDAdd ( 0 );
    LCDStr ( msg_2 ); //LCD display " HOME C NEED HELP "
    oldstate = 0;
    PORTC = 0b10000001;
    if (Usart_Data_Ready()) { // If data is received
    num = Usart_Read();
    PORTC = 0b10000001;
    // Read the received data
    if ((num==1) || (num==2)||(num==3)||(num==4)) ;
    {
    if (num==1)
    {
    LCDClr ();
    LCDAdd ( 0 );
    LCDStr ( msg_0 ); //LCD display " HOME A NEED HELP "
    PORTC = 0b10000001;
    }
    else if(num==2)
    {
    LCDClr ();
    LCDAdd ( 0 );
    LCDStr ( msg_1 ); //LCD display " HOME B NEED HELP’’
    PORTC = 0b10000001 ;
    }
    else if(num==3)
    {
    LCDClr ();
    LCDAdd ( 0 );
    LCDStr ( msg_2 ); //LCD display " HOME C NEED HELP "
    PORTC = 0b10000001;
    }
    else if (num==4)
    {
    LCDClr ();
    LCDAdd ( 0 );
    LCDStr ( msg_3 ); //LCD display " HOME D NEED HELP "
    PORTC = 0b10000001;
    }
    else
    PORTC = 0b10000001;
    }
    }
    }
    else if(Button(&PORTB, 3, 1, 1)) oldstate = 1;
    if (oldstate && Button(&PORTB, 3, 1, 0)) {
    num = 4;
    Usart_Write(num);
    LCDClr ();

    LCDAdd ( 0 );
    LCDStr ( msg_3 ); //LCD display "keadaan bahaya"
    oldstate = 0;
    PORTC = 0b10000001;
    if (Usart_Data_Ready()) { // If data is received
    num = Usart_Read();
    PORTC = 0b10000001;
    // Read the received data
    if ((num==1) || (num==2)||(num==3)||(num==4)) ;
    {
    if (num==1)
    {
    LCDClr ();
    LCDAdd ( 0 );
    LCDStr ( msg_0 ); //LCD display " HOME A NEED HELP "
    PORTC = 0b10000001;
    }
    else if(num==2)
    {
    LCDClr ();
    LCDAdd ( 0 );
    LCDStr ( msg_1 ); //LCD display " HOME B NEED HELP’’
    PORTC = 0b10000001 ;
    }
    else if(num==3)
    {
    LCDClr ();
    LCDAdd ( 0 );
    LCDStr ( msg_2 ); //LCD display " HOME C NEED HELP "
    PORTC = 0b10000001;
    }
    else if (num==4)
    {
    LCDClr ();
    LCDAdd ( 0 );
    LCDStr ( msg_3 ); //LCD display " HOME D NEED HELP "
    PORTC = 0b10000001;
    }
    else
    PORTC = 0b10000001;
    }
    }
    }
    }
    while (1);
    }
    // LCD CONFIGURATION
    void ePulse ( void )
    {
    PORTE |= 0x2;

    Delay_Cyc(1);
    Delay_Cyc(1);
    Delay_Cyc(1);
    PORTE &= 0xfd;
    Delay_Cyc(1);
    Delay_Cyc(1);
    Delay_Cyc(1);
    }
    void LCDInit ( void )
    {
    ADCON1 = 0xe;
    PORTD = 0;
    TRISD = 0;
    PORTE = 0;
    TRISE = 0;
    PORTD = 0x38;
    ePulse ();
    Delay_us(40);
    PORTD = 0x0c;
    ePulse ();
    Delay_us(40);
    }
    void LCDWrite ( unsigned char data )
    {
    PORTE |= 0x1;
    PORTD = data;
    ePulse ();
    Delay_us(40);
    PORTE &= 0xfe;
    }
    void LCDStr ( unsigned char * data )
    {
    unsigned char num = 0;
    while ( data [ num ] )
    {
    LCDWrite ( data [ num ] );
    num++;
    }
    }
    void LCDClr ( void )
    {
    PORTD = 0x1;
    ePulse ();
    Delay_ms(2);
    }

    void LCDAdd ( unsigned char data )
    {
    PORTD = 0x80 + data;
    ePulse ();
    Delay_us(40);
    }



    plZZZ help meeee...
     
Loading...