Show Posts
Pages: [1] 2
1  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: Enhanced LiquidCrystal on: April 11, 2010, 09:27:15 am
Done!
http://www.arduino.cc/playground/Code/LCD <- second row
http://www.arduino.cc/playground/LCD/EnhancedLiquidCrystal

Anybody feel free to add more text!
2  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: Enhanced LiquidCrystal on: April 11, 2010, 07:28:22 am
Just wanted to thank jrraines for his libary!!
It works fine on a 27x4 LCD (4Bit mode).

How about putting it to the Playground??? I've started to make modifications by myself before I found your lib.
If you don't know how to do that, I can do it for you smiley-wink
3  Forum 2005-2010 (read only) / Syntax & Programs / Re: 1WireBus Problem (How to convert c++ to anduino) on: March 31, 2010, 08:02:58 pm
the C++ Code did not work at all!
How can I change that to work??
4  Forum 2005-2010 (read only) / Syntax & Programs / Problem with Constructor in libraries on: March 31, 2010, 04:46:10 pm
Hi
I have trouble to convert the C++ driver for a Digital Tsic Temperature Sensor to Arduino.
I've worked a lot and it's almost done but one error with the Constructor.
error:
In function 'void setup()':
error: expected unqualified-id before '.' token In function 'void loop()':

I used the instrucktion on: http://www.arduino.cc/en/Hacking/LibraryTutorial
But I'm not sure.... I've play around but couldn't get it to work (see out-Commented code).
I think I need a Constructor.
-> in Sketch,
-> tsic.h,
-> tsic.cpp
how can I do that?????


Sketch:
Code:
#include <tsic.h>

//tsic tsic1(12, 13);  //firstPin = VCC, secondPin = Signal

void setup(){
//TSIC_INIT();
tsic.TSIC_INIT();          // set data direction of IO-Pins
  }
void loop(){
    returnvalue = getTSicTemp(&temperatur);  // pull the TSIC-Sensor

    // conversion equation from TSic's data sheet
    Temp_celsius = ((float)temperatur / 2047 * 200) - 50;
  delay(1000);
  }

tsic.h
Code:
#ifndef tsic_H
#define tsic_H
#include <inttypes.h>
#include "WProgram.h"

class tsic {
public:
      //tsic(int Pin_VCC, int Pin_Sig);
      void TSIC_INIT();
      uint8_t getTSicTemp (uint16_t *temp_value16);

private:


};
#endif

tsic.cpp
Code:
#include "tsic.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
  #include "WProgram.h"
}

//defines:
#define TSCI_POWER_PIN 12                 // Where TSIC-Sensors VCC is connected
#define TSIC_SIGNAL_PIN 13            // Where TSIC-Sensors "Signal"-Pin is connected

#define TSIC_ON()                  digitalWrite(TSCI_POWER_PIN, HIGH)      // Power up the TSIC-Sensor
#define TSIC_OFF()                  digitalWrite(TSCI_POWER_PIN, LOW)      // Power down the TSIC-Sensor
#define TSIC_SIGNAL_HIGH      digitalRead(TSIC_SIGNAL_PIN)            //if TSIC_SIGNAL_PIN is high (=1)
#define TSIC_SIGNAL_LOW            !digitalRead(TSIC_SIGNAL_PIN)            //if TSIC_SIGNAL_PIN is low  (=0)

//Variablen:
uint8_t returnvalue;  // return value of getTSicTemp(*temp);
uint16_t temperatur;  // 11-bit temperature value
uint8_t Temp_celsius; // converted temperature in °C

//Konstrucktor
/*tsic::tsic(int Pin_VCC, int Pin_Sig)
{
      #define TSCI_POWER_PIN Pin_VCC                 // Where TSIC-Sensors VCC is connected
      #define TSIC_SIGNAL_PIN Pin_Sig            // Where TSIC-Sensors "Signal"-Pin is connected
}*/


void tsic::TSIC_INIT() {


  pinMode(TSCI_POWER_PIN, OUTPUT);            // sets the digital pin as output
  pinMode(TSIC_SIGNAL_PIN, INPUT);      // sets the digital pin as input
}

uint8_t tsic::getTSicTemp (uint16_t *temp_value16) {

  uint16_t temp_value1 = 0;
  uint16_t temp_value2 = 0;
  uint8_t i;
  uint16_t Temperature;
  uint8_t parity;

  TSIC_ON();
  delayMicroseconds(60);  // wait for stabilization
  delayMicroseconds(60);

  while (TSIC_SIGNAL_HIGH); // wait until start bit starts

  // wait, TStrobe
  while (TSIC_SIGNAL_LOW);

  // first data byte
  // read 8 data bits and 1 parity bit
  for (i = 0; i < 9; i++) {
    while (TSIC_SIGNAL_HIGH);              // wait for falling edge
    delayMicroseconds(60);
    if (TSIC_SIGNAL_HIGH)
        temp_value1 |= 1 << (8-i);         // get the bit
      else
        while (TSIC_SIGNAL_LOW);           // wait until line comes high again
  }

  // second byte
  while (TSIC_SIGNAL_HIGH);
  // wait, TStrobe
  while (TSIC_SIGNAL_LOW);
  // read 8 data bits and 1 parity bit
  for (i = 0; i < 9; i++) {
    while (TSIC_SIGNAL_HIGH);               // wait for falling edge
    delayMicroseconds(60);
    if (TSIC_SIGNAL_HIGH)
        temp_value2 |= 1 << (8-i);          // get the bit
      else
        while (TSIC_SIGNAL_LOW);            // wait until line comes high again
  }

  TSIC_OFF();                               // switch TSic off

  // check parity for byte 1
  parity = 0;
  for (i = 0; i < 9; i++)
    if (temp_value1 & (1 << i))
        parity++;
  if (parity % 2)
  return 0;

  // check parity for byte 2
  parity = 0;
  for (i = 0; i < 9; i++)
    if (temp_value2 & (1 << i))
        parity++;
  if (parity % 2)
        return 0;
  temp_value1 >>= 1;                 // delete parity bit
  temp_value2 >>= 1;                 // delete parity bit
  Temperature = (temp_value1 << 8) | temp_value2;
  *temp_value16 = Temperature;

  return 1;                       // parity is OK
}

the original whole C++ file:
Code:
/******************************************************************************
*
*  AVR Code example to read a TSIC-206 / TSIC-306 digital temperatur probe
*
*  Based on C++ Samplecode in
*  "Tech Notes - ZACwireTM Digital Output, Rev. 2.3, October 17, 2006"
*
*  Tested with ATMega8, avr-gcc (GCC) 4.3.0 and a TSIC-206
*
*  see also discussion at http://www.mikrocontroller.net/topic/82087
*
******************************************************************************/
#define F_CPU 8000000UL    // Clock of target system
#include <avr/io.h>
#include <util/delay.h>
/******************************************************************************
* Hardware Connection of the TSIC-Sensor
******************************************************************************/
#define TSIC_PORT             PORTD  // Port to use
#define TSIC_PIN              PIND
#define TSIC_PORT_DDR         DDRD
#define TSCI_POWER_PIN        PD6    // Where TSIC-Sensors VCC is connected
#define TSIC_SIGNAL_PIN       PD7    // Where TSIC-Sensors "Signal"-Pin is con.
/******************************************************************************
* FUNCTION MACROS
******************************************************************************/

// Define TSCI_POWER_PIN as output, TSIC_SIGNAL_PIN as input
#define TSIC_INIT()           { TSIC_PORT_DDR |= (1<<TSCI_POWER_PIN); \
                              TSIC_PORT_DDR &= ~(1<<TSIC_SIGNAL_PIN); }

// Power up the TSIC-Sensor
#define TSIC_ON()             TSIC_PORT |=  (1<<TSCI_POWER_PIN)

// Power down the TSIC-Sensor
#define TSIC_OFF()            TSIC_PORT &= ~(1<<TSCI_POWER_PIN)

//#define TSIC_SIGNAL           (TSIC_PORT &   (1<<TSIC_SIGNAL_PIN))

