by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Dependencies:   mbed

Committer:
robt
Date:
Mon Oct 15 21:22:39 2012 +0000
Revision:
0:faf907fb2777
by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
robt 0:faf907fb2777 1 /* Program Example 6.2: Display counter for 0-99
robt 0:faf907fb2777 2 */
robt 0:faf907fb2777 3 #include "mbed.h"
robt 0:faf907fb2777 4 BusOut Seg1(p5,p6,p7,p8,p9,p10,p11,p12); // A,B,C,D,E,F,G,DP
robt 0:faf907fb2777 5 BusOut Seg2(p13,p14,p15,p16,p17,p18,p19,p20);
robt 0:faf907fb2777 6
robt 0:faf907fb2777 7 char SegConvert(char SegValue); // function prototype
robt 0:faf907fb2777 8 int main() { // main program
robt 0:faf907fb2777 9 while (1) { // infinite loop
robt 0:faf907fb2777 10 for (char j=0;j<10;j++) { // counter loop 1
robt 0:faf907fb2777 11 Seg2=SegConvert(j); // tens column
robt 0:faf907fb2777 12 for (char i=0;i<10;i++) { // counter loop 2
robt 0:faf907fb2777 13 Seg1=SegConvert(i); // units column
robt 0:faf907fb2777 14 wait(0.2);
robt 0:faf907fb2777 15 }
robt 0:faf907fb2777 16 }
robt 0:faf907fb2777 17 }
robt 0:faf907fb2777 18 }
robt 0:faf907fb2777 19
robt 0:faf907fb2777 20
robt 0:faf907fb2777 21
robt 0:faf907fb2777 22 char SegConvert(char SegValue) { // function 'SegConvert'
robt 0:faf907fb2777 23 char SegByte=0x00;
robt 0:faf907fb2777 24 switch (SegValue) { //DP G F E D C B A
robt 0:faf907fb2777 25 case 0 : SegByte = 0x3F;break; // 0 0 1 1 1 1 1 1 binary
robt 0:faf907fb2777 26 case 1 : SegByte = 0x06;break; // 0 0 0 0 0 1 1 0 binary
robt 0:faf907fb2777 27 case 2 : SegByte = 0x5B;break; // 0 1 0 1 1 0 1 1 binary
robt 0:faf907fb2777 28 case 3 : SegByte = 0x4F;break; // 0 1 0 0 1 1 1 1 binary
robt 0:faf907fb2777 29 case 4 : SegByte = 0x66;break; // 0 1 1 0 0 1 1 0 binary
robt 0:faf907fb2777 30 case 5 : SegByte = 0x6D;break; // 0 1 1 0 1 1 0 1 binary
robt 0:faf907fb2777 31 case 6 : SegByte = 0x7D;break; // 0 1 1 1 1 1 0 1 binary
robt 0:faf907fb2777 32 case 7 : SegByte = 0x07;break; // 0 0 0 0 0 1 1 1 binary
robt 0:faf907fb2777 33 case 8 : SegByte = 0x7F;break; // 0 1 1 1 1 1 1 1 binary
robt 0:faf907fb2777 34 case 9 : SegByte = 0x6F;break; // 0 1 1 0 1 1 1 1 binary
robt 0:faf907fb2777 35 }
robt 0:faf907fb2777 36 return SegByte;
robt 0:faf907fb2777 37 }
robt 0:faf907fb2777 38
robt 0:faf907fb2777 39
robt 0:faf907fb2777 40