SEARCH
TOOLBOX
LANGUAGES
modified on 17 September 2014 at 18:13 ••• 14,980 views

06-01 SevenSegCounter

From Manuals

(Difference between revisions)
Jump to: navigation, search
 
Line 81: Line 81:
[[Image:BAM210_03_05_SCH.png|center|alt=BAM210|frame|<div align="center">'''Schematic for example 06-01''']]
[[Image:BAM210_03_05_SCH.png|center|alt=BAM210|frame|<div align="center">'''Schematic for example 06-01''']]
-
 
+
<div style="text-align: left;">
  /* Program Example 6.1: seven-segment display counter
  /* Program Example 6.1: seven-segment display counter
                                                               */
                                                               */

Current revision as of 18:13, 17 September 2014

This example displays a count 0-9 on a seven segment display.

The signals used for this example are listed below:

Signals Used and Connector Locations for Example 06-01
Signal LPC4330 PIN NAME BAM210E BAM210 BAM200E BAM200 Used for
D0 P6_5 J9-1 J9-1 S2-5 S2-5 Segment A
D1 P6_4 J9-2 J9-2 S2-4 S2-4 Segment B
D2 P1_7 J9-3 J9-3 S3-7 S3-7 Segment C
D3 P4_0 J9-3 J9-3 S3-7 S3-7 Segment D
D4 P6_9 J9-4 J9-4 S8-7 n/p Segment E
D5 P5_5 J9-5 J9-5 S3-8 S3-8 Segment F
D6 P5_7 J9-6 J9-6 S3-9 S3-9 Segment G
D7 P7_6 J9-7 J9-7 S4-6 S4-6 Segment DP

The following schematic can be used to build the circuit with a BAM210E or BAM210.

BAM210
Schematic for example 06-01
/* Program Example 6.1: seven-segment display counter
                                                              */
#include "mbed.h"

BusOut Seg1(D0,D1,D2,D3,D4,D5,D6,D7);   // A,B,C,D,E,F,G,DP
char SegConvert(char SegValue);         // function prototype
char A=0;                               // declare variables A and B
char B;

int main() {                            // main program
  while (1) {                           // infinite loop
    B=SegConvert(A);                    // Call function to return B
    Seg1=B;                             // Output B
    A++;                                // increment A
    if (A>0x09){                        // if A > 9 reset to zero
          A=0;
       }
    wait(0.5);                          // delay 500 milliseconds
  }
}

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 following image shows the built circuit on a BAM210E.