Forum: µC & Digital Electronics Ethernet with PIC18F67J60

von Pasjul (Guest)

Rate this post
0 useful
not useful
Hey guys,

im having trouble with my PIC18F67J60 µC. Im trying to send an 
ethernetpacket every second or so. To record any packets on the ethernet 
im using wireshark, i pluged the network cable from the develpment board 
directly into my computer. I just get some DHCP-discover packets from my 
computer but no packets from the PIC18 at all! I read the documentation 
4times already and my resulting code looks like this:
#include <xc.h>                 // XC8 General Include File 
#include <stdint.h>             // For uint8_t definition 
#include <stdbool.h>            // For true/false definition 

#pragma config WDT = OFF        // WDT disabled (control is placed on SWDTEN bit) 
#pragma config XINST = OFF      // Turn off support for extended instruction set 
#pragma config FOSC = HS        // HS oscillator 

unsigned int counter1 = 0; 
int x = 0; 
unsigned char packetDest [6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // Multicast 
unsigned char packetSource [6] = {0xD8,0xD3,0x85,0x1F,0x11,0x01}; 
unsigned char packetTypeIP [2] = {0x08,0x00}; 
unsigned char packetIPHeader [12] = {0x45, 0x00, 0x00, 0x32, 0x11, 0xF7, 0x00, 0x00, 0x01, 0x11, 0x00, 0x00}; 
unsigned char packetIPSource [4] = {0xC0, 0xA8, 0x01,0x06}; 
unsigned char packetIPDest [4] = {0xE0, 0x00, 0x00,0xFC }; //broadcast 

void interrupt high_isr(void) 
    counter1++;                  //flash LED 
    if(counter1 == 20000) 
        ETXSTH = 0x00; 
        ETXSTL = 0x40; 
        EDATA = 0; 
        for (x=0; x<6 ;x++){ 
            EDATA = packetDest[x]; 
        for (x=0; x<6 ;x++){ 
            EDATA = packetSource[x]; 
        for (x=0; x<2 ;x++){ 
            EDATA = packetTypeIP[x]; 
        for (x=0; x<12 ;x++){ 
            EDATA = packetIPHeader[x]; 
        for (x=0; x<4 ;x++){ 
            EDATA = packetIPSource[x]; 
        for (x=0; x<4 ;x++){ 
            EDATA = packetIPDest[x]; 
        for (x=0; x<30 ;x++){ 
            EDATA = 0x01; 
        ECON1bits.TXRST = 1; 
        PORTBbits.RB4 = !PORTBbits.RB4;     //toggle LED        counter1 = 0; 

    INTCONbits.TMR0IF = 0;      // clear interrupt-flag 

void low_priority interrupt low_isr(void){ 
    // will never happen 

void main(void) 

    INTCONbits.GIE = 1;        // enable global interrupts 
    INTCONbits.TMR0IF = 0;     // clear interrupt-flag 
    INTCONbits.TMR0IE = 1;     // enable interrupt for timer0 
    T0CONbits.T0CS = 0;        // clock source: 0 = internal clock, 1 = external clock 
    T0CONbits.TMR0ON = 1;       // switch timer0 on 
    //Ethernet Setup 
     ECON2bits.ETHEN = 1; 
     ERXST = 0; 
     ERXND = 0x3F; 
     ERXRDPTL = 0x3F; 
     ERXRDPTH = 0x00; 

    ECON2bits.AUTOINC = 1; 
    ECON1bits.TXRST = 0; 
    ECON1bits.RXRST = 0; 
    ECON1bits.CSUMEN = 0; 
    ECON1bits.RXEN = 0;    // dont receiv, i just wanna send 
    TRISBbits.RB4 = 0;                 // init LED 
    PORTBbits.RB4 = 0;                  // 
    PORTBbits.RB4 = !PORTBbits.RB4;     // 

    MACON1bits.MARXEN = 1; 
    MACON3bits.PADCFG0 = 1; 
    MACON3bits.PADCFG1 = 1; 
    MACON3bits.PADCFG2 = 1; 
    MACON3bits.TXCRCEN = 1; 
    MACON3bits.FULDPX = 0; 
    MACON3bits.FRMLNEN = 1; // ? 
    MACON4bits.DEFER = 1; 
    MAMXFL = 1518; 
    MABBIPG = 0x12; 
    MAIPGL = 0x12; 
    MAIPGH = 0xC; 
    MAADR1 = 0x01; 
    MAADR2 = 0x11; 
    MAADR3 = 0x1F; 
    MAADR4 = 0x85; 
    MAADR5 = 0xD3; 
    MAADR6 = 0xD8; 


Im using a development board created by Olimex. Here is the datasheet if 

Please help!

von fchk (Guest)

Rate this post
0 useful
not useful
Use the Microchip TCP/IP Stack! No need to duplicate work.

von Pasjul (Guest)

Rate this post
0 useful
not useful
I could not finde the TCP/IP Stack in the Datasheet from the 
Could you maybe give me link or so?

von fchk (Guest)

Rate this post
0 useful
not useful

von Pasjul (Guest)

Rate this post
0 useful
not useful
Thank you for the link. I googled before but couldnt find anything.

But im still not able to send a package via TCP or UDP after several 
hours of try and error...

I tried to flash a precompiled demo-app like discribed in the 
documentation i found with your link. But there the first problem 
arises; There isnt ANY demo-app or demo-code for the pic18f67J60, the 
closest match i found was pic18f97f60 (this demo-app didnt work of 
Then i tried to program it all by myself using the udp.h and tcp.h. I 
got nothing but errors, i wasnt able to even compile my code. The 
biggest problem was a file called "tcpipconfig.h", which should be 
generated by the "tcpip configuration wizard" (like described in the 
documentation). But still no luck...

Then i again started to search for some simple examples, but i just cant 
find anything!

Any ideas where i can find a simple project for my pic18f67j60 which 
creates a simple packet? I just want to send one lousy packet, it cant 
be this hard!

Im really desperate... :-(

von fchk (Guest)

Rate this post
0 useful
not useful
1. PIC18F97J60, PIC18F87J60, and PIC18F67J60 only differ in the package 
(100/80/64 pins), the bigger packages have more io ports and more UART 
and MSSP units. Otherwise it's basically the same chip.

2. Use known-good hardware! Buy or borrow a Microchip Eval board and try 
the demo app on that hardware.

3. I've used the stack with MPLAB 8 (the old one, not the newer MPLAB X) 
and C18 compiler version 3.34. (which is NOT the newest one). I can't 
tell you if the stack works at all with Hitech or the new XC8 compiler. 
In doubt, use the mature, well-tested environment.

4. Try to strip down the code, remove everything you don't need, and 
have a look at the UDP client and UDP server example code.

5. When you have working code on the Microchip eval board, move on to 
your custom hardware.

6. Use the microchip.com forum if you can't get beyond step 4. They 
obviously only can help you if you are using a Microchip devboard 
(preferrably an PICDEM.net 2).



Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.