Hallo liebe Arduino-Freunde,
ich beschäftige mich nun ein wenig mit dem Arduino und hab mir ein Lcd (Ea-Dogm162e-a) von electronic assembly gekauft. ich besitze ein Arduino Mega 2560 und benutze die lib von :
Da ich die Arduino Version 1.0 habe, musste ich kleine Änderungen vornehmen um zu compilieren. Ich habe die Spi Ports entsprechend zu meinem Mega geändert. Ebenfalls habe ich das Lc-Display genau so angeschlossen, wie es im Datenblatt beschrieben ist.
Allerdings ist auf meinem Lc-Display gar nichts zu sehen. Ich weiß nicht genau wo der Fehler liegen könnte. Hoffe nun auf eure Hilfe ^^
Mein Source-Code:
Header-Datei
#ifndef LCDdogmSPI_h
#define LCDdogmSPI_h
#include <inttypes.h>
#include "Arduino.h"
class LCDdogmSPI {
private:
int cs_pin, rs_pin, lines;
void spiTransfer(volatile char data);
public:
LCDdogmSPI(int num_lines, int chip_select_pin, int register_select_pin);
void commandWrite(char value);
void dataWrite(char value);
void init();
void print(char value);
void println(char value[]);
void clear();
//non-core---------------
void cursorTo(int line_num, int x);
// void leftScroll(int chars, int delay_time);
//end of non-core--------
};
#endif
cpp datei
#include "LCDdogmSPI.h"
extern "C" {
#include <stdio.h> //not needed yet
#include <string.h> //needed for strlen()
#include <inttypes.h>
#include "Arduino.h"
}
#define SPI_MOSI_PIN 51
#define SPI_CLK_PIN 52
// define command bytes for the LCD
#define LCDCMD_CLR 1
#define LCDCMD_HOME 2
#define LCDCMD_ON 0x0C
#define LCDCMD_FUN_REG_2 49
#define LCDCMD_FUN_REG_1 48
#define LCDCMD_BIAS_SET 28
#define LCDCMD_POWER_CTL 90
#define LCDCMD_FOLLOWER_CTL 105
#define LCDCMD_CONTRAST_SET 116
#define LCDCMD_ENTRY_MODE_SET 6
#define LCDCMD_SET_DDRAM_ADDRESS 0x80
LCDdogmSPI::LCDdogmSPI(int num_lines, int chip_select_pin, int register_select_pin) {
cs_pin = chip_select_pin;
rs_pin = register_select_pin;
lines = num_lines;
}
void LCDdogmSPI::init() {
char clr;
char linesreg;
pinMode(SPI_MOSI_PIN, OUTPUT);
pinMode(SPI_CLK_PIN,OUTPUT);
pinMode(cs_pin,OUTPUT);
pinMode(rs_pin,OUTPUT);
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1);
clr=SPSR;
clr=SPDR;
delay(50);
linesreg = (lines == 2) ? 8 : ;
commandWrite(LCDCMD_FUN_REG_2 | linesreg); //function set
delay(1);
commandWrite(LCDCMD_FUN_REG_2 | linesreg); //function set
delay(1);
commandWrite(LCDCMD_BIAS_SET);
commandWrite(LCDCMD_POWER_CTL);
commandWrite(LCDCMD_FOLLOWER_CTL);
commandWrite(LCDCMD_CONTRAST_SET);
commandWrite(LCDCMD_ON);
commandWrite(LCDCMD_CLR);
commandWrite(LCDCMD_ENTRY_MODE_SET);
commandWrite(LCDCMD_HOME);
}
void LCDdogmSPI::commandWrite(char value) {
digitalWrite(cs_pin,LOW);
digitalWrite(rs_pin, LOW);
spiTransfer(value);
digitalWrite(cs_pin,HIGH);
delay(60);
}
void LCDdogmSPI::dataWrite(char value) {
digitalWrite(cs_pin,LOW);
digitalWrite(rs_pin, HIGH);
spiTransfer(value);
digitalWrite(cs_pin,HIGH);
}
// for compatibility with other LCD libs
void LCDdogmSPI::print(char value) {
dataWrite(value);
}
void LCDdogmSPI::println(char msg[]) {
uint8_t i; //fancy int. avoids compiler warning when comparing i with strlen()'s uint8_t
for (i=;i < strlen(msg);i++){
print(msg[i]);
}
}
void LCDdogmSPI::clear() {
commandWrite(LCDCMD_CLR);
}
void LCDdogmSPI::cursorTo(int line_num, int x) {
char address = ;
if (line_num > lines) line_num = lines;
if (lines == 1) {
x = x % 8;
} else {
x = x % 16;
}
address = (lines == 3) ? (line_num * 0x10) : (line_num * 0x40);
address += x;
address = address & 0x7F;
commandWrite(LCDCMD_SET_DDRAM_ADDRESS | address);
}
void LCDdogmSPI::spiTransfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))); // Wait for the end of the transmission
}
Sketch
#include <LCDdogmSPI.h>
#define CSB_PIN 41
#define RS_PIN 40
#define LCD_LINES 2
LCDdogmSPI lcd = LCDdogmSPI(LCD_LINES, CSB_PIN, RS_PIN);
void setup() {
lcd.init();
lcd.cursorTo(1,5);
lcd.println("Hello");
}
void loop() {
delay(10);
}
Ich hoffe jemand kann mir helfen.
Mfg
Thomas Meyer