Pages: [1]   Go Down
Author Topic: Suche Sketch für EA DIP204-4 Display  (Read 1976 times)
0 Members and 1 Guest are viewing this topic.
Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ich suche für das 20x4 Display EA DIP204J-4NLW einen funktionierenden Sketch.  Das Display hat ja den KS0073 Controller und lässt sich deshalb nicht richtig initialisieren.

Kann mir jemand helfen?

Gruß

Jürgen
Logged

berlin
Offline Offline
Sr. Member
****
Karma: 0
Posts: 293
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hallo Jürgen,
Was hast Du denn bisher probiert und damit erreicht?
Der KS0073 ist ja nun kein Hinferungsgrund per se. Hast Du die LiquidCrystal Library mit Beispielen entdeckt? Wird irgendwas angezeigt?

Das hier habe ich auf die schnelle noch im Forum gefunden:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1249053552

Viel Erfolg erstmal,
kuuk
Logged

Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hallo kuk,

danke für den Link, den habe ich auch schon gefunden, ich bin erst seit kurzen mit dem Arduino vertraut und habe mir für ein Projekt dieses Display ausgesucht. Es ist ja klein und passt daher auch in mein Gehäuse.

Ja die LiqiudChristal Library habe ich ausprobiert, es wird ja auch im Display das "hello world" angezeigt. Nur werden die Sekunden inder 3. Zeile angezeigt.

Deinen Link zufolge müßte die Initialisierung angepasst werden.

Ich habe aber keine Ahnung wie?
Kann ich die Zeilen mit Command.... in die cpp.datei einfügen?

Bin halt mit C noch ein noob. smiley

Gruß und danke für deine Antwort

Jürgen
Logged

Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ich habe mich mit der LCD4Bit.Library beschäftigt, da ich hier die Init-Sequenz für den KS 0073 eingeben konnte.

Habs soweit hinbekommen das das Display alle 4 Zeilen korrekt anzeigt.

Die LED PIN 13 sollte auch im Takt blinken, tut sie aber nicht und leuchtet dauernd!

Ich würde ja die LiquidChrystal Library nehmen, aber ich weis nicht wie die Init-Sequenz dort in die Library eingefügt wird.

Vielleicht braucht ja jemand die Init-Sequenz für den KS0073 Controller.

Hier meine pde:
Code:
//example use of LCD4Bit library

#include <LCD4Bit.h>
//create object to control an LCD.  
//number of lines in display=1
LCD4Bit lcd = LCD4Bit(4);

//some messages to display on the LCD
//char msgs[6][15] = {"apple", "banana", "pineapple", "mango", "watermelon", "pear"};
//int NUM_MSGS = 6;

void setup() {
  pinMode(13, OUTPUT);  //we'll use the debug LED to output a heartbeat

  lcd.init();
  //optionally, now set up our application-specific display settings, overriding whatever the lcd did in lcd.init()
  //lcd.commandWrite(0x0F);//cursor on, display on, blink on.  (nasty!)
  //lcd.commandWrite(0x30);
  //delay(5);
  //lcd.commandWrite(0x30);
  //delay(120);
  //lcd.commandWrite(0x30);
  //delay(120);
  lcd.commandWrite(0x01);
  delay(50);
  lcd.commandWrite(0x24);
  delay(50);
  lcd.commandWrite(0x0C);
  delay(50);
  lcd.commandWrite(0x20);
  delay(50);
  lcd.commandWrite(0x06);
  delay(50);
  lcd.commandWrite(0x24);
  delay(50);
  lcd.commandWrite(0x09);
  delay(50);
  lcd.commandWrite(0x20);
  delay(50);
  lcd.commandWrite(0x01);
}
void loop() {  
  digitalWrite(13, HIGH);  //light the debug LED
  lcd.clear();
  lcd.cursorTo(1, 0);
  lcd.printIn("Line 1");
  lcd.cursorTo(2, 0);
  lcd.printIn("Line 2");
  lcd.cursorTo(3, 0);
  lcd.printIn("Line 3");
  lcd.cursorTo(4, 0);
  lcd.printIn("Line 4");
  delay(1000);
  digitalWrite(13, LOW);  //clear the debug LED
}
« Last Edit: May 25, 2010, 02:09:27 am by Juergen-05 » Logged

CH
Offline Offline
God Member
*****
Karma: 19
Posts: 703
Book Writer "Arduino Praxiseinstieg"
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Die LED PIN 13 sollte auch im Takt blinken, tut sie aber nicht und leuchtet dauernd!

