SEARCH
TOOLBOX
LANGUAGES
modified on 14 August 2014 at 15:48 ••• 7,219 views

06-02 TwoDigitCounter

From Manuals

Revision as of 15:48, 14 August 2014 by Support (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This program counts 0 to 99 and displays them on a two digit common cathode 7-segment display.

/* Program Example 6.2: Display counter for 0-99
                                                              */
#include "mbed.h"
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);

char SegConvert(char SegValue);     // function prototype
int main() {                        // main program
  while (1) {                       // infinite loop
    for (char j=0;j<10;j++) {       // counter loop 1
      Seg2=SegConvert(j);           // tens column
      for (char i=0;i<10;i++) {     // counter loop 2
          Seg1=SegConvert(i);       // units column
          wait(0.2);
      }
    }
  }
}

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;
}



File:BAM210 06 02 SCH.png
Schematic for example 06-02