PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : RN-Control 1.4: Grafik LCD mit u8g lib



teamohnename
21.09.2012, 17:09
Hallo an alle,
wir konnten kostenlos an ein Grafik LCD 12864ZW kommen (Datenblatt:
http://www.digole.com/images/file/Digole_12864_LCD.pdf
). Nun möchten wir das testweise an einem ATmega32 (später ATmega2560)
verwenden. Genutzt wird der Controller ST7920. Komischerweise gibt es
speziell für dieses LCD nur Arduino Librarys, die einzige, die angeblich
kompatibel ist, ist die u8glib:
http://code.google.com/p/u8glib/
Download:
http://code.google.com/p/u8glib/downloads/detail?n...
Das Ganze wird an einem garantiert funktionierenden RN-Control 1.4
getestet.
Problem ist nun, dass das nicht funktioniert. Das Display haben wir, wie
im Datenblatt beschrieben, so angeschlossen:

VSS: Masse
VDD: +5V
RS (Chip Select): PORTC 5
R/W (MOSI): PORTC 4
E (SCK): PORTC 3
PSB (SPI aktiv): Masse
und die Hintergrundbeleuchtung. Rest unbeschaltet.

Wenn man das Display nun anschaltet, leuchtet natürlich die
Hintergrundbeleuchtung. Die Pixel sind quasi ,,halb" an, oben und in der
Mitte ist eine Zeile komplett an.

Wir verwenden das Beispiel hello_world.c:

/*

main.c

Hello World for ATMEGA Controller

Universal 8bit Graphics Library

Copyright (c) 2012, olikraus@gmail.com
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/

#include "u8g.h"

#if defined(__AVR__)
#include <avr/interrupt.h>
#include <avr/io.h>
#endif


/*
Software SPI:
uint8_t u8g_InitSPI(u8g_t *u8g, u8g_dev_t *dev, uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t reset);

Hardware SPI:
uint8_t u8g_InitHWSPI(u8g_t *u8g, u8g_dev_t *dev, uint8_t cs, uint8_t a0, uint8_t reset);

Parallel Interface:
uint8_t u8g_Init8Bit(u8g_t *u8g, u8g_dev_t *dev, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7,
uint8_t en, uint8_t cs1, uint8_t cs2, uint8_t di, uint8_t rw, uint8_t reset);

Visit
http://code.google.com/p/u8glib/wiki/device
for a list of valid devices (second argument of the constructor).

The following examples will use the dogm132 device: u8g_dev_st7565_dogm132_sw_spi

Note: The device must match the setup: For example, do not use a sw_spi device with u8g_InitHWSPI().
*/

u8g_t u8g;

void u8g_setup(void)
{
/*
Test Envionment, ATMEGA with the following settings:
SCK
MOSI
CS

2: PORTC
*/
u8g_InitSPI(&u8g, &u8g_dev_st7920_128x64_sw_spi, PN(2, 3), PN(2, 4), PN(2, 5), U8G_PIN_NONE, U8G_PIN_NONE);
}

void sys_init(void)
{
#if defined(__AVR__)
/* select minimal prescaler (max system speed) */
//CLKPR = 0x80;
//CLKPR = 0x00;
#endif
}

void draw(void)
{
u8g_SetFont(&u8g, u8g_font_6x10);
u8g_DrawStr(&u8g, 0, 15, "Hello World!");
}

int main(void)
{
sys_init();
u8g_setup();

for(;;)
{
u8g_FirstPage(&u8g);
do
{
draw();
} while ( u8g_NextPage(&u8g) );
u8g_Delay(100);
}

}

Dabei funktioniert allerdings rein gar nichts, also nicht mal an den
Pins tut sich was. Kontrolliert am Oszilloskop. Wenn wir allerdings
manuell LEDs an den entsprechenden Pins anschließen und aktivieren,
leuchten diese. Auch an PORTB funktioniert das ganze nicht. In dieser
Library ist das Display nur mit dem Software SPI kompatibel oder im 8bit
Modus.
Was uns nun stutzig macht, ist:
- Warum werden die wichtigen Librarys nicht eingebunden? Die einzige,
die eingebunden wird, ist die u8g.h. Von dort werden aber keine weiteren
Librarys eingebunden. Dort sind auch keine genauen Funktionsaufrufe,
sondern nur die Funktionsdeklarationen. Müssen wir die Funktionen aus dem
Ordner src irgendwie selbst einbinden? Wenn ja, wie genau soll das
funktionieren? Pauschal würden wir jetzt sagen, dass die Funktionen quasi
deklariert werden, aber leer sind und dann irgendwie noch eingebunden
werden müssen. Wenn wir das aber in dem Hauptprogramm oben mit #include
mache (natürlich vorher die betreffenden Dateien in den Hauptordner, in
dem auch das Programm und das makefile ist, stecken), ändert sich weder
die Größe des Programms, noch funktioniert es.
- Was hat es mit dem CLKPR Register auf sich? Auf dem ATmega32 gibt es
das nicht (deshalb in dem Beispiel auskommentiert, da sonst der Compiler
(avr-gcc) meckert.

Myteriös.
Vielen Dank schon mal im Voraus und
Viele Grüße
Jan
teamohnename