/********************************************** KBD.c **********************************************/ //--------------------------------------------- // // Pin-Belegung // RS an P2.0 // R/W an P2.1 // E an P2.2 // DB=-DB7 an P1.0-P1.7 // //--------------------------------------------- #include //Prototypen void waitKBD (unsigned int dauer); // Deklaration der Funktionen void waitKBD(unsigned int i) { unsigned int j; for(j = 0; j < i ; j++); } unsigned char KeyPressed(void) { int Taste = 0; P3OUT = 0xF0; // erste Zeile (P3.3) aktiv (low) waitKBD(20); switch (P3IN) { case 0x06: Taste = ('1'); //Zuweisung des entsprechenden ASCII-Werts break; case 0x05: Taste = ('2'); break; case 0x03: Taste = ('3'); break; } P3OUT = 0xF8; // erste Zeile (P3.3) inaktiv (high) if (Taste == 0) { P3OUT = 0xE8; // zweite Zeile (P3.4) aktiv (low) waitKBD(20); switch (P3IN) { case 0x06: Taste = ('4'); //Zuweisung des entsprechenden ASCII-Werts break; case 0x05: Taste = ('5'); break; case 0x03: Taste = ('6'); break; } P3OUT = 0xF8; // zweite Zeile (P3.4) inaktiv (high) } if (Taste == 0) { P3OUT = 0xD8; // dritte Zeile (P3.5) aktiv (low) waitKBD(20); switch (P3IN) { case 0x06: Taste = ('7'); //Zuweisung des entsprechenden ASCII-Werts break; case 0x05: Taste = ('8'); break; case 0x03: Taste = ('9'); break; } P3OUT = 0xF8; // dritte Zeile (P3.5) inaktiv (high) } if (Taste == 0) { P3OUT = 0xB8; // vierte Zeile (P3.6) aktiv (low) waitKBD(20); switch (P3IN) { case 0x06: Taste = ('.'); //Zuweisung des entsprechenden ASCII-Werts break; case 0x05: Taste = ('0'); break; case 0x03: Taste = ('#'); break; } P3OUT = 0xF8; // vierte Zeile (P3.6) inaktiv (high) } return(Taste); //Rückgabe des Tastenwerts } /********************************************** MainKBD.c **********************************************/ #include #include // Globale Variable unsigned int i; //main void main (void) { unsigned char Taste; 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) P1DIR = 0xFF; P2DIR = 0xFF; P4DIR = 0xFF; P6DIR = 0xFF; // alle Ports in Output-Richtung (user's Guide page 9-6: Configuring unused Port Pins) P3DIR |= 0xF8; // setzte P3.0 - P3.2 als Input und P3.3 - P3.7 als output P3OUT = 0x78; // P3.3-P3.6 = '1' P5DIR |= 0x02; // P5DIR.1 auf OUTPUT P5OUT =~ 0x02; // LED aus while (1) { Taste = KeyPressed(); switch (Taste) { case '1': P5OUT = 0x02; waitKBD(1000); P5OUT =~ 0x02; break; case '2': P5OUT = 0x02; waitKBD(1000); P5OUT =~ 0x02; break; case '3': P5OUT = 0x02; waitKBD(1000); P5OUT =~ 0x02; break; case '4': P5OUT = 0x02; waitKBD(1000); P5OUT =~ 0x02; break; case '5': P5OUT = 0x02; waitKBD(1000); P5OUT =~ 0x02; break; case '6': P5OUT = 0x02; waitKBD(1000); P5OUT =~ 0x02; break; case '7': P5OUT = 0x02; waitKBD(1000); P5OUT =~ 0x02; break; case '8': P5OUT = 0x02; waitKBD(1000); P5OUT =~ 0x02; break; case '9': P5OUT = 0x02; waitKBD(1000); P5OUT =~ 0x02; break; case '0': P5OUT = 0x02; waitKBD(1000); P5OUT =~ 0x02; break; case '.': P5OUT = 0x02; waitKBD(1000); P5OUT =~ 0x02; break; case '#': P5OUT = 0x02; waitKBD(1000); P5OUT =~ 0x02; break; } } }