// Low/High Signal of the TSIC-Sensor, e.g. "if(TSIC_SIGNAL_HIGH)..."
#define TSIC_SIGNAL_HIGH      TSIC_PIN & ( 1 << TSIC_SIGNAL_PIN )
#define TSIC_SIGNAL_LOW       !( TSIC_PIN & ( 1 << TSIC_SIGNAL_PIN ))

/******************************************************************************
* Function    :   getTSicTemp(*temp_value16);
* Description :   reads from the TSic its output value
* Parameters  :   pointer for return value
* Returns     :   1: reading sucessfull, 0: parity error
******************************************************************************/
uint8_t getTSicTemp (uint16_t *temp_value16) {

  uint16_t temp_value1 = 0;
  uint16_t temp_value2 = 0;
  uint8_t i;
  uint16_t Temperature;
  uint8_t parity;

  TSIC_ON();
  _delay_us(60);  // wait for stabilization
  _delay_us(60);

  while (TSIC_SIGNAL_HIGH); // wait until start bit starts

  // wait, TStrobe
  while (TSIC_SIGNAL_LOW);

  // first data byte
  // read 8 data bits and 1 parity bit
  for (i = 0; i < 9; i++) {
    while (TSIC_SIGNAL_HIGH);              // wait for falling edge
    _delay_us(60);
    if (TSIC_SIGNAL_HIGH)
        temp_value1 |= 1 << (8-i);         // get the bit
      else
        while (TSIC_SIGNAL_LOW);           // wait until line comes high again
  }

  // second byte
  while (TSIC_SIGNAL_HIGH);
  // wait, TStrobe
  while (TSIC_SIGNAL_LOW);
  // read 8 data bits and 1 parity bit
  for (i = 0; i < 9; i++) {
    while (TSIC_SIGNAL_HIGH);               // wait for falling edge
    _delay_us(60);
    if (TSIC_SIGNAL_HIGH)
        temp_value2 |= 1 << (8-i);          // get the bit
      else
        while (TSIC_SIGNAL_LOW);            // wait until line comes high again
  }

  TSIC_OFF();                               // switch TSic off

  // check parity for byte 1
  parity = 0;
  for (i = 0; i < 9; i++)
    if (temp_value1 & (1 << i))
        parity++;
  if (parity % 2)
  return 0;

  // check parity for byte 2
  parity = 0;
  for (i = 0; i < 9; i++)
    if (temp_value2 & (1 << i))
        parity++;
  if (parity % 2)
        return 0;
  temp_value1 >>= 1;                 // delete parity bit
  temp_value2 >>= 1;                 // delete parity bit
  Temperature = (temp_value1 << 8) | temp_value2;
  *temp_value16 = Temperature;

  return 1;                       // parity is OK
}


/******************************************************************************
* Test application
******************************************************************************/
int main (void) {

  uint16_t temperatur;  // 11-bit temperature value
  uint8_t returnvalue;  // return value of getTSicTemp(*temp);
  uint8_t Temp_celsius; // converted temperature in °C

  TSIC_INIT();          // set data direction of IO-Pins

  while(1){
    returnvalue = getTSicTemp(&temperatur);  // pull the TSIC-Sensor
    // conversion equation from TSic's data sheet
    Temp_celsius = ((float)temperatur / 2047 * 200) - 50;
  }
}

thanks for Comments!!
The Post was totally edited, so the next 3 Answers don't don't fit anymore
5  Forum 2005-2010 (read only) / Development / Re: adapting LCD driver Mitsubishi Chip M50530 on: December 05, 2009, 05:03:04 pm
thanks to PaulS!
It is now compiling...

It still doesn't work.. but first steps are made..


I've been looking for other errors since hours..
I'm about to give up since my possibilities to diagnostics are rare..
Arduino has no debug feature, I'm not even sure if the LCD is hooked up right..
or is just somewhere a bug in the code????? Too many question...
6  Forum 2005-2010 (read only) / Development / Re: adapting LCD driver Mitsubishi Chip M50530 on: December 04, 2009, 05:13:22 am
The error is in the Arduino Code line: "LCD_write("LCD - 16x4");"
But I suspect it must be somewhere in the driver file..
I searched already for every "char" but there is always an "unsigned" before it, so I'm confused..
Any suggestions??
7  Forum 2005-2010 (read only) / Development / Re: adapting LCD driver Mitsubishi Chip M50530 on: December 03, 2009, 06:26:56 pm
UPDATE:

Only 1 Error
"error: invalid conversion from 'const char*' to 'const unsigned char*"

lcd-m50530.h    <--- ..\hardware\libraries\lcd_m50530
Code:
#ifndef LCD_M50530_H
#define LCD_M50530_H
#include <avr/delay.h>

/****************************************************************
Ggf. hier den Port anpassen, an dem das LCD angeschlossen ist!
****************************************************************/
// Data-Direction-Register, am dem das LCD angeschlossen ist
#define LCD_DDR DDRD
// Port-Register, am dem das LCD angeschlossen ist
#define LCD_PORT PORTD
// Pin-Register, am dem das LCD angeschlossen ist
#define LCD_PIN PIND


/*************************************************
Ggf. hier die Bits der 4 Steuerleitungen anpassen!
*************************************************/
// Die Datenleitungen des LCDs müssen an den Pins 0-3 anliegen (Data0 auf Pin0, Data1 auf Pin1 usw.)
// Die anderen 4 Steuerleitungen sind hier einzustellen!
// Port-Pin, an dem der RW-Pin des LCDs liegt
#define LCD_RW_PIN 13
// Port-Pin, an dem der EX-Pin des LCDs liegt
#define LCD_EX_PIN 5
// Port-Pin, an dem der OC1-Pin des LCDs liegt
#define LCD_OC1_PIN 6
// Port-Pin, an dem der OC2-Pin des LCDs liegt
#define LCD_OC2_PIN 4


// ein paar Konstanten zur besseren Lesbarkeit des Quelltextes :-)
#define LCD_DISPLAY_ON            16
#define LCD_CURSOR_ON            8
#define LCD_UNDERLINE            4
#define LCD_CURSOR_BLINK      2
#define LCD_CHARACTER_BLINK      1


#define LCD_CURSOR_ADDRESS_NO_CHANGE      64
#define LCD_CURSOR_ADDRESS_INC_RD            72
#define LCD_CURSOR_ADDRESS_INC_WD            80
#define LCD_CURSOR_ADDRESS_INC_RDWD            88
#define LCD_CURSOR_ADDRESS_DEC_RD            104
#define LCD_CURSOR_ADDRESS_DEC_WD            112
#define LCD_CURSOR_ADDRESS_DEC_RDWD            120

#define LCD_DISPLAY_START_ADDRESS_NO_CHANGE      64
#define LCD_DISPLAY_START_ADDRESS_INC_RD      65
#define LCD_DISPLAY_START_ADDRESS_INC_WD      66
#define LCD_DISPLAY_START_ADDRESS_INC_RDWD      67
#define LCD_DISPLAY_START_ADDRESS_DEC_RD      69
#define LCD_DISPLAY_START_ADDRESS_DEC_WD      70
#define LCD_DISPLAY_START_ADDRESS_DEC_RDWD      71

#define LCD_SPECIAL_AE                                    (char)144      // Ä, dezimal 144, oktal 220
#define LCD_SPECIAL_OE                                    (char)145      // Ö, dezimal 145, oktal 221
#define LCD_SPECIAL_UE                                    (char)197      // Ü, dezimal 197, oktal 305
#define LCD_SPECIAL_ae                                    (char)160      // ä, dezimal 160, oktal 240
#define LCD_SPECIAL_oe                                    (char)161      // ö, dezimal 161, oktal 241
#define LCD_SPECIAL_ue                                    (char)17      // ü, dezimal 17, oktal 21
#define LCD_SPECIAL_ss                                    (char)163      // ß,  dezimal 163, oktal 243

// sendet den angelegten Befehl zum LCD
// setzt kurzzeitig das EX-Signal und nimmt es anschließend wieder zurück
extern void LCD_execute(void);

// wartet solange bis das Busy-Flag nicht mehr gesetzt ist
// und das LCD weitere Befehle entgegennimmt
extern void LCD_waitReady(void);

// überträgt das übergebene Byte an das LCD
extern void LCD_sendByte(const unsigned char byte, unsigned char control);

