/********************************************** KBD.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); void LCDClear(void); void LCDClock(void); //--------------------------------------------- void waitLCD(unsigned int i) // delay function { unsigned int j; for(j = 0; j < i; j++); } void LCDClock(void) // Enable auf fallende Flanke { waitLCD(16); P2OUT |= 0x04; // Enable-Signal (P4.6) erst mal sicherheitshalber auf high waitLCD(16); P2OUT &=~ 0x04; // und jetzt auf low waitLCD(16); } void LCDClear(void) { P1OUT = 0x01; // clear display (DB0 - DB7 an P1) LCDClock(); // Befehl Ausfuehren waitLCD(20); // clear display braucht etwas laenger } void LCDHome(void) { P1OUT = 0x02; LCDClock(); // befehl ausfuehren waitLCD(20); // clear display braucht etwas laenger } void LCDOutc(char str) { P1OUT = str; // str einfach an den port schicken P2OUT |= 0x05; // RS und E high, R/W low LCDClock(); // befehl ausfuehren waitLCD(20); } void LCDOuts(char* str) { while (*str != 0) { LCDOutc(*str++); } LCDClear(); } void LCDInit(void) { waitLCD(16); P1OUT = 0x30; // 3 mal 30h ins Steuerregister LCDClock(); waitLCD(6); P1OUT = 0x30; // LCDClock(); waitLCD(1); P1OUT = 0x30; // 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(200); 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);*/ } /********************************************** MainKBD.c **********************************************/ #include #include void main (void) { 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 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 Ports in Output-Richtung (user's Guide page 9-6: Configuring unused Port Pins) P1DIR |= 0xFF; // P1.x auf output P2DIR |= 0x07; // P2.0 - P2.2 auf output P2OUT = 0x08; // initial nur E (clock) auf high, RS und R/W auf low P1OUT = 0x00; // ports mit null initialisieren waitLCD(16); LCDInit(); // LCD initialisieren ... waitLCD(16); // init-zeit des displays ist ca. 15 ms LCDClear(); // ... und dann noch loeschen und cursor an den anfang zurueck while (1) { LCDClear(); LCDOuts("Servus!"); LCDClock(); waitLCD(20); } }