View Single Post
Old 06-12-2008, 06:38 PM   #25 (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 267 Times in 210 Posts
I'm glad you like it It is just a mockup, it doesn't do anything and has not been integrated to the mpguino codebase, but here is the code if you are interested. I basically build the numbers with 5 custom block shaped characters (will need to get rid of the current custom characters for this)

PHP Code:
//GPL Software  

byte brightness[]={0,42,85,128}; //middle button cycles through these brightness settings    
#define brightnessLength (sizeof(brightness)/sizeof(byte)) //array size    
byte brightnessIdx=2;    
#define contrast 15    

//LCD Pins    
#define DIPin 4 // register select RS    
#define DB4Pin 7     
#define DB5Pin 8     
#define DB6Pin 12     
#define DB7Pin 13    
#define ContrastPin 6    
#define EnablePin 5     
#define BrightnessPin 9    
#define lcdpowerPin 15


//LCD prototype    
class LCD{    
public:    
  
LCD( ) ;    
  
void gotoXY(byte xbyte y);    
  
void print(char string);    
  
void init();    
  
void tickleEnable();    
  
void cmdWriteSet();    
  
void LcdCommandWrite(byte value);    
  
void LcdDataWrite(byte value);    
  
byte pushNibble(byte value);    
};    


//main objects we will be working with:    
LCD lcd;    

void setup (void){     
  
pinMode(lcdpowerPin,OUTPUT);    
  
digitalWrite(lcdpowerPin,LOW);
  
pinMode(BrightnessPin,OUTPUT);    
  
analogWrite(BrightnessPin,255-brightness[brightnessIdx]);    
  
delay(500);
  
digitalWrite(lcdpowerPin,HIGH);
  
lcd.init();    
  
pinMode(ContrastPin,OUTPUT);    
  
analogWrite(ContrastPin,contrast);    

  
lcd.LcdDataWrite(3);   lcd.LcdDataWrite(2);   lcd.LcdDataWrite(3); lcd.LcdDataWrite(32); 
  
lcd.LcdDataWrite(3);   lcd.LcdDataWrite(2);   lcd.LcdDataWrite(3); lcd.LcdDataWrite(32);  
  
lcd.LcdDataWrite(0);   lcd.LcdDataWrite(0);   lcd.LcdDataWrite(3); lcd.LcdDataWrite(32);  
  
lcd.print("INST");  
  
lcd.gotoXY(0,1);    
  
lcd.LcdDataWrite(1);   lcd.LcdDataWrite(1);   lcd.LcdDataWrite(3);  lcd.LcdDataWrite(32);  
  
lcd.LcdDataWrite(3);   lcd.LcdDataWrite(1);   lcd.LcdDataWrite(3);  lcd.LcdDataWrite(4);  
  
lcd.LcdDataWrite(32);   lcd.LcdDataWrite(32);   lcd.LcdDataWrite(3);  lcd.LcdDataWrite(32);  
  
lcd.print("MPG");  
  
}     

void loop (void){     
  while(
true){}    
}     



//LCD functions    
LCD::LCD(){    
}    
//x=0..16, y= 0..1    
void LCD::gotoXY(byte xbyte y){    
  
byte dr=x+0x80;    
  if (
y==1)     
    
dr += 0x40;    
  if (
y==2)     
    
dr += 0x14;    
  if (
y==3)     
    
dr += 0x54;    
  
lcd.LcdCommandWrite(dr);      
}    

void LCD::print(char string){    
  
byte x 0;    
  
char c string[x];    
  while(
!= 0){    
    
lcd.LcdDataWrite(c);     
    
x++;    
    
string[x];    
  }    
}    


//do the lcd initialization voodoo    
void LCD::init(){    
  
pinMode(EnablePin,OUTPUT);     
  
pinMode(DIPin,OUTPUT);     
  
pinMode(DB4Pin,OUTPUT);     
  
pinMode(DB5Pin,OUTPUT);     
  
pinMode(DB6Pin,OUTPUT);     
  
pinMode(DB7Pin,OUTPUT);     
  
delay(500);    

  
LcdCommandWrite(B00000010);  // 4 bit operation      

  
LcdCommandWrite(B00101000);// 4-bit interface, 2 display lines, 5x8 font     
  
LcdCommandWrite(B00001100);  // display control:     
  
LcdCommandWrite(B00000110);  // entry mode set: increment automatically, no display shift     


  
LcdCommandWrite(B01000000);  // set cgram    
  //create some custom characters    
  
byte chars[]={
    
B11111,B00000,B11111,B11111,B00000,
    
B11111,B00000,B11111,B11111,B00000,
    
B00000,B00000,B00000,B11111,B00000,
    
B00000,B00000,B00000,B11111,B00000,
    
B00000,B00000,B00000,B11111,B00000,
    
B00000,B00000,B00000,B11111,B01110,
    
B00000,B11111,B11111,B11111,B01110,
    
B00000,B11111,B11111,B11111,B01110};
        
    for(
byte x=0;x<5;x++)      
      for(
byte y=0;y<8;y++)      
          
LcdDataWrite(chars[y*5+x]); //write the character data to the character generator ram     

  
LcdCommandWrite(B00000001);  // clear display, set cursor position to zero       

  
LcdCommandWrite(B10000000);  // set dram to zero     

}      

void  LCD::tickleEnable(){     
  
// send a pulse to enable     
  
digitalWrite(EnablePin,HIGH);     
  
delayMicroseconds(1);  // pause 1 ms according to datasheet     
  
digitalWrite(EnablePin,LOW);     
  
delayMicroseconds(1);  // pause 1 ms according to datasheet     
}      

void LCD::cmdWriteSet(){     
  
digitalWrite(EnablePin,LOW);     
  
delayMicroseconds(1);  // pause 1 ms according to datasheet     
  
digitalWrite(DIPin,0);     
}     

byte LCD::pushNibble(byte value){     
  
digitalWrite(DB7Pinvalue 128);     
  
value <<= 1;     
  
digitalWrite(DB6Pinvalue 128);     
  
value <<= 1;     
  
digitalWrite(DB5Pinvalue 128);     
  
value <<= 1;     
  
digitalWrite(DB4Pinvalue 128);     
  
value <<= 1;     
  return 
value;    
}    

void LCD::LcdCommandWrite(byte value){     
  
value=pushNibble(value);    
  
cmdWriteSet();     
  
tickleEnable();     
  
value=pushNibble(value);    
  
cmdWriteSet();     
  
tickleEnable();     
  
delay(5);     
}     

void LCD::LcdDataWrite(byte value){     
  
digitalWrite(DIPinHIGH);     
  
value=pushNibble(value);    
  
tickleEnable();     
  
value=pushNibble(value);    
  
tickleEnable();     
  
delay(5);     

__________________
WINDMILLS DO NOT WORK THAT WAY!!!
  Reply With Quote