Import-Script
27.07.2003, 19:33
Hallo! <BR> <BR>Schon seit längerer Zeit versuche ich, ein primitives LCD mit HD44780-Prozessor irgendwie unter Kontrolle zu bringen, was ich aber leider bis jetzt nicht zustande gebracht habe. <BR>Mein letzter erfolgloser Versuch bestand darin, das Display mit dem µC AT89C2051 anzusteuern. Dazu habe ich folgendes C-Programm geschrieben: <BR>(an P1 hängen die Datenleitungen zum Display, an Pin_E hängt die Enable-Leitung, an Pin_RW die RW-Leitung und an Pin_RS die RS-Leitung) <BR> <BR>#include <intrins.h> <BR> <BR>sbit Pin_E = P3^2; <BR>sbit Pin_RW = P3^3; <BR>sbit Pin_RS = P3^4; <BR> <BR>void CommandByte(void); <BR>void DataByte(void); <BR>void BusyDelay(void); <BR> <BR>unsigned int Counter; <BR>void InitWait(void); <BR>void Wait(unsigned int Duration); <BR> <BR> <BR>void main(void) <BR>{ <BR> <BR> InitWait(); <BR> <BR> Pin_RS = 0; <BR> Pin_RW = 0; <BR> Pin_E = 1; <BR> Wait(150); <BR> P1 = 0x38; <BR> CommandByte(); <BR> Wait(41); <BR> P1 = 0x38; <BR> CommandByte(); <BR> Wait(1); <BR> P1 = 0x38; <BR> CommandByte(); <BR> P1 = 0x0C; <BR> CommandByte(); <BR> P1 = 0x01; <BR> CommandByte(); <BR> <BR> P1 = 0x80; <BR> CommandByte(); <BR> P1 = 'C'; <BR> DataByte(); <BR> P1 = 'N'; <BR> DataByte(); <BR> <BR> while(1); <BR>} <BR> <BR>void CommandByte(void) <BR>{ <BR> Pin_RS = 0; <BR> _nop_(); <BR> BusyDelay(); <BR>} <BR> <BR>void DataByte(void) <BR>{ <BR> Pin_RS = 1; <BR> _nop_(); <BR> BusyDelay(); <BR>} <BR> <BR>void BusyDelay(void) <BR>{ <BR> unsigned char Busy; <BR> Pin_RW = 0; <BR> Pin_E = 0; <BR> _nop_(); <BR> Pin_E = 1; <BR> _nop_(); <BR> P1 = 0xFF; <BR> Pin_RW = 1; <BR> Pin_RS = 0; <BR> Pin_E = 0; <BR> _nop_(); <BR> Pin_E = 1; <BR> do <BR> { <BR> do <BR> { <BR> _nop_(); <BR> Busy = P1 & 0x80; <BR> } while(Busy != 0x00); <BR> Busy = P1 & 0x80; <BR> } while(Busy != 0x00); <BR> Pin_RW = 0; <BR>} <BR> <BR>void InitWait(void) <BR>{ <BR> TMOD = 0x02; // autoreload <BR> TH0 = 0x9C; // for 50 µs (at 24 MHz) <BR> TL0 = 0x9C; <BR> ET0 = 0; // enable timer 0 interrupt <BR> TR0 = 0; <BR>} <BR> <BR>void Timer0Interrupt(void) interrupt 1 <BR>{ <BR> Counter++; <BR>} <BR> <BR>void Wait(unsigned int Duration) <BR>{ <BR> Counter = 0; <BR> TR0 = 1; <BR> ET0 = 1; <BR> while(Counter < Duration); <BR> ET0 = 0; <BR> TR0 = 0; <BR>} <BR> <BR>Habe ich da möglicherweise einen kleinen Fehler eingebaut? <img src="http://progshop.com/elektronik/diskussion/clipart/uhoh.gif" border=0> <BR> <BR>mfg <BR>cndg