// setzt 4-Bit-Mode und initialisiert das LCD
// muss als erstes aufgerufen werden, bevor das LCD angesteuert werden kann
extern void LCD_init(void);

// löscht die Anzeige und setzt die Display + Cursor-Adresse auf 0,0
extern void LCD_clear(void);

// setzt den Entry-Mode des LCDs, also die automatische Erhöhung der Adresse nach einem Lese- oder Schreibbefehl
// man verwende die oben deklarierten Konstanten ;)
#define LCD_setEntryMode(mode)                  LCD_sendByte(mode, 0)

// schreibt das übergebene Zeichen an die aktuelle Cursor-Position
#define LCD_writeChar(c)                        LCD_sendByte(c, 1 << LCD_OC2_PIN)

// schreibt die übergebene Zeichenkette an die aktuelle Cursor-Position
extern void LCD_write(const unsigned char * c);

// schreibt die übergebene Zeichenkette an die aktuelle Cursor-Position (für String im ROM)
extern void LCD_write_P(const unsigned char * progmem_string);

// setzt den Display-Modus
// man verwende die oben deklarierten Konstanten ;)
#define LCD_setDisplay(mode)                  LCD_sendByte(mode | 32, 0)

// setzt den Cursor an die angegebene Adresse
#define LCD_setCursorAddress(address)      LCD_sendByte(address, (1<<LCD_OC1_PIN) | (1<<LCD_OC2_PIN))

// setzt den Cursor an die angegebene Position (y = Zeile, x = Spalte)
extern void LCD_setCursorPos(const unsigned char y, const unsigned char x);

#endif

lcd-m50530.c    <--- ..\hardware\libraries\lcd_m50530
Code:
#include <avr/io.h>
#include <avr/pgmspace.h>
#include "lcd-m50530.h"
#include <stdlib.h>


// sendet den angelegten Befehl zum LCD
// setzt kurzzeitig das EX-Signal und nimmt es anschließend wieder zurück
void LCD_execute(void)
{
      _delay_us(2);
      // EX-Signal setzen
      LCD_PORT |= (1 << LCD_EX_PIN);
      _delay_us(2);
      // EX-Signal löschen
      LCD_PORT &= ~(1 << LCD_EX_PIN);
      _delay_us(2);
}


// wartet solange bis das Busy-Flag nicht mehr gesetzt ist
// und das LCD weitere Befehle entgegennimmt
void LCD_waitReady(void)
{
      // Datenleitungen auf Eingang schalten
      // dazu die Bits der Datenleitungen auf 0 setzen
      LCD_DDR &= 240;

      // RB-Befehl senden
      //LCD_PORT = (1 << LCD_OC1_PIN) | (1 << LCD_OC2_PIN) | (1 << LCD_RW_PIN);
      LCD_PORT = 1 << LCD_RW_PIN;
      
      unsigned char flags = 0;
      while (1)
      {
            do
            {
                  _delay_us(2);
                  // EX-Signal setzen
                  LCD_PORT |= (1 << LCD_EX_PIN);
                  _delay_us(2);
                  // flags einlesen
                  flags = LCD_PIN;
                  // EX-Signal löschen
                  LCD_PORT &= ~(1 << LCD_EX_PIN);
            } while (bit_is_set(flags, 3));
            
            if (flags & 6)
                  // bits 1 oder 2 gesetzt, also entweder sind wie im 8bit-mode oder wir haben gerade den zweiten Teil im 4bit-mode gelesen
                  break;
      }
      // alle Leitungen als Ausgänge schalten
      LCD_DDR = 0xFF;
}


// überträgt das übergebene Byte an das LCD
void LCD_sendByte(const unsigned char byte, unsigned char control)
{
      LCD_waitReady();
      // die unteren 5 Bits im Control-Byte ausblenden
      control &= 224;
      // oberes Nibble übertragen
      LCD_PORT = (byte >> 4) | control;
      LCD_execute();
      // unteres Nibble übertragen
      LCD_PORT = (byte & 15) | control;
      LCD_execute();
}



// löscht die Anzeige und setzt die Display + Cursor-Adresse auf 0,0
void LCD_clear(void)
{
      LCD_sendByte(1, 0);      // DB0
      _delay_ms(2);
}


// setzt 4-Bit-Mode und initialisiert das LCD
// muss als erstes aufgerufen werden, bevor das LCD angesteuert werden kann
void LCD_init(void)
{
      // alle Leitungen auf Ausgang schalten
      LCD_DDR = 0xFF;

      // auf 4-Bit-Mode umschalten
      LCD_sendByte(216, 0);      // DB7, DB6, DB4, DB3
      LCD_clear();
}


// schreibt die übergebene Zeichenkette an die aktuelle Cursor-Position
void LCD_write(const unsigned char * c)
{
    while (*c)
      LCD_writeChar(*c++);
}


// schreibt die übergebene Zeichenkette an die aktuelle Cursor-Position (für String im ROM)
void LCD_write_P(const unsigned char * progmem_string)
{
      register unsigned char c;
      while ((c = pgm_read_byte(progmem_string++)))
            LCD_writeChar(c);
}


// setzt den Cursor an die angegebene Position (y = Zeile, x = Spalte)
void LCD_setCursorPos(const unsigned char y, const unsigned char x)
{
      // Adresse aus x und y berechnen
      // Adressen sind wie folgt: Zeile 0 = 0; Zeile 1 = 64; Zeile 2 = 128; Zeile 3 = 192; Zeile 4 = 0+24; Zeile 5 = 64+24; Zeile 6 = 128+24; Zeile 7 = 192+24
      unsigned char address = x + ((y % 4) << 6);
      if (y > 3)
            address += 24;
      LCD_sendByte(address, (1<<LCD_OC1_PIN) | (1<<LCD_OC2_PIN));
}

LCD.pde   <--- for testing
Code:
#include <avr/io.h>
#include <lcd-m50530.h>


void setup()
{
// wait for power up
      delay(250);

      // LCD initialisieren
      LCD_init();

      // ein paar Zeichen ausgeben
      LCD_write("LCD - 16x4");
}

void loop()
{

}

does anyone know where the error is?
Is the Arduino Code right?
Or is it some were in the libraries??

Thank for any Help!!
8  Forum 2005-2010 (read only) / Development / Re: adapting LCD driver Mitsubishi Chip M50530 on: November 28, 2009, 02:42:31 pm
lcd-m50530.c    <--- ..\hardware\libraries
Code:
/***********************************************************

      LCD-Routinen
      für Samsung 2138a mit M50530-Controller
      24 x 8 Zeichen

      Copyright 2003-04 by Daniel Jelkmann


      Zur Ansteuerung wird der 4Bit-Mode verwendet.
      Neben den 4 Datenleitungen (Data0-3) werden 4 weitere
      Steuerleitungen (Read/Write, Execute, OC1, OC2)
      benötigt. Damit werden am AVR 8 Pins benötigt.

      
      Anschluss:
      
      Alle 8 LCD-Signale müssen an einem Port des AVR
      angeschlossen werden. Gemäß folgender Tabelle müssen
      die 4 Datenleitungen an den niederwertigsten Bits
      anliegen. Die Reihenfolge der restlichen 4 Steuerleitungen
      und der verwendete Port ist über die Konstanten im
      Quellcode festgelegt und muss ggf. angepasst werden.
      Die restlichen LCD-Signale sind in folgender Tabelle
      zu finden.

            LCD      Beschreibung            Anschluss
            -------------------------------------------------------------------------
            Pin 01      Masse                  Masse
            Pin 02      Data0                  nicht angeschlossen
            Pin 03      Data1                  nicht angeschlossen
            Pin 04      Data2                  nicht angeschlossen
            Pin 05      Data3                  nicht angeschlossen
            Pin 06      Data4                  AVR Port Bit 0
            Pin 07      Data5                  AVR Port Bit 1
            Pin 08      Data6                  AVR Port Bit 2
            Pin 09      Data7                  AVR Port Bit 3
            Pin 10      EX (Execute)            AVR Port Bit 4*
            Pin 11      R/W (Read/Write)      AVR Port Bit 5*
            Pin 12      OC2                        AVR Port Bit 7*
            Pin 13      OC1                        AVR Port Bit 6*
            Pin 14      Kontrast-Regelung, ungefähr 8,2 Volt, am besten mittels Poti anschließen
            Pin 15      Versorgungsspannung, +5 Volt
            Pin 16      Masse                  Masse


      
      * Die Reihenfolge dieser Leitungen kann über die
      Konstanten im Quellcode angepasst werden.
      
      
      Es wird keine Gewähr für die Vollständigkeit, Korrektheit,
      Funktionsfähigkeit oder für sonstige Eigenschaften des
      Codes übernommen. Haftung ausgeschlossen.
      
*************************************************************/


