OBS.: Não estou usando conector RJ45 com transformador e sim, simplesmente o RJ45 nos pinos 1 e 2 (para transmissao) e 3 e 6 (para recepção).... Estou usando MikroC...
#define Spi_Ethernet_HALFDUPLEX 0
#define Spi_Ethernet_FULLDUPLEX 1
sfr sbit Spi_Ethernet_RST at P1.B0;
sfr sbit Spi_Ethernet_CS at P1.B1;
// Usuario descreve quem esta mandando , para interpretacao futura de mais de um dispositivos
idata unsigned char Informacao[46];
idata unsigned char myMacAddr[6] = {0x00, 0x14, 0xA5, 0x76, 0x19, 0x3f} ; // Endereco MAC dispositivo
idata unsigned char myIpAddr[4] = {192, 168, 1,200} ; // Endereco IP dispositivo
idata unsigned char dyna[28] ;
idata unsigned char remoteHost[4] = {192, 168, 1, 6};
idata unsigned int remotePort = 3456 ; //Porta naqual a informaca sera enviada (lida no PC)
idata unsigned int destPort = 33000 ; //Porta naqual a infor esta sendo enviada
idata unsigned int reqLength = 46; //Tamanho total da informacao
void Montar_inf()
{
Informacao[0] = 'a';
Informacao[1] = 't';
Informacao[2] = 'b';
Informacao[3] = 'b';
Informacao[4] = 'e';
Informacao[5] = 'a';
Informacao[6] = 't';
Informacao[7] = 'b';
Informacao[8] = 'b';
Informacao[9] = 'e';
Informacao[10] = 'a';
Informacao[11] = 't';
Informacao[12] = 'b';
Informacao[13] = 'b';
Informacao[14] = 'e';
Informacao[15] = 'a';
Informacao[16] = 't';
Informacao[17] = 'b';
Informacao[18] = 'b';
Informacao[19] = 'e';
Informacao[20] = 'a';
Informacao[21] = 't';
Informacao[22] = 'b';
Informacao[23] = 'b';
Informacao[24] = 'e';
Informacao[25] = 'a';
Informacao[26] = 't';
Informacao[27] = 'b';
Informacao[28] = 'b';
Informacao[29] = 'e';
Informacao[30] = 'a';
Informacao[31] = 't';
Informacao[32] = 'b';
Informacao[33] = 'b';
Informacao[34] = 'e';
Informacao[35] = 'a';
Informacao[36] = 't';
Informacao[37] = 'b';
Informacao[38] = 'b';
Informacao[39] = 'e';
Informacao[40] = 'a';
Informacao[41] = 't';
Informacao[42] = 'b';
Informacao[43] = 'b';
Informacao[44] = 'e';
Informacao[45] = 'f';
}
//
unsigned int Spi_Ethernet_UserTCP(unsigned char *remoteHost, unsigned int remotePort, unsigned int localPort, unsigned int reqLength)
{
idata unsigned int reqLength2;
idata unsigned char u;
idata unsigned char len;
u=0;
reqLength2 = 0;
reqLength2 = reqLength;
while(reqLength2--)
{
Spi_Ethernet_putByte(toupper(informacao[u])) ;
u++;
}
len = reqLength;
return(len) ;
}
unsigned int Spi_Ethernet_UserUDP(unsigned char *remoteHost, unsigned int remotePort, unsigned int destPort, unsigned int reqLength)
{
unsigned int len ; // Envio de informacao
idata unsigned int reqLength2;
idata unsigned char u;
//Adequacao para envio no modo UDP
byteToStr(remoteHost[0], dyna) ;
dyna[3] = '.' ;
byteToStr(remoteHost[1], dyna + 4) ;
dyna[7] = '.' ;
byteToStr(remoteHost[2], dyna +

dyna[11] = '.' ;
byteToStr(remoteHost[3], dyna + 12) ;
dyna[15] = ':' ;
// Incluindo a porta + destino
intToStr(remotePort, dyna + 16) ;
dyna[20] = '[' ;
intToStr(destPort, dyna + 21) ;
dyna[26] = ']' ;
dyna[27] = 0 ;
len = 27 + reqLength ;
// Colocando a String dentro do buffer
Spi_Ethernet_putBytes(dyna, 27) ;
u=0;
reqLength2 = 0;
reqLength2 = reqLength;
while(reqLength2--)
{
Spi_Ethernet_putByte(toupper(informacao[u])) ;
u++;
}
return(len) ; //Volta a library retornando a quantidade de bytes que deve ser transmitido
}
void main()
{
Spi_Init();
Spi_Ethernet_Init(myMacAddr, myIpAddr,Spi_Ethernet_FULLDUPLEX) ;
while(1)
{
Montar_inf();
Spi_Ethernet_doPacket() ; // Montando pacotes
}
}