Die LED geht kurz aus, aber dann beim nächsten Durchlauf des Loop() sofort wieder an. Darum hat es den Anschein als ob die LED immer HIGH ist.
Damit die LED blinkt, muss du die LED-Ansteuerung für LOW vor dem delay() setzen.

Bisher:
Code:
delay(1000);
digitalWrite(13, LOW);  //clear the debug LED

Besser:
Code:
digitalWrite(13, LOW);  //clear the debug LED
delay(1000);


Logged

Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hallo Webmeister,

da hätt ich ja auch selbst draufkommen müssen, aber durch die Programmierung der Init hab ich´s nicht gepeilt.  smiley-wink

Werd ich mal ändern und ich stell die Init noch mal mit Kommentaren hier rein.

Gruß
Jürgen
Logged

Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hier der Code mit Kommentaren zur Initialisierung de KS0073:
Code:
//example use of LCD4Bit library

#include <LCD4Bit.h>
//create object to control an LCD.  
//number of lines in display=1
LCD4Bit lcd = LCD4Bit(4);

void setup() {
  pinMode(13, OUTPUT);  //we'll use the debug LED to output a heartbeat

  lcd.init();
  //optionally, now set up our application-specific display settings, overriding whatever the lcd did in lcd.init()
  //lcd.commandWrite(0x0F);//cursor on, display on, blink on.  (nasty!)
  lcd.commandWrite(0x01);//clear display
  delay(02);
  lcd.commandWrite(0x24);//function set RE=1
  delay(50);
  lcd.commandWrite(0x0C);//control, display on, cursor off, blinken off
  delay(50);
  lcd.commandWrite(0x20);//function set RE=0
  delay(50);
  lcd.commandWrite(0x06);//entry mode segment bidirectional
  delay(50);
  lcd.commandWrite(0x24);//function set RE=1
  delay(50);
  lcd.commandWrite(0x09);//extended function set, 4 lines, 5-dot fontwith
  delay(50);
  lcd.commandWrite(0x20);//function set RE=0
  delay(20);
  lcd.commandWrite(0x01);//clear display
  delay(02);
}
void loop() {  
  digitalWrite(13, HIGH);  //light the debug LED
  lcd.clear();
  lcd.cursorTo(1, 0);
  lcd.printIn("Line 1");
  lcd.cursorTo(2, 0);
  lcd.printIn("Line 2");
  lcd.cursorTo(3, 0);
  lcd.printIn("Line 3");
  lcd.cursorTo(4, 0);
  lcd.printIn("Line 4");
  digitalWrite(13, LOW);  //clear the debug LED
  delay(1000);
}

Dann muß noch die cpp-datei angepasst werden:

1. Constructor austauschen!

Neuer Code:

//constructor.  num_lines must be 1 or 2, currently.
LCD4Bit::LCD4Bit (int num_lines) {
  g_num_lines = num_lines;
  if (g_num_lines < 1 || g_num_lines > 4)
  {
    g_num_lines = 4;
  }
}

2. cursorTo austauschen!

Neuer Code:

void LCD4Bit::cursorTo(int line_num, int x){
//first, put cursor home
commandWrite(CMD_HOME);
if (x>19)
{
x=19;
}
switch (line_num)
{
case 1:
x+=0x00 ; break;
case 2:
x+= 0x20 ; break;
case 3:
x+= 0x40 ; break; // In fact, line 3 is an extension of the line 1 (beyond the 20 first characters)
case 4:
x+= 0x60 ; break; // Line 4 is an extension of line 2
}

commandWrite(0x80+x);
}


Ich hoffe jemanden hiermit auch geholfen zu haben, denn das Display kann ja auch mit 3,3 volt betrieben werden und das war der Hauptgrund für den Kauf!

Gruß

Jürgen
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Kann ich deine LCD4bit.cpp haben? Danke
Logged

Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ja hier ist sie:
Code:
*
LCD4Bit v0.1 16/Oct/2006 neillzero http://abstractplain.net

What is this?
An arduino library for comms with HD44780-compatible LCD, in 4-bit mode (saves pins)

Sources:
- The original "LiquidCrystal" 8-bit library and tutorial
    http://www.arduino.cc/en/uploads/Tutorial/LiquidCrystal.zip
    http://www.arduino.cc/en/Tutorial/LCDLibrary
- DEM 16216 datasheet http://www.maplin.co.uk/Media/PDFs/N27AZ.pdf
- Massimo's suggested 4-bit code (I took initialization from here) http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1144924220/8
See also:
- glasspusher's code (probably more correct): http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1160586800/0#0

