/******************************************************************************* ** ** ** Datei: Display.C ** ** Das Programm beinhaltet: Routinen zur Kommunikation zwischen ** ** Controller und Display ** ** über I2C-Bus ** ** ** ** ** ** Eingangsparameter: KEINE! (void) ** ** ** ** Ausgangsparameter: KEINE! (void) ** ** ** ** Rueckgabewert: KEINER! (void) ** ** ** ******************************************************************************** ** ** ** Autor: Thorsten Breuer ** ** Quellen: ** ** Datum: 09.01.1999 WS 98/99 ** ** ** *******************************************************************************/ /******************** Steueranweisungen fuer den Compiler *********************/ #pragma OBJECTEXTEND #pragma CODE DEBUG #pragma SYMBOLS /************************ Text im Quelltext einbinden *************************/ #include #include #include /********************************* Konstanten *********************************/ #define A0_LOW ((unsigned char *)0x28020L) #define A0_HIGH ((unsigned char *)0x28021L) #define CLS 0x01 #define HOME 0x02 #define ENTRY 0x04 #define INCREMENT 0x02 #define DECREMENT 0x00 #define CONTROL 0x08 #define DISPLAY_ON 0x04 #define DISPLAY_OFF 0x00 #define CURSOR_ON 0x02 #define CURSOR_OFF 0x00 #define BLINK 0x01 #define NO_BLINK 0x00 #define SHIFT 0x10 #define SHI_LEFT 0x00 #define SHI_RIGHT 0x04 #define DIS_LEFT 0x08 #define DIS_RIGHT 0x0C #define FUNCTION_SET 0x20 #define _8BIT 0x10 #define _4BIT 0x00 #define _2LINE 0x08 #define _1LINE 0x00 #define _10DOTS 0x04 #define _7DOTS 0x00 /***************************** globale Variablen ******************************/ unsigned char i; /* allgemeine Zaehlvariable */ unsigned char antwort[25]; unsigned char str[16]; unsigned char ziffer[10]; /********************************* Prototypen *********************************/ void display_init(void); void instruction(char wert); void instruct(char wert); void clear_display(void); void write(unsigned int zeile); /* Displayausgabe */ void ausgabe_display(unsigned char byte); /* Kommunikation mit dem Display */ void transmit_i2c(unsigned char byte); void wait(unsigned int); /* Warteschleife für kurze Pausen */ void initial_i2c(void); unsigned char read_tast(void); /* Byte von Tastatur lesen */ void write_tast(unsigned char); /* Byte an Tastatur anlegen */ unsigned char taste_einlesen(void); /* Tastendruck ermitteln */ void zahlausgabe(unsigned int); /* Verfahrweg in mm ausgeben */ /******************** Warteschleife für kurze Wartezeiten *********************/ void wait(unsigned int zeit) { while (zeit>0) zeit--; } /*************************** I2C-Bus initialisieren ***************************/ void initial_i2c(void) { *A0_HIGH = 0x80; wait(50); *A0_LOW = 0x55; wait(50); *A0_HIGH = 0xA0; wait(50); *A0_LOW = 0x1C; wait(50); } /*************************** Display initialisieren ***************************/ void display_init(void) { wait(1500); instruct(3); wait(500); instruct(3); wait(100); instruct(3); wait(50); instruct(2); wait(50); instruction(FUNCTION_SET | _2LINE); wait(50); instruction(CONTROL | DISPLAY_OFF); wait(50); instruction(CLS); wait(150); instruction(CONTROL | DISPLAY_ON | CURSOR_OFF | NO_BLINK); wait(50); for(i=0;i<10;i=i+1) /* Char-Array speichert die Ziffern 0-9 */ ziffer[i] = (char) (i+48); /* Display kann nur Text und keine Zahlen ausgeben */ } /**************************** 8-BIT Wert übergeben ****************************/ void instruction(char wert) { antwort[0] = (wert & 0x0F) << 4; antwort[1] = wert & 0xF0; transmit_i2c(antwort[1]); transmit_i2c(antwort[1]+4); transmit_i2c(antwort[1]); transmit_i2c(antwort[0]); transmit_i2c(antwort[0]+4); transmit_i2c(antwort[0]); } /**************************** 4-BIT Wert übergeben ****************************/ void instruct(char wert) { wert*=16; transmit_i2c(wert); transmit_i2c(wert+4); transmit_i2c(wert); } /****************** Löscht Diplay und setzt Cursor auf Home *******************/ void clear_display(void) { instruction(CLS); wait(50); instruction(HOME); wait(50); } /****************** Ausgabe von ASCII-Zeichen auf LC-Display ******************/ void write(unsigned int zeile) { if (zeile<200) { zeile -= 101; instruction(0x80+zeile); } if (zeile>199) { zeile -=201; instruction(0xC0+zeile); } for (i=0; i