#include <avr/io.h>
//#include <avr/delay.h>
#include <avr/pgmspace.h>

#include "lcd-m50530.h"

#include <stdlib.h>


/*
// wartet die angegebene Zeit in Millisekunden
// F_MCU muss entsprechend gesetzt sein
// (benötigt delay.h)
void delay(const unsigned int ms)
{
      for (unsigned char i = ms; i > 0; --i)
            // 4 cycles per loop * 250 = 1.000 cycles; 1.000 x F_MCU = 1 ms
            _delay_loop_2(250*F_MCU);
}*/


// sendet den angelegten Befehl zum LCD
// setzt kurzzeitig das EX-Signal und nimmt es anschließend wieder zurück
void LCD_execute(void)
{
      delay_short();
      // EX-Signal setzen
      LCD_PORT |= (1 << LCD_EX_PIN);
      delay_short();
      // EX-Signal löschen
      LCD_PORT &= ~(1 << LCD_EX_PIN);
      delay_short();
}


// wartet solange bis das Busy-Flag nicht mehr gesetzt ist
// und das LCD weitere Befehle entgegennimmt
void LCD_waitReady(void)
{
      /*
            READ BUSY FLAG & FUNCTION FLAGS (RB)
            input:
                  OC1            0
                  OC2            0
                  RW            1
            output:
                  DB7            busy-flag (1 = busy)
      */

      // Datenleitungen auf Eingang schalten
      // dazu die Bits der Datenleitungen auf 0 setzen
      LCD_DDR &= 240;

      // RB-Befehl senden
      //LCD_PORT = (1 << LCD_OC1_PIN) | (1 << LCD_OC2_PIN) | (1 << LCD_RW_PIN);
      LCD_PORT = 1 << LCD_RW_PIN;
      
      unsigned char flags = 0;
      while (1)
      {
            do
            {
                  delay_short();
                  // EX-Signal setzen
                  LCD_PORT |= (1 << LCD_EX_PIN);
                  delay_short();
                  // flags einlesen
                  flags = LCD_PIN;
                  // EX-Signal löschen
                  LCD_PORT &= ~(1 << LCD_EX_PIN);
            } while (bit_is_set(flags, 3));
            
            if (flags & 6)
                  // bits 1 oder 2 gesetzt, also entweder sind wie im 8bit-mode oder wir haben gerade den zweiten Teil im 4bit-mode gelesen
                  break;
      }
            
      
/*      unsigned char busy;
      do
      {
            delay_short();
            LCD_execute();
            // busy-Signal einlesen
            busy = bit_is_set(LCD_PIN, 3);
            LCD_execute();
      } while (busy);
*/
      
      // alle Leitungen als Ausgänge schalten
      LCD_DDR = 0xFF;
}


// überträgt das übergebene Byte an das LCD
void LCD_sendByte(const unsigned char byte, unsigned char control)
{
      LCD_waitReady();
      // die unteren 5 Bits im Control-Byte ausblenden
      control &= 224;
      // oberes Nibble übertragen
      LCD_PORT = (byte >> 4) | control;
      LCD_execute();
      // unteres Nibble übertragen
      LCD_PORT = (byte & 15) | control;
      LCD_execute();
}



// löscht die Anzeige und setzt die Display + Cursor-Adresse auf 0,0
void LCD_clear(void)
{
      /*
            CLEAR DISPLAY, MOVE DISPLAY/CURSOR ADDRESS HOME
            input:
                  OC1            0
                  OC2            0
                  RW            0
                  DB7-DB1      0
                  DB0            1
      */
      LCD_sendByte(1, 0);      // DB0
      delay(2);
}


// setzt 4-Bit-Mode und initialisiert das LCD
// muss als erstes aufgerufen werden, bevor das LCD angesteuert werden kann
void LCD_init(void)
{
      // alle Leitungen auf Ausgang schalten
      LCD_DDR = 0xFF;

      // auf 4-Bit-Mode umschalten
      /*
            SET FUNCTION MODE
            input:
                  OC1            0
                  OC2            0
                  RW            0
                  DB7,DB6      1
                  DB5            I/O 8/4      (1 = 8 bit, 0 = 4 bit)
                  DB4            FONT 8/12 (1 = 5x8 fonts, 0 = 5x12 fonts)
                  DB3,DB2      DUTY
                  DB1,DB0      RAM
      */
      LCD_sendByte(216, 0);      // DB7, DB6, DB4, DB3
      LCD_clear();
}


// schreibt die übergebene Zeichenkette an die aktuelle Cursor-Position
void LCD_write(const unsigned char * c)
{
    while (*c)
      LCD_writeChar(*c++);
}


// schreibt die übergebene Zeichenkette an die aktuelle Cursor-Position (für String im ROM)
void LCD_write_P(const unsigned char * progmem_string)
{
      register unsigned char c;
      while ((c = pgm_read_byte(progmem_string++)))
            LCD_writeChar(c);
}


// setzt den Cursor an die angegebene Position (y = Zeile, x = Spalte)
void LCD_setCursorPos(const unsigned char y, const unsigned char x)
{
      // Adresse aus x und y berechnen
      // Adressen sind wie folgt: Zeile 0 = 0; Zeile 1 = 64; Zeile 2 = 128; Zeile 3 = 192; Zeile 4 = 0+24; Zeile 5 = 64+24; Zeile 6 = 128+24; Zeile 7 = 192+24
      unsigned char address = x + ((y % 4) << 6);
      if (y > 3)
            address += 24;
      LCD_sendByte(address, (1<<LCD_OC1_PIN) | (1<<LCD_OC2_PIN));
}
9  Forum 2005-2010 (read only) / Development / Re: adapting LCD driver Mitsubishi Chip M50530 on: November 28, 2009, 02:41:57 pm
lcd-m50530.h    <--- ..\hardware\libraries
Code:
/***********************************************************

      LCD-Routinen
      für Samsung 2138a mit M50530-Controller
      24 x 8 Zeichen

      Copyright 2003 by Daniel Jelkmann


      Zur Ansteuerung wird der 4Bit-Mode verwendet.
      Neben den 4 Datenleitungen (Data0-3) werden 4 weitere
      Steuerleitungen (Read/Write, Execute, OC1, OC2)
      benötigt. Damit werden am AVR 8 Pins benötigt.

      
      Anschluss:
      
      Alle 8 LCD-Signale müssen an einem Port des AVR
      angeschlossen werden. Gemäß folgender Tabelle müssen
      die 4 Datenleitungen an den niederwertigsten Bits
      anliegen. Die Reihenfolge der restlichen 4 Steuerleitungen
      und der verwendete Port ist über die Konstanten im
      Quellcode festgelegt und muss ggf. angepasst werden.
      Die restlichen LCD-Signale sind in folgender Tabelle
      zu finden.

            LCD      Beschreibung            Anschluss
            -------------------------------------------------------------------------
            Pin 01      Masse                  Masse
            Pin 02      Data0                  nicht angeschlossen
            Pin 03      Data1                  nicht angeschlossen
            Pin 04      Data2                  nicht angeschlossen
            Pin 05      Data3                  nicht angeschlossen
            Pin 06      Data4                  AVR Port Bit 0
            Pin 07      Data5                  AVR Port Bit 1
            Pin 08      Data6                  AVR Port Bit 2
            Pin 09      Data7                  AVR Port Bit 3
            Pin 10      EX (Execute)            AVR Port Bit 5*
            Pin 11      R/W (Read/Write)      AVR Port Bit 4*
            Pin 12      OC2                        AVR Port Bit 7*
            Pin 13      OC1                        AVR Port Bit 6*
            Pin 14      Kontrast-Regelung, ungefähr 8,2 Volt, am besten mittels Poti anschließen
            Pin 15      Versorgungsspannung, +5 Volt
            Pin 16      Masse                  Masse


      
      * Die Reihenfolge dieser Leitungen kann über die
      Konstanten im Quellcode angepasst werden.
      
      
      Es wird keine Gewähr für die Vollständigkeit, Korrektheit,
      Funktionsfähigkeit oder für sonstige Eigenschaften des
      Codes übernommen. Haftung ausgeschlossen.
      
*************************************************************/