Tested only with a DEM 16216 (maplin "N27AZ" - http://www.maplin.co.uk/Search.aspx?criteria=N27AZ)
If you use this successfully, consider feeding back to the arduino wiki with a note of which LCD it worked on.

Usage:
see the examples folder of this library distribution.

*/

#include "LCD4Bit.h"
extern "C" {
  #include <stdio.h>  //not needed yet
  #include <string.h> //needed for strlen()
  #include <inttypes.h>
  #include "WConstants.h"  //all things wiring / arduino
}

//command bytes for LCD
#define CMD_CLR 0x01
#define CMD_RIGHT 0x1C
#define CMD_LEFT 0x18
#define CMD_HOME 0x02

// --------- PINS -------------------------------------
//is the RW pin of the LCD under our control?  If we're only ever going to write to the LCD, we can use one less microcontroller pin, and just tie the LCD pin to the necessary signal, high or low.
//this stops us sending signals to the RW pin if it isn't being used.
int USING_RW = false;

//RS, RW and Enable can be set to whatever you like
int RS = 12;
int RW = 11;
int Enable = 2;
//DB should be an unseparated group of pins  - because of lazy coding in pushNibble()
int DB[] = {7, 8, 9, 10};  //wire these to DB4~7 on LCD.

//--------------------------------------------------------

//how many lines has the LCD? (don't change here - specify on calling constructor)
int g_num_lines = 2;

//pulse the Enable pin high (for a microsecond).
//This clocks whatever command or data is in DB4~7 into the LCD controller.
void LCD4Bit::pulseEnablePin(){
  digitalWrite(Enable,LOW);
  delayMicroseconds(1);
  // send a pulse to enable
  digitalWrite(Enable,HIGH);
  delayMicroseconds(1);
  digitalWrite(Enable,LOW);
  delay(1);  // pause 1 ms.  TODO: what delay, if any, is necessary here?
}

//push a nibble of data through the the LCD's DB4~7 pins, clocking with the Enable pin.
//We don't care what RS and RW are, here.
void LCD4Bit::pushNibble(int value){
  int val_nibble= value & 0x0F;  //clean the value.  (unnecessary)

  for (int i=DB[0]; i <= DB[3]; i++) {
    digitalWrite(i,val_nibble & 01);
    val_nibble >>= 1;
  }
  pulseEnablePin();
}

//push a byte of data through the LCD's DB4~7 pins, in two steps, clocking each with the enable pin.
void LCD4Bit::pushByte(int value){
  int val_lower = value & 0x0F;
  int val_upper = value >> 4;
  pushNibble(val_upper);
  pushNibble(val_lower);
}


//stuff the library user might call---------------------------------
//constructor.  num_lines must be 1 or 2, currently.
LCD4Bit::LCD4Bit (int num_lines) {
  g_num_lines = num_lines;
  if (g_num_lines < 1 || g_num_lines > 4)
  {
    g_num_lines = 4;
  }
}

void LCD4Bit::commandWriteNibble(int nibble) {
  digitalWrite(RS, LOW);
  if (USING_RW) { digitalWrite(RW, LOW); }
  pushNibble(nibble);
}


void LCD4Bit::commandWrite(int value) {
  digitalWrite(RS, LOW);
  if (USING_RW) { digitalWrite(RW, LOW); }
  pushByte(value);
  //TODO: perhaps better to add a delay after EVERY command, here.  many need a delay, apparently.
}




//print the given character at the current cursor position. overwrites, doesn't insert.
void LCD4Bit::print(int value) {
  //set the RS and RW pins to show we're writing data
  digitalWrite(RS, HIGH);
  if (USING_RW) { digitalWrite(RW, LOW); }

  //let pushByte worry about the intricacies of Enable, nibble order.
  pushByte(value);
}


//print the given string to the LCD at the current cursor position.  overwrites, doesn't insert.
//While I don't understand why this was named printIn (PRINT IN?) in the original LiquidCrystal library, I've preserved it here to maintain the interchangeability of the two libraries.
void LCD4Bit::printIn(char msg[]) {
  uint8_t i;  //fancy int.  avoids compiler warning when comparing i with strlen()'s uint8_t
  for (i=0;i < strlen(msg);i++){
    print(msg[i]);
  }
}


//send the clear screen command to the LCD
void LCD4Bit::clear(){
  commandWrite(CMD_CLR);
  delay(1);
}


// initiatize lcd after a short pause
//while there are hard-coded details here of lines, cursor and blink settings, you can override these original settings after calling .init()
void LCD4Bit::init () {
  pinMode(Enable,OUTPUT);
  pinMode(RS,OUTPUT);
  if (USING_RW) { pinMode(RW,OUTPUT); }
  pinMode(DB[0],OUTPUT);
  pinMode(DB[1],OUTPUT);
  pinMode(DB[2],OUTPUT);
  pinMode(DB[3],OUTPUT);

  delay(50);

  //The first 4 nibbles and timings are not in my DEM16217 SYH datasheet, but apparently are HD44780 standard...
  commandWriteNibble(0x03);
  delay(5);
  commandWriteNibble(0x03);
  delayMicroseconds(100);
  commandWriteNibble(0x03);
  delay(5);

  // needed by the LCDs controller
  //this being 2 sets up 4-bit mode.
  commandWriteNibble(0x02);
  commandWriteNibble(0x02);
  //todo: make configurable by the user of this library.
  //NFXX where
  //N = num lines (0=1 line or 1=2 lines).
  //F= format (number of dots (0=5x7 or 1=5x10)).
  //X=don't care

  int num_lines_ptn = g_num_lines - 1 << 3;
  int dot_format_ptn = 0x00;      //5x7 dots.  0x04 is 5x10

  commandWriteNibble(num_lines_ptn | dot_format_ptn);
  delayMicroseconds(60);

  //The rest of the init is not specific to 4-bit mode.
  //NOTE: we're writing full bytes now, not nibbles.

  // display control:
  // turn display on, cursor off, no blinking
  commandWrite(0x0C);
  delayMicroseconds(60);

  //clear display
  commandWrite(0x01);
  delay(3);

  // entry mode set: 06
  // increment automatically, display shift, entire shift off
  commandWrite(0x06);

  delay(1);//TODO: remove unnecessary delays
}


//non-core stuff --------------------------------------
//move the cursor to the given absolute position.  line numbers start at 1.
//if this is not a 2-line LCD4Bit instance, will always position on first line.
void LCD4Bit::cursorTo(int line_num, int x){
//first, put cursor home
commandWrite(CMD_HOME);
if (x>19)
{
x=19;
}
switch (line_num)
{
case 1:
x+=0x00 ; break;
case 2:
x+= 0x20 ; break;
case 3:
x+= 0x40 ; break; // In fact, line 3 is an extension of the line 1 (beyond the 20 first characters)
case 4:
x+= 0x60 ; break; // Line 4 is an extension of line 2
}

commandWrite(0x80+x);
}
//scroll whole display to left
void LCD4Bit::leftScroll(int num_chars, int delay_time){
  for (int i=0; i<num_chars; i++) {
    commandWrite(CMD_LEFT);
    delay(delay_time);
  }
}

//Improvements ------------------------------------------------
//Remove the unnecessary delays (e.g. from the end of pulseEnablePin()).
//Allow the user to pass the pins to be used by the LCD in the constructor, and store them as member variables of the class instance.
//-------------------------------------------------------------


Gruß

Jürgen
Logged

Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ich habe mich mit der LiquidChrystal-Library beschäftigt und mein Display auch hier initialisiert.

Was bei diesem Display gut ist: 1. 3,3 - 5,0 Volt Betriebsspannung!
                                              2. Klein! Nur 7,5 x 2,5 cm !
                                              3. Zeilen sind 1,2,3,4 nicht 1,3,2,4 !

Weniger gut ist eigendlich nur der Pin-Abstand von 2,0 mm , so das ich mir 2 mm Adapterbuchsen bestellen mußte, die gab es leider nicht bei meinem Elektronik-Laden um die Ecke.  smiley-sad

Ich mußte mir einen Adapter auf Lochraster bauen, aber das war das einfachste!

Den init-code einfach ins Setup einfügen!

Hier mein Code:
Code:



LiquidCrystal lcd(12, 11, 2, 7, 8, 9, 10); //rw-pin auf Masse!


void setup()
{
  lcd.begin(20, 4);
  
  {
    lcd.command(0x01);//clear display
    delay(02);
    lcd.command(0x24);//function set RE=1
    delay(50);
    lcd.command(0x0C);//control, display on, cursor off, blinken off
    delay(50);
    lcd.command(0x20);//function set RE=0
    delay(50);
    lcd.command(0x06);//entry mode segment bidirectional
    delay(50);
    lcd.command(0x24);//function set RE=1
    delay(50);
    lcd.command(0x09);//extended function set, 4 lines, 5-dot fontwith
    delay(50);
    lcd.command(0x20);//function set RE=0
    delay(20);
    lcd.command(0x01);//clear display
 }
}


Dann in der cpp-Datei folgendes ändern:

int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
in   int row_offsets[] = { 0x00, 0x20, 0x40, 0x60 };

Gruß

Jürgen

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Schon fertig. Danke.  smiley
Logged

Pages: [1]   Go Up
Jump to: