06-03 KeyPressDisplay
From Manuals
This program reads a number pressed on the personal computers keyboard while using a terminal program and displays the number on the 7 segment display.
The signals used for this example are listed below:
| Signal | LPC4330 PIN NAME | BAM210E | BAM210 | BAM200E | BAM200 | Used for |
| USBTX | P2_10 | MBED-HDK | MBED-HDK | S10-4 | n/p | MBED-HDK Serial RX |
| USBRX | P2_11 | MBED-HDK | MBED-HDK | s10-5 | n/p | MBED-HDK Serial TX |
| D0 | P6_5 | J9-1 | J9-1 | S2-5 | S2-5 | Ones Segment A |
| D1 | P6_4 | J9-2 | J9-2 | S2-4 | S2-4 | Ones Segment B |
| D2 | P1_7 | J9-3 | J9-3 | S3-7 | S3-7 | Ones Segment C |
| D3 | P4_0 | J9-3 | J9-3 | S3-7 | S3-7 | Ones Segment D |
| D4 | P6_9 | J9-4 | J9-4 | S8-7 | n/p | Ones Segment E |
| D5 | P5_5 | J9-5 | J9-5 | S3-8 | S3-8 | Ones Segment F |
| D6 | P5_7 | J9-6 | J9-6 | S3-9 | S3-9 | Ones Segment G |
| D7 | P7_6 | J9-7 | J9-7 | S4-6 | S4-6 | Ones Segment DP |
| D8 | P6_12 | J10-1 | J10-1 | S10-3 | n/p | Tens Segment A |
| D9 | P5_0 | J10-2 | J10-2 | S1-4 | S1-4 | Tens Segment B |
| D10 | P4_6 | J10-3 | J10-3 | S2-3 | S2-6 | Tens Segment C |
| D11 | P4_8 | J10-4 | J10-4 | S2-7 | S2-7 | Tens Segment D |
| D12 | P4_9 | J10-5 | J10-5 | S2-8 | S2-8 | Tens Segment E |
| D13 | P4_10 | J10-6 | J10-6 | S2-9 | S2-9 | Tens Segment F |
| D16 | P2_3 | J10-9 | J10-9 | S4-8 | S4-8 | Tens Segment G |
| D17 | P2_4 | J10-10 | J10-10 | S4-9 | S4-9 | Tens Segment DP |
The following schematic can be used to build the circuit with a BAM210E or BAM210.
File:BAM210 06 02 SCH.png
Schematic for example 06-03
/* Program Example 6.3: Host keypress to 7-seg display
*/
#include "mbed.h"
Serial pc(USBTX, USBRX); // comms to host PC
BusOut Seg1(D0,D1,D2,D3,D4,D5,D6,D7); // A,B,C,D,E,F,G,DP
BusOut Seg2(D8,D9,D10,D11,D12,D13,D16,D17); // A,B,C,D,E,F,G,DP
void SegInit(void); // function prototype
void HostInit(void); // function prototype
char GetKeyInput(void); // function prototype
char SegConvert(char SegValue); // function prototype
char data1, data2; // variable declarations
int main() { // main program
SegInit(); // call function to initialise the 7-seg displays
HostInit(); // call function to initialise the host terminal
while (1) { // infinite loop
data2 = GetKeyInput(); // call function to get 1st key press
Seg2=SegConvert(data2); // call function to convert and output
data1 = GetKeyInput(); // call function to get 2nd key press
Seg1=SegConvert(data1); // call function to convert and output
pc.printf(" "); // display spaces between numbers
}
}
// functions
void SegInit(void) {
Seg1=SegConvert(0); // initialise to zero
Seg2=SegConvert(0); // initialise to zero
}
void HostInit(void) {
pc.printf("\n\rType two digit numbers to be displayed\n\r");
}
char GetKeyInput(void) {
char c = pc.getc(); // get keyboard data (ascii 0x30-0x39)
pc.printf("%c",c); // print ascii value to host PC terminal
return (c&0x0F); // apply bit mask to convert to decimal, and return
}
char SegConvert(char SegValue) { // function 'SegConvert'
char SegByte=0x00;
switch (SegValue) { //DP G F E D C B A
case 0 : SegByte = 0x3F;break; // 0 0 1 1 1 1 1 1 binary
case 1 : SegByte = 0x06;break; // 0 0 0 0 0 1 1 0 binary
case 2 : SegByte = 0x5B;break; // 0 1 0 1 1 0 1 1 binary
case 3 : SegByte = 0x4F;break; // 0 1 0 0 1 1 1 1 binary
case 4 : SegByte = 0x66;break; // 0 1 1 0 0 1 1 0 binary
case 5 : SegByte = 0x6D;break; // 0 1 1 0 1 1 0 1 binary
case 6 : SegByte = 0x7D;break; // 0 1 1 1 1 1 0 1 binary
case 7 : SegByte = 0x07;break; // 0 0 0 0 0 1 1 1 binary
case 8 : SegByte = 0x7F;break; // 0 1 1 1 1 1 1 1 binary
case 9 : SegByte = 0x6F;break; // 0 1 1 0 1 1 1 1 binary
}
return SegByte;
}
The terminal window was captured in the image below.
The following image shows the built circuit on a BAM210E.


