Anleitung zur Displayansteuerung

Gast #3429
Lesenswert?

Ich möchte noch hinzufügen, dass ich das tutorial4 auf 
mikrocontroller.net schon gelesen habe, aber mit assembler leider nichts 
anfangen kann. Aus diesem Grund bitte ich um eine Lösung in C.
Gast #3430
Lesenswert?

Hi Kurt!

Das sollte Dir helfen.
Daten- und Steuerleitungen einfach nur anpassen,

Gruss,
Holger



//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Diese Funktion beinhaltet eine einfache 8-Bit LCD-Routine
// Und lenkt printf auf das Display um
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Belegung Port | LCD
//      P8.6 | EN  (6)
//      P8.7 | RS  (4)
//          P0.7 | DB7 (14)
//          P0.6 | DB6 (13)
//          P0.5 | DB5 (12)
//          P0.4 | DB4 (11)
//          P0.7 | DB7 (10)
//          P0.6 | DB6 (9)
//          P0.5 | DB5 (8)
//          P0.4 | DB4 (7)
//      GND  | R/W (5)
//      GND  | VSS (1)
//      +5V  | VDD (2)
//   220R to GND | contrast (3)
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// 2.2002   Holger Buss
// http://www.mikrocontroller.com
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#include    <stdio.h>

#define DispRS   p8_7     // Steuerleitungen
#define DispEN   p8_6
#define DispPort p0       // an diesem Port liegen die Datenleitungen
#include    "sfr62.h"  // entsprechend dem Prozessor anpassen ( hier: 
M16C62)

unsigned char Text[]="Hello world \0";

void _long_delay(void)
{
long t = 1000;
while (t--);
}

void _short_delay(void)
{
int t = 5;
while (t--);
}


void _lcd_write_data(unsigned char data)
{
 DispRS = 0;
 DispPort = data;
 DispEN = 1;
 DispEN = 1;
 DispEN = 1;
 DispEN = 0;
}


void lcd_write_byte(unsigned char data)
{
 DispRS = 1;
 DispPort = data;
 DispEN = 1;
 DispEN = 1;
 DispEN = 1;
 DispEN = 0;
}


int my_pput(int zeichen)
{
 lcd_write_byte((unsigned char) zeichen);
}

// initialize the LCD controller
void lcd_init(void)
{
_long_delay();
_lcd_write_data(0x38);   // 4-bit:0x28  8-Bit:0x38
_long_delay();
_lcd_write_data(0x38);
_long_delay();
_lcd_write_data(0x02);
_long_delay();
_lcd_write_data(0x06);
_long_delay();
_lcd_write_data(0x0c);
_long_delay();
_lcd_write_data(0x10);
_long_delay();
_lcd_write_data(1);   // clear LCD
_long_delay();

}


void WriteLCD(unsigned char *this_text)
{
 unsigned char i = 0;
 while(this_text[i] != 0)
  {
   lcd_write_byte(this_text[i++]);
   _short_delay();
  }
}



void far main()
{
 unsigned int i = 1234;
 lcd_init();

 stdout->_func_out = my_pput; // legt die stdout auf das Display um

 _lcd_write_data(0xc0);  // cursor Line 2
 WriteLCD(Text);

 printf("Moin %u",i);

 while(1)  // das war`s
  {
  }

}

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren