backlight drawing V+ from display power

Hey,

I have setup a win2004 LCD (HD44780 pin compatible) connected to a Longtech 1.0 serial controller board. The backlight dimming works fine via a pwm pin (3), but when I apply 5v to drive the LCD display it makes the backlight go to full brightness. I thought they were seperate circuits?

To ensure that what I am seeing relates to the circuit I have put on the display the value of pin3 and the value of the optical sensor being read from A0. Their values change fine (A0 is mapped from 0, 1023, 0, 255). If I fiddle with the LCD's power lead while it's on (disconnect / re connect) sometimes it starts working as expected - numbers go down, backlight dims.

Any ideas?

Here is the code: ( im still not happy with the lcd control codes, newLine etc - its at the experimental stage having been ripped straight off the net.)

void setup() {
  // put your setup code here, to run once:
    Serial.begin(9600); 
      Serial.print(254, BYTE);
  Serial.print(0x48, BYTE);
  backlightOn();
}

void loop() {
  // put your main code here, to run repeatedly: 
  int PhotoCell = analogRead(A0);
  int LCDBacklight = map(PhotoCell, 0, 1023, 0, 255);
  analogWrite(3, LCDBacklight);


   //backlightOn();  // turn the backlight on all the time
   clearLCD();
   cursorHome();
  Serial.print(LCDBacklight);
  newLine();
  Serial.print(PhotoCell);
   delay(500);

}

void shiftLeft() {
  Serial.print(0xFE,BYTE);
  Serial.print(0x55,BYTE);
  Serial.print(0,BYTE);
}


//  LCD  FUNCTIONS-- keep the ones you need.

// clear the LCD
void clearLCD(){
  Serial.print(0xFE, BYTE);
  Serial.print(0x51, BYTE);
}

// move the cursor to the home position
void cursorHome(){
  Serial.print(254, BYTE);
  Serial.print(70, BYTE);
}

void newLine(){
  cursorSet(1,1);
}

// move the cursor to a specific place
// e.g.: cursorSet(3,2) sets the cursor to x = 3 and y = 2
void cursorSet(int xpos, int ypos){
  Serial.print(254, BYTE);
  Serial.print(69, BYTE);
  Serial.print(xpos);   //Column position
  Serial.print(ypos); //Row position
}


// backspace and erase previous character
void backSpace() {
  Serial.print(78, BYTE);
  Serial.print(8, BYTE);
}


// move cursor left
void cursorLeft(){
  Serial.print(254, BYTE);
  Serial.print(73, BYTE);
}


// move cursor right
void cursorRight(){
  Serial.print(254, BYTE);
  Serial.print(74, BYTE);
}


// turn on backlight
void backlightOn(){
  Serial.print(0xFE, BYTE);
  Serial.print(0x52, BYTE);
}


// turn off backlight
void backlightOff(){
  Serial.print(0xFE, BYTE);
  Serial.print(0x53, BYTE);
}

Datasheet on the serial controller: http://watchmelater.com/td/datasheets/RS-232_2004_.pdf

Thanks for your help.

Looks like it may have been part of the borrowed code fooling me:

  backlightOn();

This makes the backlight ignore the voltage input i guesss and lets it draw from the LCD's power supply ??

The backlight dimming works fine via a pwm pin (3), but when I apply 5v to drive the LCD display it makes the backlight go to full brightness. I thought they were seperate circuits?

Pin 3 deals with the LCD contrast it has nothing to do with the backlight. I'm not sure how you are accessing that pin to apply the pwm, but all that should do is determine how (and if) the characters appear on the screen. It is usually a set-and-forget adjustment that is made only once and is typically implemented via a potentiometer. There's a square blue device in three of the datasheet photographs which would be this potentiometer.

I am curious why your code uses a mixture of hex and decimal commands. The datasheet uses only hex so why are you converting some of them to decimal and leaving the others in hex?

Don

By pin3 I meant Digital pin 3 on the arduino.

I found the code on the net, that's why there's a mix. Is it a problem to have hex / dec values? When I went on to code the rest the commands were in The format of Serial.print(0xFE, BYTE); Serial.print(0x51, BYTE); Serial.print(1, BYTE); etc.