/********************************************** LCD.c **********************************************/ //--------------------------------------------- // // Pin-Belegung: // // RS an P2.0 // R/W an P2.1 // E an P2.2 // DB0-DB7 an P1.0-P1.7 // //--------------------------------------------- #include /*------PROTOTYPEN----------*/ void waitLCD(unsigned int i); void LCDOutc(char str); // Output eines Zeichens void LCDOuts(char* str); // Output eines Strings void LCDInit(void); // Initialisierung des LCD's void LCDClear(void); void LCDClock(void); void LCDHome(void); // Sprinde an den Anfang des LCD's /*------DEKLARATIONEN----------*/ void waitLCD(unsigned int i) // Delay Funktion { unsigned int j; for(j = 0; j < i; j++); } void LCDClock(void) // Daten werden auf die fallende Flanke von Enable übernommen { waitLCD(16); P2OUT |= 0x04; // Enable-Signal (P2.2) auf HIGH waitLCD(16); P2OUT &=~ 0x04; // und jetzt auf LOW waitLCD(16); } void LCDHome(void) { P2OUT &=~ 0x01; //P1OUT = 0x80; // Set DDRAM auf Adress 00H //LCDClock(); P1OUT = 0x02; // Return Home LCDClock(); } void LCDClear(void) { P2OUT &=~ 0x01; // RS auf LOW P1OUT = 0x01; // Clear Display (DB0 - DB7 an P1) LCDClock(); // Befehl ausführen waitLCD(100); // Clear Display braucht etwas laenger } void LCDOutc(char str) // Ausgabe eines Zeichens { P2OUT |= 0x01; // RS auf HIGH P1OUT = str; // str einfach an den Port schicken LCDClock(); // Befehl ausführen } void LCDOuts(char* str) // Ausgabe eines Strings { while (*str != 0) { LCDOutc(*str++); } LCDClock(); } void LCDInit(void) // siehe Datenblatt LCD { waitLCD(16); P2OUT &=~ 0x01; // RS auf LOW P1OUT = 0x30; // 1. mal 30h ins Steuerregister LCDClock(); waitLCD(6); P1OUT = 0x30; // 2. mal ... LCDClock(); waitLCD(2); P1OUT = 0x30; // 3. mal ... LCDClock(); P1OUT = 0x38; // Function Set: 8 Bit-Operation, 2 Zeilen-Display, 5*7 Dot Font LCDClock(); // Befehl ausfuehren waitLCD(20); P1OUT = 0x0E; // Display Control: Display anschalten, Cursor an, Cursor blinkt nicht LCDClock(); // Befehl ausfuehren waitLCD(20); P1OUT = 0x06; // Entry mode set: kein Display shift, Inkrement LCDClock(); waitLCD(20); P1OUT = 0x14; // Cursor-Shift: nach rechts; kein Display-shift LCDClock(); // Befehl ausfuehren waitLCD(20); /*P1OUT = 0x80; // DDRAM-Adress == 0 LCDClock(); waitLCD(20);*/ } /********************************************** MainLCD.c **********************************************/ #include #include void main (void) { /*------uC Initialisierung----------*/ WDTCTL = WDTPW + WDTHOLD; // Watchdog Timer aus SCFQCTL =~ 0x80; // DCO Modulation is enabled FLL_CTL0 = 0xA0; // 1 - DCO output is not divided // 0 - low frequenzy mode 32768 Hz crystal at XT1 // 10 - 8 pF internal capacitance // 0000 - no fault condition present /*FLL_CTL1 = 0x60; // 0 - unused // 1 - sub main clock is off // 1 - XT2 is off (not assembled!) // 00 - master clock source is DCO // 0 - source for SMCLK is DCO // 0 - auxiliary clock is divided by 1*/ FLL_CTL1 = 0x38; // 0 - unused // 0 - sub main clock is on // 1 - XT2 is off (not assembled) // 11 - master clock source is XT1 at 32,768kHz // 0 - source for SMCLK is DCO // 0 - auxiliary clock is divided by 1 P1SEL = 0x00; P2SEL = 0x00; P3SEL = 0x00; P4SEL = 0x00; P5SEL = 0x00; P6SEL = 0x00; // alle unused Ports als I/O's verwenden (user's Guide page 9-6: Configuring unused Port Pins) P3DIR = 0xFF; P4DIR = 0xFF; P5DIR = 0xFF; P6DIR = 0xFF; // alle unused Ports in Output-Richtung (user's Guide page 9-6: Configuring unused Port Pins) P1DIR = 0xFF; // P1.x auf output P1OUT = 0x00; // P1.x mit Null initialisieren P2DIR |= 0x07; // P2.0 - P2.2 auf output P2OUT = 0x08; // initial nur E (clock) auf high, RS und R/W auf low3 /*------LCD Initialisierung----------*/ LCDInit(); // LCD initialisieren ... waitLCD(16); // init-zeit des displays ist ca. 15 ms LCDClear(); // ... und dann noch loeschen und cursor an den anfang zurueck /*------PROGRAMM ABLAUF----------*/ while (1) { LCDHome(); P2OUT |= 0x01; LCDOuts("Servus"); } }