#ifndef LCD_M50530_H
#define LCD_M50530_H

#include <avr/delay.h>


//#define F_MCU                         5            /* Takt-Frequenz in MHz */


// wartet die angegebene Zeit in Millisekunden
// XTAL_CPU muss entsprechend gesetzt sein
// (benötigt delay.h)
//extern void delay(unsigned int ms);
#define delay(ms)            for (unsigned int i = ms; i > 0; --i)      \
                                          _delay_loop_2(XTAL_CPU / 4000);
//                                          _delay_loop_2(250*F_MCU);


/****************************************************************
Ggf. hier den Port anpassen, an dem das LCD angeschlossen ist!
****************************************************************/
// Data-Direction-Register, am dem das LCD angeschlossen ist
#define LCD_DDR DDRA
// Port-Register, am dem das LCD angeschlossen ist
#define LCD_PORT PORTA
// Pin-Register, am dem das LCD angeschlossen ist
#define LCD_PIN PINA


/*************************************************
Ggf. hier die Bits der 4 Steuerleitungen anpassen!
*************************************************/
// Die Datenleitungen des LCDs müssen an den Pins 0-3 anliegen (Data0 auf Pin0, Data1 auf Pin1 usw.)
// Die anderen 4 Steuerleitungen sind hier einzustellen!
// Port-Pin, an dem der RW-Pin des LCDs liegt
#define LCD_RW_PIN 13
// Port-Pin, an dem der EX-Pin des LCDs liegt
#define LCD_EX_PIN 5
// Port-Pin, an dem der OC1-Pin des LCDs liegt
#define LCD_OC1_PIN 6
// Port-Pin, an dem der OC2-Pin des LCDs liegt
#define LCD_OC2_PIN 4


// ein paar Konstanten zur besseren Lesbarkeit des Quelltextes :-)
#define LCD_DISPLAY_ON            16
#define LCD_CURSOR_ON            8
#define LCD_UNDERLINE            4
#define LCD_CURSOR_BLINK      2
#define LCD_CHARACTER_BLINK      1


#define LCD_CURSOR_ADDRESS_NO_CHANGE      64
#define LCD_CURSOR_ADDRESS_INC_RD            72
#define LCD_CURSOR_ADDRESS_INC_WD            80
#define LCD_CURSOR_ADDRESS_INC_RDWD            88
#define LCD_CURSOR_ADDRESS_DEC_RD            104
#define LCD_CURSOR_ADDRESS_DEC_WD            112
#define LCD_CURSOR_ADDRESS_DEC_RDWD            120

#define LCD_DISPLAY_START_ADDRESS_NO_CHANGE      64
#define LCD_DISPLAY_START_ADDRESS_INC_RD      65
#define LCD_DISPLAY_START_ADDRESS_INC_WD      66
#define LCD_DISPLAY_START_ADDRESS_INC_RDWD      67
#define LCD_DISPLAY_START_ADDRESS_DEC_RD      69
#define LCD_DISPLAY_START_ADDRESS_DEC_WD      70
#define LCD_DISPLAY_START_ADDRESS_DEC_RDWD      71


#define LCD_SPECIAL_AE                                    (char)144      // Ä, dezimal 144, oktal 220
#define LCD_SPECIAL_OE                                    (char)145      // Ö, dezimal 145, oktal 221
#define LCD_SPECIAL_UE                                    (char)197      // Ü, dezimal 197, oktal 305
#define LCD_SPECIAL_ae                                    (char)160      // ä, dezimal 160, oktal 240
#define LCD_SPECIAL_oe                                    (char)161      // ö, dezimal 161, oktal 241
#define LCD_SPECIAL_ue                                    (char)17      // ü, dezimal 17, oktal 21
#define LCD_SPECIAL_ss                                    (char)163      // ß,  dezimal 163, oktal 243


// wartet einen kurzen Moment, 4 cycles per loop * 8 = 32 cycles, macht bei 16 MHz 2 µs
#define delay_short()      _delay_loop_2(8)


// sendet den angelegten Befehl zum LCD
// setzt kurzzeitig das EX-Signal und nimmt es anschließend wieder zurück
extern void LCD_execute(void);


// wartet solange bis das Busy-Flag nicht mehr gesetzt ist
// und das LCD weitere Befehle entgegennimmt
extern void LCD_waitReady(void);


// überträgt das übergebene Byte an das LCD
extern void LCD_sendByte(const unsigned char byte, unsigned char control);


// setzt 4-Bit-Mode und initialisiert das LCD
// muss als erstes aufgerufen werden, bevor das LCD angesteuert werden kann
extern void LCD_init(void);

// löscht die Anzeige und setzt die Display + Cursor-Adresse auf 0,0
extern void LCD_clear(void);


// setzt den Entry-Mode des LCDs, also die automatische Erhöhung der Adresse nach einem Lese- oder Schreibbefehl
// man verwende die oben deklarierten Konstanten ;)
#define LCD_setEntryMode(mode)                  LCD_sendByte(mode, 0)


// schreibt das übergebene Zeichen an die aktuelle Cursor-Position
#define LCD_writeChar(c)                        LCD_sendByte(c, 1 << LCD_OC2_PIN)


// schreibt die übergebene Zeichenkette an die aktuelle Cursor-Position
extern void LCD_write(const unsigned char * c);

// schreibt die übergebene Zeichenkette an die aktuelle Cursor-Position (für String im ROM)
extern void LCD_write_P(const unsigned char * progmem_string);


// setzt den Display-Modus
// man verwende die oben deklarierten Konstanten ;)
#define LCD_setDisplay(mode)                  LCD_sendByte(mode | 32, 0)


// setzt den Cursor an die angegebene Adresse
#define LCD_setCursorAddress(address)      LCD_sendByte(address, (1<<LCD_OC1_PIN) | (1<<LCD_OC2_PIN))


// setzt den Cursor an die angegebene Position (y = Zeile, x = Spalte)
extern void LCD_setCursorPos(const unsigned char y, const unsigned char x);

#endif

LCD.pde   <--- for testing
Code:
#include <avr/io.h>
#include <lcd-m50530.h>


void setup()
{
// wait for power up
      delay(250);

      // LCD initialisieren
      LCD_init();
      // Modus des LCDs ändern
      LCD_setEntryMode(LCD_CURSOR_ADDRESS_INC_WD | LCD_DISPLAY_START_ADDRESS_NO_CHANGE);
      // Cursor einschalten
      LCD_setDisplay(LCD_DISPLAY_ON | LCD_CURSOR_ON | LCD_CURSOR_BLINK | LCD_CHARACTER_BLINK);


      // ein paar Zeichen ausgeben
      LCD_write("LCD - 24x8 characters");
      LCD_setCursorPos(1,5);
      LCD_write("Samsung 2138a");
      LCD_setCursorPos(7, 21);
      LCD_write(":-)");
      LCD_setCursorPos(4, 0);
      LCD_write("test successful");
}

void loop()
{
  pin13=HIGH;
}
10  Forum 2005-2010 (read only) / Development / adapting LCD driver Mitsubishi Chip M50530 on: November 28, 2009, 01:27:20 pm
Hi
I've found one driver already. It is originally for some Atmel microcontroller and is written in C.
I want to adapt it to Arduino.
This driver for a LCD with a Mitsubishi Chip M50530.
 The "lcd_m50530" Folder come in the "...\hardware\libraries".
 "LCD.pde" is my test Project.
 
 Arduino IDE says: " 'PORTA' undeclared " and a lot more... smiley-wink
 
 "PORTA" is Port A as used in "lcd-m50530.h" and I need o change it an Arduino Pin.
 My LCD is connected with 4 DataBus Pins to the Arduino, how can I make out of PORTA 4 Pin?
 
 Sorry for that kind of Questions and if I mixed up some things I'm totally new to Arduino...
 First I need my LCD to work, later I can test the other Hardware and display them on the LCD..
 The most difficult thing has to be done first

