THE DESIGN CYCLE
PIC18F67J60’s PORTA as outputs so
they can support the Ethernet status
LEDs, which are integrated into the
Ethernet magnetics. All of the pushbuttons are attached to PIC18F67J60’s
PORTB. So, to service the pushbutton
switches, we use the TRISB value of
0xFF to set up all of PORTB’s pins as
inputs. PORTC supports the RS-232
port, the SPI interface, and the real-time clock. The SPI interface is connected to a 25LC256 EEPROM and we
must configure the TRISC bit pattern
to set the SPI I/O pin directions (input
or output) according to their functions.
The PIC18F67J60’s EUSART controller will automatically set the TX
and RX pin directions. The EEPROM
CS (Chip Select) pin is attached to bit
2 of PORTD. Since the PIC18F67J60
will control the access to the EEPROM, the PORTD TRIS value for bit 2
sets that I/O pin as an output. The
least significant bits of PORTF drive
the LEDs. So, it stands to reason that
we will make the LED driving pins outputs. Of course, you’ll need to set the
directions of the unused I/O pins if
you plan to use them in your project.
Standard microcontrollers need
reset time to get their internal act
together. The same holds true for the
PIC18F67J60, which is basically a
standard microcontroller with a big
on-chip Ethernet peripheral. Take
another look at Listing 1. The PHYRDY
bit within the ESTAT register is set
when the PIC18F67J60’s PHY internals ripen. Nothing should be done to
any of the PIC18F67J60’s MAC, MII,
or PHY registers until after the PHY
comes ready. So, following a power-up
of the PIC18F67J60, we simply enable
the PIC18F67J60’s Ethernet electronics by setting the ETHEN bit in the
PIC18F67J60’s ECON2 register. We
then just sit and spin poll the PHYRDY
bit and exit the polling loop once the
PHYRDY bit is set.
Once we see the PHYRDY bit go
logically high, we give the PIC18F67J60
LISTING 1
void init_67J60(void)
{
char x;
TRISA = 0b11111100;
TRISB = 0b11111111;
TRISC = 0b01010111;
TRISD = 0b11111011;
TRISF = 0b11100001;
LED2 = 1;
LATF = 0xFF;
//Enable Ethernet
ETHEN = 1;
while(!PHYRDY);
msecs_timer = 0;
while(msecs_timer < 2);
//turn off LEDs
LATF = 0x00;
RXEN = 0;
TXRTS = 0;
packetheader[nextpacket_low] = LOW_BYTE(RXSTART);
packetheader[nextpacket_high] = HIGH_BYTE(RXSTART);
ERXSTL = LOW_BYTE(RXSTART);
ERXSTH = HIGH_BYTE(RXSTART);
ERXRDPTL = LOW_BYTE(RXSTOP);
ERXRDPTH = HIGH_BYTE(RXSTOP);
ERXNDL = LOW_BYTE(RXSTOP);
ERXNDH = HIGH_BYTE(RXSTOP);
ETXSTL = LOW_BYTE(TXSTART);
ETXSTH = HIGH_BYTE(TXSTART);
MACON1 = MACON1_TXPAUS | MACON1_RXPAUS | MACON1_MARXEN;
NOP();
//Pad packets to 60 bytes, add CRC, and check Type/Length field
MACON3 = MACON3_PADCFG0 | MACON3_TXCRCEN | MACON3_FRMLNEN;
NOP();
// Allow infinite deferals if the medium is continuously busy
// (do not time out a transmission if the half duplex medium is
// completely saturated with other people's data)
MACON4 = MACON4_DEFER;
NOP();
// Late collisions occur beyond 63 bytes (default for 802.3 spec)
MACLCON2 = 63;
NOP();
MAIPGL = 0x12;
NOP();
MAIPGH = 0x0C;
NOP();
MAMXFLL = LOW_BYTE(MAXFRAME);
NOP();
MAMXFLH = HIGH_BYTE(MAXFRAME);
NOP();
■ LISTING 1. There’s not much difference
between this PIC18F67J60 code and
the ENC28J60 code. In fact, the
register names are identical across the
platforms. That makes for an easy port
of the Fred Eady-devised ENC28J60 and
RTL8019AS code to the PIC18F67J60.
MAADR1 = macaddrc[0];
NOP();
MAADR2 = macaddrc[1];
NOP();
MAADR3 = macaddrc[2];
NOP();
MAADR4 = macaddrc[3];
NOP();
MAADR5 = macaddrc[4];
NOP();
Continued ...
March 2007 87