User manual

Table Of Contents
464
mikoC PRO for PIC32
MikroElektronika
/*
* main entry
*/
void main()
{
CHECON = 0x32;
AD1PCFG |= 0xFFFC; // all digital but rb0(AN0) and rb1(AN1)
PORTB = 0;
TRISB = 0xFFFF; // set PORTB as input for buttons and adc
PORTD = 0;
TRISD = 0; // set PORTD as output,
ADC1_Init(); // Enable ADC module
/*
* starts ENC28J60 with :
* reset bit on RC0
* CS bit on RC1
* my MAC & IP address
* full duplex
*/
// SPI1_Init(); // init SPI communication with ethernet board
SPI2_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, 16,
_SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW,
_SPI_IDLE_2_ACTIVE);
SPI_Ethernet_Init(myMacAddr, myIpAddr, Spi_Ethernet_FULLDUPLEX); // init ethernet
board
// dhcp will not be used here, so use precongured addresses
SPI_Ethernet_confNetwork(ipMask, gwIpAddr, dnsIpAddr);
while(1) // do forever
{
/*
* if necessary, test the return value to get error code
*/
SPI_Ethernet_doPacket(); // process incoming Ethernet packets
/*
* add your stuff here if needed
* Spi_Ethernet_doPacket() must be called as often as possible
* otherwise packets could be lost
*/
}