EDIT: I have included the code in my next 2 posts:

In the .zip is the same
http://rapidshare.de/files/48754617/M50530.zip.html
11  Forum 2005-2010 (read only) / Development / ATmega16 (non Ardui) code to Duemilanove ATmega328 on: March 16, 2010, 02:58:39 pm
Hi
I have driverfiles (LCD with M50530 chip) from a ATmega16 (not Arduino).
m50530.c
Code:
#include "m50530.h"
#include <util/delay.h>
#include <avr/pgmspace.h>

void LCDToggleEX(void)
{
  //_delay_us(5);

  LCDCTRLPORT |= _BV(LCDPIN_EX);
  
  _delay_us(2);  // 10

  LCDCTRLPORT &= ~_BV(LCDPIN_EX);

  //_delay_us(5);
}

int LCDIsBusy(void)
{
  unsigned char lInpData = 0;
  int lBusyFlag = 0;
  int l4BitFlag = 0;

    // data port set up to input
  LCDDATADIR &= 0xf0;
  
    // set RW signal
  LCDCTRLPORT |= _BV(LCDPIN_RW);

    // delay?
  //_delay_us(5);  

    // set EX signal
  LCDCTRLPORT |= _BV(LCDPIN_EX);

    // delay?
  //_delay_us(2); // 10

    // read 1st nibble
  lInpData = LCDDATAPIN;

    // clear EX signal
  LCDCTRLPORT &= ~_BV(LCDPIN_EX);

  lBusyFlag =  ( lInpData & (1 << 3) );
  l4BitFlag = !( lInpData & (1 << 2) );

    // delay?
  //_delay_us(5);  

    // read 2nd nibble
  if ( l4BitFlag )
  {
      // set EX signal
    LCDCTRLPORT |= _BV(LCDPIN_EX);

      // delay?
    //_delay_us(2);  // 10

      // read 2nd nibble
    LCDDATAPIN;

      // clear EX signal
    LCDCTRLPORT &= ~_BV(LCDPIN_EX);
  }

  //_delay_us(10);

    // clear RW signal
  LCDCTRLPORT &= ~_BV(LCDPIN_RW);

    // set data port back to output
  LCDDATADIR |= 0x0f;
    // clear data outputs
  LCDDATAPORT &= 0xf0;

  return lBusyFlag;
}

void LCDSend(unsigned char AControl, unsigned char AData)
{
  unsigned char lHN = ( AData & 0xf0 ) >> 4;
  unsigned char lLN = ( AData & 0x0f );
  
  while ( LCDIsBusy() )
    ;

  LCDCTRLPORT &= ~(_BV(LCDPIN_RW) | _BV(LCDPIN_IOC1) | _BV(LCDPIN_IOC2) | _BV(LCDPIN_EX));
  LCDCTRLPORT |= AControl;

  LCDDATAPORT &= 0xf0;
  LCDDATAPORT |= lHN;

  LCDToggleEX();

  LCDDATAPORT &= 0xf0;
  LCDDATAPORT |= lLN;
  
  LCDToggleEX();

  LCDDATAPORT &= 0xf0;
  LCDCTRLPORT &= ~AControl;

  //_delay_us(20);
}

void LCDInit(void)
{
    // port setup
  LCDDATADIR |= 0x0f;
  LCDCTRLDIR |= _BV(LCDPIN_RW) | _BV(LCDPIN_IOC1) | _BV(LCDPIN_IOC2) | _BV(LCDPIN_EX);
  
    // SF - Set Function Mode
      //  >> 4 Bit I/O, 5x8 Font, 1/32 duty
      //      >> 4 lines x 40 words, 96 words CG RAM
  LCDSend( 0, LCD_CMD_SETFUNCTIONMODE | sfIO4BIT | sfFont5x8 | 0x0B );

    // SE - Set Entry Mode
  LCDSend( 0, LCD_CMD_SETENTRYMODE | emCursorIncWrite );

    // SU - Set Underline Mode
  LCDSend( 0, LCD_CMD_SETUNDERLINEMODE | suNoUnderline );

    // SB - Set Blinking Frequency
  LCDSend( 0, LCD_CMD_SETBLINKINGFREQUENCY | sbNormal );

    // SD - Set Display Mode
  LCDSend( 0, LCD_CMD_SETDISPLAYMODE | dmDisplayOn /*| dmCursorOn*/ | dmCursorBlink);

    // CH - Clear Cursor of DD RAM display data home & display start address home
  LCDSend( 0, LCD_CMD_CLEARCURSORDATAADDRHOME );

  _delay_ms(2);
}

  // setzt den Cursor an die angegebene Position (y = Zeile, x = Spalte)
void LCDSetCursorPos(const unsigned char y, const unsigned char x)
{
    // Adresse aus x und y berechnen
    // Adressen sind wie folgt: Zeile 0 = 0; Zeile 1 = 40; Zeile 2 = 80; Zeile 3 = 120; Zeile 4 = 160; Zeile 5 = 64+24; Zeile 6 = 128+24; Zeile 7 = 192+24
  unsigned char address = x + (y*40);

  LCDSend(_BV(LCDPIN_IOC1)|_BV(LCDPIN_IOC2), address);
}

  // schreibt die übergebene Zeichenkette an die aktuelle Cursor-Position
void LCDWrite(const char * c)
{
  while (*c)
    LCDWriteChar(*c++);
}

  // schreibt die übergebene Zeichenkette aus dem Programmspeicher
  // an die aktuelle Cursor-Position
void LCDWritePGM(const char * c)
{
  uint8_t b;

  while ( (b = pgm_read_byte(c++)) )
        LCDWriteChar(b);
}
m50530.h
Code:
#ifndef M50530_H
#define M50530_H
#include <avr/io.h>

  // Data and Control signals can be connected to different ports!

  // data port, LCD signals DB4-DB7 have to be connected to P0-P3
#define LCDDATAPORT PORTC
#define LCDDATADIR  DDRC
#define LCDDATAPIN  PINC

  // control port, LCD signals RW, EX, I/OC1, I/OC2
#define LCDCTRLPORT PORTD
#define LCDCTRLDIR  DDRD
//#define LCDCTRLPIN  PIND
#define LCDPIN_RW   PD2
#define LCDPIN_IOC1 PD4
#define LCDPIN_IOC2 PD5
#define LCDPIN_EX   PD3


  // display commands
#define LCD_CMD_SETFUNCTIONMODE          0xc0  // SF
#define LCD_CMD_SETENTRYMODE             0x40  // SE
#define LCD_CMD_SETDISPLAYMODE           0x20  // SD
#define LCD_CMD_SHIFTCURDISPADDRESS      0x10  // MA
#define LCD_CMD_SETUNDERLINEMODE         0x0C  // SU
#define LCD_CMD_WRITERAMUNDERLINEBIT     0x08  // WU
#define LCD_CMD_SETBLINKINGFREQUENCY     0x04  // SB
#define LCD_CMD_CURSORHOMESTARTADDR      0x03  // MH
#define LCD_CMD_CLEARCURSORDATAADDRHOME  0x01  // CH
#define LCD_CMD_NOOPERATION              0x00  // NOP


  // SF - Set Function Mode constants
#define sfIO8BIT         0x20  // bit 5
#define sfIO4BIT         0x00
#define sfFont5x8        0x10  // bit 4
#define sfFont5x12       0x00
  
  // SD - Set Display Mode constants
#define dmDisplayOn      0x10
#define dmCursorOn       0x08
#define dmUnderline      0x04
#define dmCursorBlink    0x02
#define dmCharacterBlink 0x01

  // SU - Set Underline Mode constants
#define suSetUnderline   0x03
#define suResetUnderline 0x02
#define suNoUnderline    0x00

  // SB - Set Blinking Frequency constants
#define sbSlow           0x00
#define sbNormal         0x01
#define sbFast           0x02
#define sbFastest        0x03

  // SE - Set Entry Mode constants

  // base definitions cursor
