0
votes

I want to send a command by PIC12F1572 to another PIC12F1572 through UART and in that I want to send a function which will blink the LED on the slave PIC. I have done some code but I am somewhat confusing can anyone help me here? P.S- I am Using MPLAB X IDE v3.50

Master/Transmitter PIC12F1572:

    #include <xc.h>
    #include "main.h"
    #include "config.h"
    #include "TYPEDEF_Definitions.h"
    #include "PIC_12_Timer0.h"
    #include "PIC_12_UART.h"
    #include "System_init.h"
    #include "Pin_manager.h"
    #include "LED.h"

    #define _XTAL_FREQ 16000000
void main()
{   
    SYSTEM_Initialize();
    //pin_config();
    LATA = 0x00;  
    UART_Init();                  //Initialize UART
  // StartLedBlinkingWithColor(color);

    TRISAbits.TRISA2  = 1; //make RA2 as input

    while (1)
    {   
      //LATAbits.LATA2 = 1;
      uint8_t Var = 0x61;
       //uint8_t Var = LATAbits.LATA2;

        if(TXSTAbits.TRMT == 1)
            {

                  UART_write(LED_Blink()); // is it possible?? or how it will be possible

                 // __delay_ms(1000);
            }

       LATAbits.LATA2 = 1;


    }
}

void LED_Blink()
{
       LATAbits.LATA2   = 1; 
       LATAbits.LATA5   = 1; 

       __delay_ms(1000);


       LATAbits.LATA2   = 0; 
       LATAbits.LATA5   = 0;


}

RECEIVER/SLAVE PIC12F1572:

#include <xc.h>
#include "config.h"
#include "PIC_12F_GPIO.h"
#include "Led.h"
#include "Interruptmanage.h"
#include "PIC_12F_UART.h"
#include "PIC_12F_TIMER0.h"
#include "main.h"

void main( void)
{
    uint8 data;   

    InterruptInit();
    TIMER0_Init();
    UART_Init();
    InitLeds(); // here I init GPIO pin..no prb here

    // SetLedOff();

    /*-------------R E C E I V E R*------------*/
    while (1) 
    {   // Endless loop

        if (UART_DataReady() )     // I get prob here ..
        { 
          PORTA = UART_ReadOneByte(); // read the received data, [how can I receive my Led_Blink() function??
          LATAbits.LATA2   = 1;      
          //LATAbits.LATA2 = data;

          //SendByteSerially(data);
        }
     }
}
2
This looks like it could be an interesting question, but it is currently unclear what specifically you are asking. What did you expect, and how is your code working differently? Have a look at the How to Ask page for some guidance.FriendFX
okay.now I want to send a led_blink() function through UART so that this function will blink the LEDs on other PIC..in short I want to control the Blinking of LEDs..I edit the the above code :)Garryp

2 Answers

1
votes

There are a couple of things to consider:

  • You cannot "send a function" through the UART. Therefore, the LED_Blink() function needs to be on the receiver side. Before doing anything else, verify that the function works on the receiver side, without any UART interaction.
  • Next, you can define a protocol, which is basically deciding which byte values you send through the UART should trigger the LED_Blink() call on the receiver side. For example, if you decide to use the byte value of 42 to trigger a LED blink, your sender would call UART_write(42) and on the receiver side, you would have something like the following:

    data = UART_ReadOneByte();
    if (data == 42) {
        LED_Blink();
    }
    
0
votes

So for Receiving data from UART and saving it in array and use the data to vlink nthe LED I Have done this code: Anyone interested can have a look

 while (1)
 {

        if (EUSART_DataReady)
        {
            for (i = 0; i<FRAMESIZE; i++)   //#define FRAMESIZE 19
            {
                RX_Buffer[i] = EUSART_Read();
                if (RX_Buffer[i] == '\n')        //check'\n' in the end of frame
                   break;
            }

            RX_Buffer[i] = '\n';                        //append '\n' at the end of stoaring array for detection of frame
            RX_Buffer[i+1] = '\0';                      // End of an array
            EUSART_WriteAnArrayOfBytes(RX_Buffer);


        if(RX_Buffer[0]=='R' && RX_Buffer[FRAMESIZE-2] == '\n')   //check for correct frame
          {

            LATAbits.LATA2 = 1;
            __delay_ms(2000);
            LATAbits.LATA2 = 0;
            __delay_ms(1000);
          }
        }

  }