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.