A personal repository of random information in compensation for a fatigued biological computer
I will make use of the on hand PICDEM Net board to verify that some of my settings are correct (ie enabling ENC28J60) before moving to the new board. (PICDEM Net 2 was previously running TCPIP Stack version 4.13
PICKIT 2 installed & connected
PICDEM NET 2 connected to PICKIT 2 & connected to network (with DHCP server available) via J1
1. Installed Microchip MPLab IDE 8.15
2. Installed Microchip C18 Student Version 3.22
3. Installed Microchip TCPIP Stack 4.51
Following 'Getting Started' in the help files provided with TCPIP 4.51:
4. Ran the Microchip Config Wizard and left the board name as MCHPBoard, set the NIC address per the sticker on the bottom. Note this updates TCPIPConfig.h and leaves a copy of the original as TCPIPConfig.dist
5. In MPLab IDE: opened C:\Microchip Solutions\TCPIP Demo App\TCPIP Demo App-C18 project and did a Project -> Build All
6. In MPLab IDE: Programmer -> Select Programmer -> PicKit 2
7. In MPLAB IDE: Programmer -> Program
8. Hold Down Button 0 (RB3) on PICDEM Net 2 and power on/off to clear EEPROM settings
9. PICDEM Net 2 should pick up TCPIP address and display it on the LCD..
10 In a browser goto 192.168.1.14/mpfsupload (where 192.. etc matches the LCD displayed IP address) and navigate to C:\Microchip Solutions\TCPIP Demo App and select MPFSImg2.bin and Upload..
Set to use ENC28J60
Set MPLab to use PIC18F4610
Set pin assignments to match our target PIC18F4610
Remove not required modules so we can get it to fit in our target processor
In MPLab IDE (assumes C:\Microchip Solutions\TCPIP Demo App\TCPIP Demo App-C18 project is still open)
- Edit C:\Microchip Solutions\TCPIP Demo App\hardwareprofile.h (It shows in the Project files list (Menu VIEW->PROJECT) under header files, double click to edit it)
- Search for and uncomment the 2 x lines with this text (as a comment on the commented lines :) "Uncomment this line if you wish to use the ENC28J60.. on the PICDEM Net 2.." (not we actually only need to do it for the Non Hitech C section but its easier to just find both)
- Save and Close hardwareprofile.h
- Do a Build and program the PICDEM Net 2 as earlier, move the Ethernet connector to J2 and start it up.
In MPLab IDE (assumes C:\Microchip Solutions\TCPIP Demo App\TCPIP Demo App-C18 project is still open)
- Configure -> Select Device: PIC18F4610
- Edit hardwareprofile.h
At the top of the file, uncomment the line: "#define YOUR_BOARD"
In the '// Set configuration fuses (but only once)' section ( we may come back here to change our config fuses as necessary later..):
Note that I also added in PIC18F4682 & PIC18F4685 as we have these on hand as well in case we need more rom..
Copy and paste this | below it as this |
#elif defined(__18F4620) // PICDEM Z board #pragma config OSC=HSPLL, WDT=OFF, MCLRE=ON, PBADEN=OFF, LVP=OFF | #elif defined(__18F4620 ) || defined(__18F4610 ) || defined(__18F4682 ) || defined(__18F4685 ) // My Board #pragma config OSC=HSPLL, WDT=OFF, MCLRE=ON, PBADEN=OFF, LVP=OFF |
Copy and paste this below it as this #elif defined(PICDEMZ)
#define GetSystemClock() (16000000ul) // Hz
#define GetInstructionClock() (GetSystemClock()/4)
#define GetPeripheralClock() GetInstructionClock()#elif defined(YOUR_BOARD)
#define GetSystemClock() (40000000ul) // Hz
#define GetInstructionClock() (GetSystemClock()/4)
#define GetPeripheralClock() GetInstructionClock()
Pin assignments:
Note1: The default application assumes certain other connections based on the PICDEM Net 2 board:
Temperature sensor on RA3
Potentiometer on RA2
We wont be using these but the default application still assumes they are there. If we want to use these pins in the future we will have to remove the associated code as well.
PICDEM Net 2 Module | PICDEM Net 2 Connection | Pin Count | PlugNProg Module | PlugNProg Connection | Pin Count |
4 x Tact | RB0-3 | 4 | 4 x Tact | RB4-7 | 4 |
Analogue Temp Sensor | RA3 | 1 | |||
Potentiometer | RA2 | 1 | |||
8 x LEDS | RJ0-7 | 8 | 1 4LED | RB0-3 | 4 |
RS232 | RC6-7 | 2 | |||
LCD Data (D0-7) | RE0-7 | 8 | JM162B LCD D4-7 | RD0-3 | 4 |
LCD E | RH0 | 1 | JM162B LCD Control - (Pin 3) - E | RE2 | 1 |
LCD R/W | RH1 | 1 | JM162B LCD Control - (Pin 2) - R/W | RE1 | 1 |
LCD RS | RH2 | 1 | JM162B LCD Control (Pin 1) - RS | RE0 | 1 |
SPI SCK | RC3 | 1 | SPI Breakout SPI In | RC3 | 1 |
SPI SDI | RC4 | 1 | SPI Breakout SPI In | RC4 | 1 |
SPI SDO | RC5 | 1 | SPI Breakout SPI In | RC5 | 1 |
ENC28J60 Chip Select | RD3 | 1 | SPI Breakout Select (SPI Out 1) | RA4 | 1 |
25LC256 EEPROM Chip Select | RD7 | 1 | SPI Breakout Select (SPI Out 2) | RA5 | 1 |
Total Pins: | 32 | Total Pins: | 20 |
In MPLab IDE (assumes C:\Microchip Solutions\TCPIP Demo App\TCPIP Demo App-C18 project is still open)
- Edit hardwareprofile.h
In the '// Hardware mappings' section:
We will copy the PICDEM Net 2 settings as our starting point. Find '#elif defined(PICDEMNET2) && !defined(HI_TECH_C)' and copy that set of declarations to the '// Define your own board hardware profile here' section.
Now we edit each set of pins to change the mappings per our own board per the pin assignments table above..:
Change this | to this | Note |
// I/O pins #define LED0_TRIS (TRISJbits.TRISJ0) #define LED0_IO (LATJbits.LATJ0) #define LED1_TRIS (TRISJbits.TRISJ1) #define LED1_IO (LATJbits.LATJ1) #define LED2_TRIS (TRISJbits.TRISJ2) #define LED2_IO (LATJbits.LATJ2) #define LED3_TRIS (TRISJbits.TRISJ3) #define LED3_IO (LATJbits.LATJ3) #define LED4_TRIS (TRISJbits.TRISJ4) #define LED4_IO (LATJbits.LATJ4) #define LED5_TRIS (TRISJbits.TRISJ5) #define LED5_IO (LATJbits.LATJ5) #define LED6_TRIS (TRISJbits.TRISJ6) #define LED6_IO (LATJbits.LATJ6) #define LED7_TRIS (TRISJbits.TRISJ7) #define LED7_IO (LATJbits.LATJ7) #define LED_GET() (LATJ) #define LED_PUT(a) (LATJ = (a)) | // I/O pins #define LED0_TRIS (TRISBbits.TRISB0) #define LED0_IO (LATBbits.LATB0) #define LED1_TRIS (TRISBbits.TRISB1) #define LED1_IO (LATBbits.LATB1) #define LED2_TRIS (TRISBbits.TRISB2) #define LED2_IO (LATBbits.LATB2) #define LED3_TRIS (TRISBbits.TRISB3) #define LED3_IO (LATBbits.LATB3) #define LED4_TRIS (TRISBbits.TRISB4) // No LED4 #define LED4_IO (LATBbits.LATB4) #define LED5_TRIS (TRISBbits.TRISB5) // No LED5 #define LED5_IO (LATBbits.LATB5) #define LED6_TRIS (TRISBbits.TRISB6) // No LED6 #define LED6_IO (LATBbits.LATB6) #define LED7_TRIS (TRISBbits.TRISB7) // No LED7 #define LED7_IO (LATBbits.LATB7) #define LED_GET() ((LED3_IO<<3) | (LED2_IO<<2) | (LED1_IO<<1) | LED0_IO) #define LED_PUT(a) do{BYTE vTemp = (a); LED0_IO = vTemp&0x1; LED1_IO = vTemp&0x2; LED2_IO = vTemp&0x4; LED3_IO = vTemp&0x8;} while(0) | Change all J port assignments to B.. no Leds 4-7 so dummy these (is that what PRODL does?) |
#define BUTTON0_TRIS (TRISBbits.TRISB3) #define BUTTON0_IO (PORTBbits.RB3) #define BUTTON1_TRIS (TRISBbits.TRISB2) #define BUTTON1_IO (PORTBbits.RB2) #define BUTTON2_TRIS (TRISBbits.TRISB1) #define BUTTON2_IO (PORTBbits.RB1) #define BUTTON3_TRIS (TRISBbits.TRISB0) #define BUTTON3_IO (PORTBbits.RB0) | #define BUTTON0_TRIS (TRISDbits.TRISD4) #define BUTTON0_IO (PORTDbits.RD4) #define BUTTON1_TRIS (TRISDbits.TRISD5) #define BUTTON1_IO (PORTDbits.RD5) #define BUTTON2_TRIS (TRISDbits.TRISD6) #define BUTTON2_IO (PORTDbits.RD6) #define BUTTON3_TRIS (TRISDbits.TRISD7) #define BUTTON3_IO (PORTDbits.RD7) | B0-3 to B7-4 (reversed ordering as well) |
Change this | to this | Note |
// ENC28J60 I/O pins | // ENC28J60 I/O pins | |
// 25LC256 I/O pins
| // 25LC256 I/O pins | |
// LCD I/O pins | // LCD I/O pins #define LCD_RD_WR_TRIS (TRISEbits.TRISE1) |
LCD into 4 bit mode.. edit LCDBlocking.c to turn on 4 bit mode, and also fix the bug..
From | To |
//#define FOUR_BIT_MODE | #define FOUR_BIT_MODE |
LCD_DATA0_IO = Data & 0x10; | LCD_DATA0_IO = ((Data & 0x10) == 0x10); |
Ok, now doing a Project -> Build All and it fails on space, changing back to the PICDEM Net 2 and after another Project -> Build All we can check the space required is 55296, and the poor PIC18F4610 only has room for 32k instructions, heck even the PIC18F4685 only has room for 48k instructions.
So time to remove some modules..
In MPLab IDE, edit tcpipconfig.h:
Overall module in/out settings are in the '// Application Options' section:
My bare minimum | |
//#define STACK_USE_UART // Application demo using UART for IP address display and stack configuration |
Note that disabling some items breaks dependancies, such as the Email demo needs HTTP2 & SMTP client modules installed, so to get the project to compile we need to change additional settings further on in the '// Application-Specific Options' section:
// Define which HTTP modules to use #define STACK_USE_HTTP_APP_RECONFIG // Use the AppConfig web page in the Demo App (~2.5kb ROM, ~0b RAM) | // Define which HTTP modules to use #define STACK_USE_HTTP_APP_RECONFIG // Use the AppConfig web page in the Demo App (~2.5kb ROM, ~0b RAM) |
Since we removed all DHCP modules, we will hardcode the IP addresses under the section: '// Network Addressing Options':
Note this will require an EEPROM reset of the board (Hold down button 0 whilst powering up for 4 seconds)
From | To |
#define MY_DEFAULT_IP_ADDR_BYTE1 (169ul) #define MY_DEFAULT_MASK_BYTE1 (255ul) #define MY_DEFAULT_GATE_BYTE1 (169ul) #define MY_DEFAULT_PRIMARY_DNS_BYTE1 (169ul) #define MY_DEFAULT_SECONDARY_DNS_BYTE1 (169ul) | #define MY_DEFAULT_IP_ADDR_BYTE1 (192ul) #define MY_DEFAULT_MASK_BYTE1 (255ul) #define MY_DEFAULT_GATE_BYTE1 (192ul) #define MY_DEFAULT_PRIMARY_DNS_BYTE1 (192ul) #define MY_DEFAULT_SECONDARY_DNS_BYTE1 (192ul) |