Duplex Config Flags
Duplex Config Flags
#include "__NetEthEnc28j60.h"
// Prototypes
float getTempKimo(char channel);
float getHygroKimo(char channel);
int led0Status = 0;
int led1Status = 0;
char send = 0;
char secondes = 0;
char nb200ms = 0;
SOCKET_28j60_Dsc *socket_global;
// Data to send
char dat[taillePacket];
unsigned int dat_pos = 0;
/***********************************
* RAM variables
*/
unsigned char myMacAddr[6] = "ENC28" ; // my
MAC address
unsigned char myIpAddr[4] = {0,0,0,0} ; // my
IP address
unsigned char gwIpAddr[4] = {192,168,1,254};
// gateway (router) IP address
unsigned char ipMask[4] = {255,255,255,0};
// network mask (for example : 255.255.255.0)
unsigned char dnsIpAddr[4] = {192,168,1,254};
// DNS server IP address
LATD.f1 = 1;
//memcpy(remoteHostIpAddr, Net_Ethernet_28j60_dnsResolve(server, 5), 4);
// the total length of the request is the length of the dynamic string plus
the text of the request
len = 28 + udpDsc->dataLength;
// then puts the request string converted into upper char into the transmit
buffer
while(udpDsc->dataLength--)
{
Net_Ethernet_28j60_putByte(toupper(Net_Ethernet_28j60_getByte()));
}
return(len);
}
nb200ms++;
if (nb200ms%5 == 0)
{
nb200ms = 0;
Net_Ethernet_28j60_UserTimerSec ++;
secondes++;
}
if (secondes%10 == 0)
{
secondes = 0;
send = 1;
}
if(led0Status == 0)
{
LATD.f0 = 0;
}
else if(led0Status == 1)
{
LATD.f0 = 1;
}
else if(led0Status == 2)
{
LATD.f0 = !LATD.f0;
}
INTCON.T0IF = 0;
}
}
void main()
{
char useDHCP = 0;
int i = 0;
ADCON1 = 0;
ANCON0 = 0x0f;
PORTA = 0 ;
TRISA = 0xff ; // set PORTA as input for ADC
PORTB = 0 ;
TRISB = 0xff ; // set PORTB as input for buttons
LATD = 0 ;
TRISD = 0 ; // set PORTD as output
INTCON.GIE = 1;
T0CON = 0b10000110;
TMR0H = TMR0_PRE / 256;
TMR0L = TMR0_PRE % 256;
INTCON.T0IE = 1;
LATD.f1 = 1;
Net_Ethernet_28j60_stackInitTCP();
SPI1_Init();
SPI_Rd_Ptr = SPI1_Read;
Net_Ethernet_28j60_Init(myMacAddr, myIpAddr,
Spi_Ethernet_FULLDUPLEX) ;
if(Net_Ethernet_28j60_getIpAddress()[0] == 0) useDHCP = 1;
LATD.f1 = 0;
led0Status = 2;
if(useDHCP == 1)
{
while(Net_Ethernet_28j60_initDHCP(10) == 0) // try to get one from
DHCP until it works
{
Net_Ethernet_28j60_Init(myMacAddr, myIpAddr,
Spi_Ethernet_FULLDUPLEX);
//Net_Ethernet_28j60_Init(myMacAddr, myIpAddr,
Spi_Ethernet_HALFDUPLEX) ;
}
memcpy(myIpAddr, Net_Ethernet_28j60_getIpAddress(), 4) ; //
get assigned IP address
memcpy(ipMask, Net_Ethernet_28j60_getIpMask(), 4) ; //
get assigned IP mask
memcpy(gwIpAddr, Net_Ethernet_28j60_getGwIpAddress(), 4) ; //
get assigned gateway IP address
memcpy(dnsIpAddr, Net_Ethernet_28j60_getDnsIpAddress(), 4) ; //
get assigned dns IP address
}
else
{
Net_Ethernet_28j60_confNetwork(ipMask, gwIpAddr, dnsIpAddr) ; //
use configured IP address
}
led0Status = 1;
while(1)
{
/*
* if necessary, test the return value to get error code
*/
if (send == 1)
{
sendData();
}
}
}