Hallo,
@ Peter Fleury:
ich möchte ein LCD im 4bit-Modus mit den Datenleitungen an den
high-nibble des LCD-Ports (Pin 4 ... 7) anschließen und Deine
LCD-Library nutzen. Der Grund: Die Avr-Ctrl-Platine von
www.microcontroller.com nutzt diese Pins als Daten-Bits.
siehe:
http://mikrocontroller.cco-ev.de/images/avr_schaltplan.gif
Könnte folgende Änderung an Deiner LCD.C funktionieren?
...
#if LCD_IO_MODE
static void inline lcd_write(uint8_t data,uint8_t rs)
{
/* configure data pins as output */
outp(0xFF, DDR(LCD_DATA_PORT) );
if (rs) { /* write data (RS=1, RW=0) */
/* output high nibble first */
outp(((data&0xF0)|(1<<LCD_RS_PIN), LCD_DATA_PORT );
lcd_e_toggle();
/*(data>>4)&0x0F)*/
/* output low nibble */
outp(((data<<4)&0xF0)|(1<<LCD_RS_PIN), LCD_DATA_PORT );
lcd_e_toggle();
} else { /* write instruction (RS=0, RW=0) */
/* output high nibble first */
outp((data&0xF0), LCD_DATA_PORT );
lcd_e_toggle();
/* output low nibble */
outp((data<<4)&0xF0, LCD_DATA_PORT );
lcd_e_toggle();
}
/* all data pins high (inactive) */
outp(0xF0, LCD_DATA_PORT);
}
#else
#define lcd_write(d,rs) if (rs) *(volatile uint8_t*)(LCD_IO_DATA) = d;
else *(volatile uint8_t*)(LCD_IO_FUNCTION) = d;
/* rs==0 -> write instruction to LCD_IO_FUNCTION */
/* rs==1 -> write data to LCD_IO_DATA */
#endif
#if LCD_IO_MODE
static uint8_t lcd_read(uint8_t rs)
{
register uint8_t dataH, dataL;
if (rs) sbi(LCD_RS_PORT, LCD_RS_PIN); /* RS=1: read data
*/
else cbi(LCD_RS_PORT, LCD_RS_PIN); /* RS=0: read busy flag
*/
sbi(LCD_RW_PORT, LCD_RW_PIN); /* RW=1 read mode
*/
/* configure data pins as input */
outp(0x0F, DDR(LCD_DATA_PORT));
lcd_e_high();
lcd_e_delay();
dataH = inp(PIN(LCD_DATA_PORT)); /* read high nibble first
*/
lcd_e_low();
lcd_e_delay(); /* Enable 500ns low
*/
lcd_e_high();
lcd_e_delay();
dataL = inp(PIN(LCD_DATA_PORT)); /* read low nibble
*/
lcd_e_low();
return ( (dataH&0xF0) | (dataL>>4) );
}
#else
#define lcd_read(rs) (rs) ? *(volatile
uint8_t*)(LCD_IO_DATA+LCD_IO_READ) : *(volatile
uint8_t*)(LCD_IO_FUNCTION+LCD_IO_READ)
/* rs==0 -> read instruction from LCD_IO_FUNCTION */
/* rs==1 -> read data from LCD_IO_DATA */
#endif
...
Bei mir funktioniert es nicht. Ich denke, es könnte aber auch ein
Problem mit dem Makefile dahinterstecken, weil das compilieren nur mit
der folgenden Fehlermeldungen abbricht:
avr-gcc -c -g -Os -funsigned-char -funsigned-bitfields -fpack-struct
-fshort-enums -Wall -Wstrict-prototypes -mmcu=at90s8535
-Wa,-ahlmsnd=lcdhn.lst -I. lcdhn.c -o lcdhn.o
lcdhn.c:351:1: unterminated argument list invoking macro "outp"
lcdhn.c: In function `lcd_write':
lcdhn.c:100: error: `outp' undeclared (first use in this function)
lcdhn.c:100: error: (Each undeclared identifier is reported only once
lcdhn.c:100: error: for each function it appears in.)
lcdhn.c:100: error: parse error at end of input
lcdhn.c:75: warning: `delay' defined but not used
lcdhn.c:83: warning: `toggle_e' defined but not used
make.exe: *** [lcdhn.o] Error 1
Man merkt es sofort, ich habe wenig Erfahrung mit C, aber ich verstehe
trotzdem nicht, warum outp nicht gefunden wird. Es wird doch
eingebunden:
#include <avr/io.h>
#include "sfr_defs.h"
/* #include "lcd.h" */
#include "lcdhn.h"
/* lcdhn.h ist die von mir modifizierte Version von lcd.h , hn steht
für highnibble.
lcdhn.c analog. */
Ich bin für jede Hilfe dankbar.
Matthias