# how to send a command from a master uC , help

#### Omerdf

Joined Nov 8, 2020
2
 I'm new to microcontrollers and I am trying to figure out how to send a command from a master uC in order to output a logical '1' at the slave's port pin through ethernet interface. This kind of MicroController (PIC18F97J60) has an internal ethernet interface and doesn't need an external interface. I need some guidance as I am new to it. Is there a simple ethernet tcp/ip code so I can learn from? Or maybe a book that covers that subject? The following code depicts my general idea , The IF condition should perform only if it gets a data with logical '1' through ethernet TCP IP interface from the master and then it should turn high the RA0 pin.
Ethernet command:
//The slave MicroController//
#include <xc.h>
#include <stdio.h>

//Initialize variables funcion:
void init (){
TRISA = 0b00000000; //All A pins are outputs
PORTAbits.RA0 =0; //initializing RA0 to 0

}
//main function:
void main (){
init ();

while(1){
if(...){ //If a logcal '1' received from the master through Ethernet TCP/IP then do this:

PORTAbits.RA0 = 1;//Turn the output pin RA0 on

}
else{ //in any other case , turn the output pin RA0 off
PORTAbits.RA0 =0;

}
}

}

#### geekoftheweek

Joined Oct 6, 2013
692
That's a start. When writing to a port you want to use LATAbits though. Writing to PORTAbits will generally work, but not guaranteed. Use PORT only for reading... LAT for writing.

I haven't messed with these PICs myself, but if you use mplab it may be able to give you a skeleton program to start with. If not mplab will install examples you can start with.

Good luck.

#### Omerdf

Joined Nov 8, 2020
2
The reason i have used PORTA directive is because i have seen it in almost every example that exists .
Thank you for your help !

#### geekoftheweek

Joined Oct 6, 2013
692
The reason i have used PORTA directive is because i have seen it in almost every example that exists .
Thank you for your help !
I'm guessing a lot of that is most examples online (at least when I first started) are based on models that don't have the LATs registers like older 16F and lower parts. Many other types of microcontrollers use PORTs for both reading and writing which may also explain why it seems so common.