This new version of the modified Microchip TCP/IP stack includes now a
separate header file for each development board or reference design
file that defines the particular hardware configuration, options and
initialization values for various registers.
The configuration file must include all the required macro definitions
for the particular drivers for each device such as the Ethernet
controller, LCD display or serial EEPROM memory. If something is
missing you most probably will get an error during compilation time.
The current distribution includes several hardware configuration files
for different development boards or designs and different hardware options.
You can use these files as a reference to build the configuration file
for your specific design.
The main config.h file will select which
hardware configuration file to include in the project based on the
macro previously defined in MPLAB IDE.
All hardware configuration files are located in the general
src/include directory.
The hardware configuration files included in this distribution are:
- eip10.h LJCV Electronics eIP-10 Board
- eip10_lcd.h LJCV Electronics eIP-10 Board + character LCD module
- eip10_spilcd.h LJCV Electronics eIP-10 Board + character LCD module
with SPI interface and MCP23S08 port extender
- exp16_dspic33.h Microchip Explorer 16 Board with dsPIC33FJ256GP710 PIM
and Microchip Ethernet PICTail+
- exp16_pic24h.h Microchip Explorer 16 Board with PIC24HJ256GP610 PIM
and Microchip Ethernet PICTail+
- minipic10t.h Jorge Amodio mini PIC10T reference project
- pic10t.h Jorge Amodio PIC10T reference project
- picdem2.h Microchip PICDEM 2+ (mod) + LJCV Electronics nic28 NIC
- picnet1.h LJCV Electronics PICNet 1 Development Board
- picnet1_spilcd.h LJCV Electronics PICNet 1 Board + character LCD module
with SPI interface and MCP23S08 port extender
All the files above include references about where to obtain additional
information about each board and detailed schematics.
Configuration files for additional boards will be added soon, as well
designs based on the new PIC18F97J60 family of integrated microcontroller
and ethernet controller.
Example description for the PICNet 1 Board with SPI LCD driver hardware
configuration file (picnet1_spilcd.h):
First you must include the appropriate header file for the microcontroller
family.
// Include the appropriate header file for the microcontroller family
#include <p18cxxx.h>
Next you must define the CPU clock frequency in Hertz. Notice that this
is the actual CPU clock and not the frequency of the crystal or
oscillator source used, the value depends on the oscillator configuration
bits and registers. For example if your hardware design uses a PIC18F4620
with a 10MHz crystal or ceramic resonator and you set the HS-PLL the
actual clock frequency will be 40 MHz.
TCY_CLOCK defines the actual instruction
cycle frequency as a function of the CPU clock, for PIC18 devices one
instruction takes four clock cycles to execute then
TCY_CLOCK=CPU_CLOCK/4, on PIC24 and dsPIC33
devices each instruction takes two clock cycles, then
TCY_CLOCK=CPU_CLOCK/2.
These two parameters are use throughout the code to provide delays and
clock configuration for peripherals such as the MSSP for SPI or I2C
communications, the USART module for the RS232 interface, etc.
//************************************************************************
// Define Microcontroller Clock Frequency in Hertz
//
#define CPU_CLOCK (40000000)
#define TCY_CLOCK (CPU_CLOCK/4)
The following section includes for each available Input/Output port,
pin by pin a description of what each pin is used for and its initial
direction and state.
The macros defining initial direction and state will be used by the
initialization routine in the main application to properly set the
direction and initial state of each I/O port.
Below is an example of the definitions for PORTA.
//************************************************************************
// GPIO Ports assignments, configuration and initial default value
// Define the direction for each Input/Output pin (0-Output, 1-Input) and
// the initial state at the application startup
//
// PORTA Direction and initial status
// +-------------- n/a OSC1
// |+------------- n/a OSC2
// ||+------------ RA5 = LED Z
// |||+----------- RA4 = LED Y
// ||||+---------- RA3 = LED X
// |||||+--------- RA2 = MCP23S08 CS
// ||||||+-------- RA1 = n/c
// |||||||+------- RA0 = n/c
#define INIT_TRISA (0b00000000)
#define INIT_PORTA (0b00000100)
There are other registers that may require an initial or configuration
value, such as the configuration of the microcontroller analog features
and input ports.
The next group of macros defines the initial values for such registers.
//************************************************************************
// Initialization values for various registers
//
#define INIT_ADCON0 (0b00000000) // ADON=0, Channel 0
#define INIT_ADCON1 (0b00001111) // No analog inputs
#define INIT_ADCON2 (0b10111110) // Right justify, Fosc/64 (~21.0kHz)
The TCP/IP stack code uses a series of name macros to refer to specific
items such as LEDs, pushbuttons or control signals associated with
I/O ports.
The following group of macros "map" the logic name of the items to the
corresponding I/O port and pin.
//************************************************************************
// Available LEDs and switches macro name definitions for application use
//
#define LED0_IO (PORTAbits.RA3)
#define LED1_IO (PORTAbits.RA4)
#define LED2_IO (PORTAbits.RA5)
#define LED3_IO (PORTAbits.RA5) // No LED3 map to LED2
#define LED4_IO (PORTAbits.RA5) // No LED4 map to LED2
#define LED5_IO (PORTAbits.RA5) // No LED5 map to LED2
#define LED6_IO (PORTAbits.RA5) // No LED6 map to LED2
#define LED7_IO (PORTAbits.RA5) // No LED7 map to LED2
#define BUTTON0_IO (PORTBbits.RB0)
#define BUTTON1_IO (PORTBbits.RB1)
#define BUTTON2_IO (PORTBbits.RB1) // No BUTTON2 map to BUTTON1
#define BUTTON3_IO (PORTBbits.RB1) // No BUTTON3 map to BUTTON1
Each driver module requires specific macros to be defined, which
command the compiler to include the appropriate code and set specific
options.
The next three sections of the file show various macros used to include
the LCD, Ethernet and serial EEPROM drivers and some of their options
and control signal mappings.
//************************************************************************
// LCD Module features and configuration
// For this particular project the PICNet 1 has a character mode LCD
// driven via the SPI interface using a MCP23S08 I/O port extender
//
#define USE_LCD
#define USE_CM_LCD // Include Character Mode LCD Driver
#define LCD_USE_BUFFER // Enable local RAM LCD Buffer
//#define LCD_USE_CGCHARS // Enable Custom Characters support
#define LCD_USE_SPI
#define LCD_4BIT_IFACE
#define LCD_ROWS 2
#define LCD_COLS 16
#define USE_MCP23S08
#define PORTX_CS_IO (LATAbits.LATA2)
#define PORTX_SPI_IF (PIR1bits.SSPIF)
#define PORTX_SSPBUF (SSPBUF)
#define PORTX_SPISTAT (SSPSTAT)
#define PORTX_SPICON1 (SSPCON1)
#define PORTX_ADDRESS (0x00)
#define PORTX_SPICON1_CFG (0x20)
#define PORTX_SPISTAT_CFG (0x40)
//#define PORTX_SAVE_SPI_CFG
//************************************************************************
// Definitions for ENC28J60 Ethernet Controller interface
//
#define USE_ENC28J60
#define ENC_CS_IO (LATBbits.LATB3)
#define ENC_SPI_IF (PIR1bits.SSPIF)
#define ENC_SSPBUF (SSPBUF)
#define ENC_SPISTAT (SSPSTAT)
#define ENC_SPISTATbits (SSPSTATbits)
#define ENC_SPICON1 (SSPCON1)
#define ENC_SPICON1bits (SSPCON1bits)
#define ENC_SPICON1_CFG (0x20) // SPI master, SCK=Fosc/4, idle low
#define ENC_SPISTAT_CFG (0x40) // Tx from active to idle clock
// Rx sample at middle
//************************************************************************
// Definitions for 25LC256 or 25LC1024 Serial EEPROM interface
//
//#define USE_25LC256
#define USE_25LC1024
#define EEPROM_CS_IO (LATBbits.LATB4)
#define EEPROM_SPI_IF (PIR1bits.SSPIF)
#define EEPROM_SSPBUF (SSPBUF)
#define EEPROM_SPICON1 (SSPCON1)
#define EEPROM_SPISTAT (SSPSTAT)
#define EEPROM_SPISTATbits (SSPSTATbits)
#define EEPROM_SPICON1_CFG (0x20)
#define EEPROM_SPISTAT_CFG (0x40)