by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"
main.cpp
00001 /* Program Example 6.2: Display counter for 0-99 00002 */ 00003 #include "mbed.h" 00004 BusOut Seg1(p5,p6,p7,p8,p9,p10,p11,p12); // A,B,C,D,E,F,G,DP 00005 BusOut Seg2(p13,p14,p15,p16,p17,p18,p19,p20); 00006 00007 char SegConvert(char SegValue); // function prototype 00008 int main() { // main program 00009 while (1) { // infinite loop 00010 for (char j=0;j<10;j++) { // counter loop 1 00011 Seg2=SegConvert(j); // tens column 00012 for (char i=0;i<10;i++) { // counter loop 2 00013 Seg1=SegConvert(i); // units column 00014 wait(0.2); 00015 } 00016 } 00017 } 00018 } 00019 00020 00021 00022 char SegConvert(char SegValue) { // function 'SegConvert' 00023 char SegByte=0x00; 00024 switch (SegValue) { //DP G F E D C B A 00025 case 0 : SegByte = 0x3F;break; // 0 0 1 1 1 1 1 1 binary 00026 case 1 : SegByte = 0x06;break; // 0 0 0 0 0 1 1 0 binary 00027 case 2 : SegByte = 0x5B;break; // 0 1 0 1 1 0 1 1 binary 00028 case 3 : SegByte = 0x4F;break; // 0 1 0 0 1 1 1 1 binary 00029 case 4 : SegByte = 0x66;break; // 0 1 1 0 0 1 1 0 binary 00030 case 5 : SegByte = 0x6D;break; // 0 1 1 0 1 1 0 1 binary 00031 case 6 : SegByte = 0x7D;break; // 0 1 1 1 1 1 0 1 binary 00032 case 7 : SegByte = 0x07;break; // 0 0 0 0 0 1 1 1 binary 00033 case 8 : SegByte = 0x7F;break; // 0 1 1 1 1 1 1 1 binary 00034 case 9 : SegByte = 0x6F;break; // 0 1 1 0 1 1 1 1 binary 00035 } 00036 return SegByte; 00037 } 00038 00039 00040
Generated on Fri Sep 30 2022 07:46:56 by 1.7.2