#define LCD_EM_CursorRead 0x08
#define LCD_EM_CursorWrite 0x10
#define LCD_EM_CursorIncrement 0x00
#define LCD_EM_CursorDecrement 0x20

  // base definitions display
#define LCD_EM_DisplayRead 0x01
#define LCD_EM_DisplayWrite 0x02
#define LCD_EM_DisplayIncrement 0x00
#define LCD_EM_DisplayDecrement 0x04

  // constants for cursor
#define emCursorNoChange       0x00
#define emCursorIncRead        LCD_EM_CursorIncrement | LCD_EM_CursorRead
#define emCursorIncWrite       LCD_EM_CursorIncrement | LCD_EM_CursorWrite
#define emCursorIncReadWrite   LCD_EM_CursorIncrement | LCD_EM_CursorRead | LCD_EM_CursorWrite
#define emCursorDecRead        LCD_EM_CursorDecrement | LCD_EM_CursorRead
#define emCursorDecWrite       LCD_EM_CursorDecrement | LCD_EM_CursorWrite
#define emCursorDecReadWrite   LCD_EM_CursorDecrement | LCD_EM_CursorRead | LCD_EM_CursorWrite

  // constants for display start address                                                
#define emDisplayNoChange      0x00
#define emDisplayIncRead       LCD_EM_DisplayIncrement | LCD_EM_DisplayRead
#define emDisplayIncWrite      LCD_EM_DisplayIncrement | LCD_EM_DisplayWrite
#define emDisplayIncReadWrite  LCD_EM_DisplayIncrement | LCD_EM_DisplayRead | LCD_EM_DisplayWrite
#define emDisplayDecRead       LCD_EM_DisplayDecrement | LCD_EM_DisplayRead
#define emDisplayDecWrite      LCD_EM_DisplayDecrement | LCD_EM_DisplayWrite
#define emDisplayDecReadWrite  LCD_EM_DisplayDecrement | LCD_EM_DisplayRead | LCD_EM_DisplayWrite


//extern int LCDIsBusy(void);
extern void LCDSend(unsigned char AControl, unsigned char AData);
extern void LCDInit(void);
extern void LCDSetCursorPos(const unsigned char y, const unsigned char x);
extern void LCDWrite(const char * c);
extern void LCDWritePGM(const char * c);

  // schreibt das übergebene Zeichen an die aktuelle Cursor-Position
#define LCDWriteChar(c)            LCDSend(_BV(LCDPIN_IOC2), c)

  // setzt den Display-Modus
  // man verwende die oben deklarierten Konstanten ;)
//#define LCDSetDisplayMode(mode)    LCDSend(0, mode | 32)

  // setzt den Cursor an die angegebene Adresse
//#define LCDSetCursorAddress(address)   LCDSend((1<<LCDPIN_IOC1) | (1<<LCDPIN_IOC2), address)

#define cls(void)      LCDSend(0, LCD_CMD_CLEARCURSORDATAADDRHOME);
#endif

I modivied the Ports in the Headerfile to:
  // data port, LCD signals DB4-DB7 have to be connected to P0-P3
#define LCDDATAPORT PORTD
#define LCDDATADIR  DDRD
#define LCDDATAPIN  PIND

  // control port, LCD signals RW, EX, I/OC1, I/OC2
#define LCDCTRLPORT PORTD
#define LCDCTRLDIR  DDRD
//#define LCDCTRLPIN  PIND
#define LCDPIN_RW   7      // not in use
#define LCDPIN_IOC1 6
#define LCDPIN_IOC2 4
#define LCDPIN_EX   5



What else do I need to change??
Lib is included in the folder:   ...\libraries\m50530    (m50530.h and m50530.c)

Sketch:
Code:
#include <m50530.h>
#include <m50530.c>

void setup()
{
// wait for power up
      delay(5000);
  LCDInit();
  LCDSend( 0, LCD_CMD_SETDISPLAYMODE | dmDisplayOn | dmCursorOn | dmCursorBlink);
  LCDWrite("TEST");

}

void loop()
{

}

LCD is not working... what eels does need to be changed????
12  Forum 2005-2010 (read only) / Deutsch / Re: Pin Namen/belegung in libraries?? on: July 07, 2010, 02:36:34 am
SUPER!!!!

Sei doch so nett und tu ihn in den Arduino Playground raufladen mit kurzer Beschreibung.
Da sind sämtliche Treiber gesammelt. Das habe ich auch mit meinem Display gemacht (es ist zwar ein Standard, hat aber 2 Enable Eingänge).

Bei Gelegenheit muss ich mir dein Code genauer ansehen... hast du viel verändert?
13  Forum 2005-2010 (read only) / Deutsch / Re: Pin Namen/belegung in libraries?? on: June 18, 2010, 03:45:31 pm
nein, ich habe ein anderes Display günstig bekommen...

wenn du es versuchen willst versuche:

- den Code an C++ / mit Header-Datei richtig anzupassen (hat nix mit Arduino zu tun nur Systematisch die Syntax überprüfen ob es konform ist)
- den Read/Write-Pin überprüfen (ich hatte ihn auf Masse), es gibt aber auch Treiber die daran festellen ob das LCD bussy ist.

viel Erfolg!!
14  Forum 2005-2010 (read only) / Deutsch / Re: Pin Namen/belegung in libraries?? on: March 23, 2010, 01:12:52 pm
Ich hab jetzt raus gefunden das ich die PB2 -> PINB2 ändern kann ohne das der Compiler meckert.

Der LCD Treiber ist original so wie er auf dem Atmel gelaufen ist, ich habe bloß PBx -> PINBx geändert.
Es kompiliert, aber das LCD zeigt nichts an, was muss ich noch ändern?????????????
Helft mir BITTE!


Das ganze als libraries:
m50530.h
Code:
#ifndef M50530_H
#define M50530_H
#include <avr/io.h>

  // Data and Control signals can be connected to different ports!

  // data port, LCD signals DB4-DB7 have to be connected to P0-P3
#define LCDDATAPORT PORTC
#define LCDDATADIR  DDRC
#define LCDDATAPIN  PINC

  // control port, LCD signals RW, EX, I/OC1, I/OC2
#define LCDCTRLPORT PORTD
#define LCDCTRLDIR  DDRD


//#define LCDCTRLPIN  PIND
#define LCDPIN_RW   PIND7      //(PORTB & 0X10)      //PD7      //7
#define LCDPIN_IOC1 PIND4//16      //4
#define LCDPIN_IOC2 PIND2      //2
#define LCDPIN_EX   PIND3      //3


  // display commands
#define LCD_CMD_SETFUNCTIONMODE          0xc0  // SF
#define LCD_CMD_SETENTRYMODE             0x40  // SE
#define LCD_CMD_SETDISPLAYMODE           0x20  // SD
#define LCD_CMD_SHIFTCURDISPADDRESS      0x10  // MA
#define LCD_CMD_SETUNDERLINEMODE         0x0C  // SU
#define LCD_CMD_WRITERAMUNDERLINEBIT     0x08  // WU
#define LCD_CMD_SETBLINKINGFREQUENCY     0x04  // SB
#define LCD_CMD_CURSORHOMESTARTADDR      0x03  // MH
#define LCD_CMD_CLEARCURSORDATAADDRHOME  0x01  // CH
#define LCD_CMD_NOOPERATION              0x00  // NOP


  // SF - Set Function Mode constants
#define sfIO8BIT         0x20  // bit 5
#define sfIO4BIT         0x00
#define sfFont5x8        0x10  // bit 4
#define sfFont5x12       0x00
  
  // SD - Set Display Mode constants
#define dmDisplayOn      0x10
#define dmCursorOn       0x08
#define dmUnderline      0x04
#define dmCursorBlink    0x02
#define dmCharacterBlink 0x01

  // SU - Set Underline Mode constants
#define suSetUnderline   0x03
#define suResetUnderline 0x02
#define suNoUnderline    0x00

  // SB - Set Blinking Frequency constants
#define sbSlow           0x00
#define sbNormal         0x01
#define sbFast           0x02
#define sbFastest        0x03

  // SE - Set Entry Mode constants

  // base definitions cursor
#define LCD_EM_CursorRead 0x08
#define LCD_EM_CursorWrite 0x10
#define LCD_EM_CursorIncrement 0x00
#define LCD_EM_CursorDecrement 0x20

  // base definitions display
