LCD and ENC28J60 libraries collide?

I have a HD44780 LCD and a ENC28J60 connected to my Arduino Duemilanove. Here is the code:

//#include <LiquidCrystal.h>
#include "etherShield.h"
//LiquidCrystal lcd(A3,A2,8,4,5,6,7);
static uint8_t mymac[6]={0x00,0x1E,0xC0,0x59,0x65,0x70};
static uint8_t myip[4]={192,168,0,14};
#define BUFFER_SIZE 250
unsigned char buf[BUFFER_SIZE+1];
uint16_t plen;
EtherShield es=EtherShield();
void setup() {
//  lcd.begin(16,2);
//  lcd.print("Watt-A-Duino 1.0");
//  lcd.setCursor(0,1);
//  lcd.print("DSP:TMY-01.00.00");
    /*initialize enc28j60*/
  es.ES_enc28j60Init(mymac);
  es.ES_enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz
  delay(10);
  /* Magjack leds configuration, see enc28j60 datasheet, page 11 */
  // LEDA=green LEDB=yellow
  //
  // 0x880 is PHLCON LEDB=on, LEDA=on
  // enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);
  es.ES_enc28j60PhyWrite(PHLCON,0x880);
  delay(500);
  // 0x990 is PHLCON LEDB=off, LEDA=off
  // enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);
  es.ES_enc28j60PhyWrite(PHLCON,0x990);
  delay(500);
  //
  // 0x880 is PHLCON LEDB=on, LEDA=on
  // enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);
  es.ES_enc28j60PhyWrite(PHLCON,0x880);
  delay(500);
  //
  // 0x990 is PHLCON LEDB=off, LEDA=off
  // enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);
  es.ES_enc28j60PhyWrite(PHLCON,0x990);
  delay(500);
  //
  // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit
  // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10);
  es.ES_enc28j60PhyWrite(PHLCON,0x476);
  delay(100);
  //init the ethernet/ip layer:
  es.ES_init_ip_arp_udp_tcp(mymac,myip,80);
}
void loop() {
  
  plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf);

  /*plen will be unequal to zero if there is a valid packet (without crc error) */
  if(plen!=0){
       if(es.ES_eth_type_is_arp_and_my_ip(buf,plen)){
      	es.ES_make_arp_answer_from_request(buf);
      }
      // check if ip packets (icmp or udp) are for us:
      else if(es.ES_eth_type_is_ip_and_my_ip(buf,plen)!=0){
         if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V){
         		// a ping packet, let's send pong
            es.ES_make_echo_reply_from_request(buf,plen);
   		    }
      }
  }  
}

The LCD and the ENC28J60 work great by themselves, but trying to use both at once causes neither to work and the yellow LED on the Arduino blinks.

Your (unspecified) ethernet shield is probably using one or more of the same pins that your LCD is using. Use the information at shieldlist.org to determine which pins your ethernet shield is using and pick different ones for the LCD. You can save one pin by connecting the LCD RW pin (pin 5) to GND.

Don

It's a homemade version of http://www.nuelectronics.com/estore/index.php?main_page=project_eth . In the final application, there's going to be the LCD, the ENC28J60, a dsPIC33F DSP connected using SPI, a button or two, and maybe a SD card slot.

It's a homemade version of ...

My answer still holds, just look up the information about the device that you copied to find out which Arduino pins it uses.

Don

The ENC28J60 is using pins 10-13 (SPI) and 2(INT). The LCD is using 4-8 and A2-A3, so I don't see a conflict unless there's something about the I/Os I don't know about.

I just discovered that if I uncomment the LCD code down to the first "lcd.print" line, both the LCD and the ENC28J60 work great together. As soon as I uncomment the "lcd.setCursor" line, the Arduino goes into the "flashing LED" mode and nothing works.

NiHaoMike:
I just discovered that if I uncomment the LCD code down to the first “lcd.print” line, both the LCD and the ENC28J60 work great together. As soon as I uncomment the “lcd.setCursor” line, the Arduino goes into the “flashing LED” mode and nothing works.

When lcd.print is executed the RS line from the Arduino to the LCD module is high. When lcd setCursor is executed the RS line from the Arduino to the LCD module is low. I would start my investigation into the problem by making sure that you are not inadvertently using this same Arduino pin for something else.

Don

Problem solved. I noticed that any program larger than a certain size (4400 bytes or so) failed to work, as if the chip was bad. With little to lose, I borrowed a friend's Arduino and reflashed the bootloader. Now everything works fine. It seems like the bootloader somehow got corrupt such that it fails on large programs.