View Single Post
Old 04-17-2008, 01:16 AM   #34 (permalink)
dcb
needs more cowbell
 
dcb's Avatar
 
Join Date: Feb 2008
Location: ÿ
Posts: 5,038

pimp mobile - '81 suzuki gs 250 t
90 day: 96.29 mpg (US)

schnitzel - '01 Volkswagen Golf TDI
90 day: 53.56 mpg (US)
Thanks: 158
Thanked 269 Times in 212 Posts
Well, I didn't get anywhere with the 4 bit library, and it was getting annoying recompiling the library for a bunch of trial and error, so I tried this:
http://www.arduino.cc/cgi-bin/yabb2/...m=1160586800/0

I didn't get results at first and don't recall everything that was involved (predefined timings was one of the gotchas). But here are my current pin assignments and the mpguino display code. It does a good job of highlighting the sequence of events but the delays do need to be redone as status checks and pushed back into the lcd library. Note, with this code I had to hit the reset button after downloading the script or powering up sometimes.
Code:
LCD	arduino
1	ground
2	5v
3	digital 6
4	digital 4
5	digital 0
6	digital 5
7	not connected
8	not connected
9	not connected
10	not connected
11	digital 7
12	digital 8
13	digital 12
14	digital 13
15	5v
16	ground
Code:
int DI = 4; // register select RS
int RW = 0; 

int db4=7; int db5=8; int db6=12; int db7=13;
int contrast=6;
int Enable = 5; 
 
 
void tickleEnable() 
{ 
 // send a pulse to enable 
 digitalWrite(Enable,HIGH); 
 delayMicroseconds(1);  // pause 1 ms according to datasheet 
 digitalWrite(Enable,LOW); 
 delayMicroseconds(1);  // pause 1 ms according to datasheet 
}  
 
void cmdWriteSet() 
{ 
 digitalWrite(Enable,LOW); 
 delayMicroseconds(1);  // pause 1 ms according to datasheet 
  digitalWrite(DI,0); 
  digitalWrite(RW,0); 
} 
void LcdCommandWrite(int value)  
{ 
 int i = 0; 
 
    digitalWrite(db7, value & 128); 
    value <<= 1; 
    digitalWrite(db6, value & 128); 
    value <<= 1; 
    digitalWrite(db5, value & 128); 
    value <<= 1; 
    digitalWrite(db4, value & 128); 
    value <<= 1; 
    cmdWriteSet(); 
    tickleEnable(); 

    digitalWrite(db7, value & 128); 
    value <<= 1; 
    digitalWrite(db6, value & 128); 
    value <<= 1; 
    digitalWrite(db5, value & 128); 
    value <<= 1; 
    digitalWrite(db4, value & 128); 
     value <<= 1; 
    cmdWriteSet(); 
    tickleEnable(); 
} 
 
void LcdDataWrite(int value)  
{ 
 int i = 0; 
  
 digitalWrite(DI, HIGH); 
 digitalWrite(RW, LOW); 
   
    digitalWrite(db7, value & 128); 
    value <<= 1; 
    digitalWrite(db6, value & 128); 
    value <<= 1; 
    digitalWrite(db5, value & 128); 
    value <<= 1; 
    digitalWrite(db4, value & 128); 
  value <<= 1; 

    tickleEnable(); 
 
    digitalWrite(db7, value & 128); 
    value <<= 1; 
    digitalWrite(db6, value & 128); 
    value <<= 1; 
    digitalWrite(db5, value & 128); 
    value <<= 1; 
    digitalWrite(db4, value & 128); 
value <<= 1; 
    tickleEnable(); 
    delay(5);
} 
 
void setup (void)  
{ 
 pinMode(Enable,OUTPUT); 
 pinMode(RW,OUTPUT); 
 pinMode(DI,OUTPUT); 
 pinMode(db4,OUTPUT); 
 pinMode(db5,OUTPUT); 
 pinMode(db6,OUTPUT); 
 pinMode(db7,OUTPUT); 
 
 delay(100); 
 LcdCommandWrite(0x2c);  // function set: 
  delay(64);             // 4-bit interface, 2 display lines, 5x7 font 
                        // other interaces: 
                        // 0x20 = 4 bit, 1 display line 
 
 LcdCommandWrite(0x06);  // entry mode set: 
                        // increment automatically, no display shift 
 delay(20);                       
 LcdCommandWrite(0x0c);  // display control: 
                        // turn display on, cursor on, no blinking 
 delay(20);                       
 LcdCommandWrite(0x01);  // clear display, set cursor position to zero   
 
 delay(100);                       
LcdCommandWrite(0x80);  // set dram to zero (necessary?
 delay(20);       

 analogWrite(contrast,75);
 delay(20);       

} 
  int i='0';
 
void loop (void)  
{ 
   
  delay(500);                  // stop the program for some time 

  LcdCommandWrite(0x01);  // set cursor position to zero   
  delay(20);                      
  firstDisplay(); 
 
boolean asc=true;
  while(true){
    for(int x = 0; x < 256; x++){
     analogWrite(contrast,x);
     delay(8);
    }
    for(int x = 255; x >0; x--){
     analogWrite(contrast,x);
     delay(8);
    }
  };
} 
 


void firstDisplay() 
{ 
//     LcdDataWrite(value); 
     LcdDataWrite('O'); 
     LcdDataWrite('P'); 
     LcdDataWrite('E'); 
     LcdDataWrite('N'); 
     LcdDataWrite('G'); 
     LcdDataWrite('A'); 
     LcdDataWrite('U'); 
     LcdDataWrite('G'); 
     LcdDataWrite('E'); 
LcdCommandWrite(0xC9);  // C0 would be start of second line
 delay(20);       

     LcdDataWrite('M'); 
     LcdDataWrite('P'); 
     LcdDataWrite('G'); 
     LcdDataWrite('U'); 
     LcdDataWrite('I'); 
     LcdDataWrite('N'); 
     LcdDataWrite('O'); 
 }
__________________
WINDMILLS DO NOT WORK THAT WAY!!!

Last edited by dcb; 04-17-2008 at 01:23 AM..
  Reply With Quote