06-05 ModularCodeExample
From Manuals
This program is an example that uses modular code. It performs the same function as Example 6.3. Using modular code allows programmers to reuse code. 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-05
/* Program Example 6.5: main.cpp file for modular 7-seg keyboard controller
This example program includes example code PE6.06, PE6.07, PE6.08, PE6.09
*/
#include "mbed.h"
#include "HostIO.h"
#include "SegDisplay.h"
char data1, data2; // variable declarations
int main() { // main program
SegInit(); // call init function
HostInit(); // call init function
while (1) { // infinite loop
data2 = GetKeyInput(); // call to get 1st key press
Seg2 = SegConvert(data2); // call to convert and output
data1 = GetKeyInput(); // call to get 2nd key press
Seg1 = SegConvert(data1); // call to convert and output
pc.printf(" "); // display spaces on host
}
}
The terminal window was captured in the image below.
The following image shows the built circuit on a BAM210E.