#define LCD_EM_DisplayRead 0x01
#define LCD_EM_DisplayWrite 0x02
#define LCD_EM_DisplayIncrement 0x00
#define LCD_EM_DisplayDecrement 0x04

  // constants for cursor
#define emCursorNoChange       0x00
#define emCursorIncRead        LCD_EM_CursorIncrement | LCD_EM_CursorRead
#define emCursorIncWrite       LCD_EM_CursorIncrement | LCD_EM_CursorWrite
#define emCursorIncReadWrite   LCD_EM_CursorIncrement | LCD_EM_CursorRead | LCD_EM_CursorWrite
#define emCursorDecRead        LCD_EM_CursorDecrement | LCD_EM_CursorRead
#define emCursorDecWrite       LCD_EM_CursorDecrement | LCD_EM_CursorWrite
#define emCursorDecReadWrite   LCD_EM_CursorDecrement | LCD_EM_CursorRead | LCD_EM_CursorWrite

  // constants for display start address                                                
#define emDisplayNoChange      0x00
#define emDisplayIncRead       LCD_EM_DisplayIncrement | LCD_EM_DisplayRead
#define emDisplayIncWrite      LCD_EM_DisplayIncrement | LCD_EM_DisplayWrite
#define emDisplayIncReadWrite  LCD_EM_DisplayIncrement | LCD_EM_DisplayRead | LCD_EM_DisplayWrite
#define emDisplayDecRead       LCD_EM_DisplayDecrement | LCD_EM_DisplayRead
#define emDisplayDecWrite      LCD_EM_DisplayDecrement | LCD_EM_DisplayWrite
#define emDisplayDecReadWrite  LCD_EM_DisplayDecrement | LCD_EM_DisplayRead | LCD_EM_DisplayWrite


//extern int LCDIsBusy(void);
extern void LCDSend(unsigned char AControl, unsigned char AData);
extern void LCDInit(void);
extern void LCDSetCursorPos(const unsigned char y, const unsigned char x);
extern void LCDWrite(const char * c);
extern void LCDWritePGM(const char * c);

  // schreibt das übergebene Zeichen an die aktuelle Cursor-Position
#define LCDWriteChar(c)            LCDSend(_BV(LCDPIN_IOC2), c)

  // setzt den Display-Modus
  // man verwende die oben deklarierten Konstanten ;)
//#define LCDSetDisplayMode(mode)    LCDSend(0, mode | 32)

  // setzt den Cursor an die angegebene Adresse
//#define LCDSetCursorAddress(address)   LCDSend((1<<LCDPIN_IOC1) | (1<<LCDPIN_IOC2), address)

#define cls(void)      LCDSend(0, LCD_CMD_CLEARCURSORDATAADDRHOME);
#endif

m50530.cpp
Code:
#include "m50530.h"
#include <util/delay.h>
#include <avr/pgmspace.h>

void LCDToggleEX(void)
{
  //_delay_us(5);

  LCDCTRLPORT |= _BV(LCDPIN_EX);
  
  _delay_us(2);  // 10

  LCDCTRLPORT &= ~_BV(LCDPIN_EX);

  //_delay_us(5);
}

int LCDIsBusy(void)
{
  unsigned char lInpData = 0;
  int lBusyFlag = 0;
  int l4BitFlag = 0;

    // data port set up to input
  LCDDATADIR &= 0xf0;
  
    // set RW signal
  LCDCTRLPORT |= _BV(LCDPIN_RW);

    // delay?
  //_delay_us(5);  

    // set EX signal
  LCDCTRLPORT |= _BV(LCDPIN_EX);

    // delay?
  //_delay_us(2); // 10

    // read 1st nibble
  lInpData = LCDDATAPIN;

    // clear EX signal
  LCDCTRLPORT &= ~_BV(LCDPIN_EX);

  lBusyFlag =  ( lInpData & (1 << 3) );
  l4BitFlag = !( lInpData & (1 << 2) );

    // delay?
  //_delay_us(5);  

    // read 2nd nibble
  if ( l4BitFlag )
  {
      // set EX signal
    LCDCTRLPORT |= _BV(LCDPIN_EX);

      // delay?
    //_delay_us(2);  // 10

      // read 2nd nibble
    LCDDATAPIN;

      // clear EX signal
    LCDCTRLPORT &= ~_BV(LCDPIN_EX);
  }

  //_delay_us(10);

    // clear RW signal
  LCDCTRLPORT &= ~_BV(LCDPIN_RW);

    // set data port back to output
  LCDDATADIR |= 0x0f;
    // clear data outputs
  LCDDATAPORT &= 0xf0;

  return lBusyFlag;
}

void LCDSend(unsigned char AControl, unsigned char AData)
{
  unsigned char lHN = ( AData & 0xf0 ) >> 4;
  unsigned char lLN = ( AData & 0x0f );
  
  while ( LCDIsBusy() )
    ;

  LCDCTRLPORT &= ~(_BV(LCDPIN_RW) | _BV(LCDPIN_IOC1) | _BV(LCDPIN_IOC2) | _BV(LCDPIN_EX));
  LCDCTRLPORT |= AControl;

  LCDDATAPORT &= 0xf0;
  LCDDATAPORT |= lHN;

  LCDToggleEX();

  LCDDATAPORT &= 0xf0;
  LCDDATAPORT |= lLN;
  
  LCDToggleEX();

  LCDDATAPORT &= 0xf0;
  LCDCTRLPORT &= ~AControl;

  //_delay_us(20);
}

void LCDInit(void)
{
    // port setup
  LCDDATADIR |= 0x0f;
  LCDCTRLDIR |= _BV(LCDPIN_RW) | _BV(LCDPIN_IOC1) | _BV(LCDPIN_IOC2) | _BV(LCDPIN_EX);
  
    // SF - Set Function Mode
      //  >> 4 Bit I/O, 5x8 Font, 1/32 duty
      //      >> 4 lines x 40 words, 96 words CG RAM
  LCDSend( 0, LCD_CMD_SETFUNCTIONMODE | sfIO4BIT | sfFont5x8 | 0x0B );

    // SE - Set Entry Mode
  LCDSend( 0, LCD_CMD_SETENTRYMODE | emCursorIncWrite );

    // SU - Set Underline Mode
  LCDSend( 0, LCD_CMD_SETUNDERLINEMODE | suNoUnderline );

    // SB - Set Blinking Frequency
  LCDSend( 0, LCD_CMD_SETBLINKINGFREQUENCY | sbNormal );

    // SD - Set Display Mode
  LCDSend( 0, LCD_CMD_SETDISPLAYMODE | dmDisplayOn /*| dmCursorOn*/ | dmCursorBlink);

    // CH - Clear Cursor of DD RAM display data home & display start address home
  LCDSend( 0, LCD_CMD_CLEARCURSORDATAADDRHOME );

  _delay_ms(2);
}

  // setzt den Cursor an die angegebene Position (y = Zeile, x = Spalte)
void LCDSetCursorPos(const unsigned char y, const unsigned char x)
{
    // Adresse aus x und y berechnen
    // Adressen sind wie folgt: Zeile 0 = 0; Zeile 1 = 40; Zeile 2 = 80; Zeile 3 = 120; Zeile 4 = 160; Zeile 5 = 64+24; Zeile 6 = 128+24; Zeile 7 = 192+24
  unsigned char address = x + (y*40);

  LCDSend(_BV(LCDPIN_IOC1)|_BV(LCDPIN_IOC2), address);
}

  // schreibt die übergebene Zeichenkette an die aktuelle Cursor-Position
void LCDWrite(const char * c)
{
  while (*c)
    LCDWriteChar(*c++);
}

  // schreibt die übergebene Zeichenkette aus dem Programmspeicher
  // an die aktuelle Cursor-Position
void LCDWritePGM(const char * c)
{
  uint8_t b;

  while ( (b = pgm_read_byte(c++)) )
        LCDWriteChar(b);
}
15  Forum 2005-2010 (read only) / Deutsch / Re: Pin Namen/belegung in libraries?? on: March 19, 2010, 05:41:46 pm
geht leider nicht, kann natürlich aber noch an anderen Sachen hängen....
Pages: [1] 2