Hellow Everyone! I have a somethig like that. The thing is that, I am trying ping test between pc and pic. I am using 18f458, enc28j60-h from olimex and mikroc compilers. I am trying simulate on proteus but doesn't works, even the proteus examples, so I tested the circuit on the protoboard and I can't do it work. This is the code:
#include "__EthEnc28j60.h"
#include "__EthEnc28j60private.h"
// duplex config flags
#define Spi_Ethernet_HALFDUPLEX 0x00 // half duplex
#define Spi_Ethernet_FULLDUPLEX 0x01 // full duplex
// mE ehternet NIC pinout
sfr sbit SPI_Ethernet_Rst at LATC0_bit; // for writing to output pin always use latch (PIC18 family)
sfr sbit SPI_Ethernet_CS at LATC1_bit; // for writing to output pin always use latch (PIC18 family)
sfr sbit SPI_Ethernet_Rst_Direction at TRISC0_bit;
sfr sbit SPI_Ethernet_CS_Direction at TRISC1_bit;
// end ethernet NIC definitions
// network parameters
unsigned char myMacAddr[6] = {0x4D, 0x14, 0xA5, 0x76, 0x19, 0x3f} ; // my MAC address
unsigned char myIpAddr[4] = {192, 168, 10, 60} ; // my IP address
unsigned char myMaskAddr[4] = {255,255,255,0};
//#define putConstString SPI_Ethernet_putConstString
//#define putString SPI_Ethernet_putString
unsigned int SPI_Ethernet_UserTCP(unsigned char *remoteHost, unsigned int remotePort, unsigned int localPort, unsigned int reqLength, TEthPktFlags *flags)
{
return 0;
}
unsigned int SPI_Ethernet_UserUDP(unsigned char *remoteHost, unsigned int remotePort, unsigned int destPort, unsigned int reqLength, TEthPktFlags *flags)
{
return 0; // back to the library with the length of the UDP reply
}
void main()
{
TRISD.F0=0;
TRISD.F1=0;
adcon0=0;
adcon1=15;
cmcon=0x07;
portd=0;
// starts ENC28J60 with: reset bit on PORTC.F0, CS bit on PORTC.F1,
// my MAC & IP address, full duplex
SPI1_Init();
SPI_Ethernet_Init(myMacAddr, myIpAddr, Spi_Ethernet_FULLDUPLEX);
while(1) { // do forever
SPI_Ethernet_doPacket(); // process incoming Ethernet packets
if (portd.f0==1)
portd.f0=0;
else
portd.f0=1;
delay_ms(100);
portd.f1=1;
}
}