Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp
00001 #include "mbed.h" 00002 Serial pc(USBTX, USBRX); // comms to host PC 00003 BusOut Seg1(p5,p6,p7,p8,p9,p10,p11,p12); // A,B,C,D,E,F,G,DP 00004 BusOut Seg2(p13,p14,p15,p16,p17,p18,p19,p20); // A,B,C,D,E,F,G,DP 00005 void SegInit(void); // function prototype 00006 void HostInit(void); // function prototype 00007 char GetKeyInput(void); // function prototype 00008 char SegConvert(char SegValue); // function prototype 00009 char data1, data2; // variable declarations 00010 int main() // main program 00011 { 00012 SegInit(); // call function to initialise the 7-seg displays 00013 HostInit(); // call function to initialise the host terminal 00014 while (1) { // infinite loop 00015 data2 = GetKeyInput(); // call function to get 1st key press 00016 Seg2=SegConvert(data2); // call function to convert and output 00017 data1 = GetKeyInput(); // call function to get 2nd key press 00018 Seg1=SegConvert(data1); // call function to convert and output 00019 pc.printf(" "); // display spaces between 2 digit numbers 00020 } 00021 } 00022 00023 void SegInit(void) 00024 { 00025 Seg1=SegConvert(0); // initialise to zero 00026 Seg2=SegConvert(0); // initialise to zero 00027 } 00028 void HostInit(void) 00029 { 00030 pc.printf("\n\rType two digit numbers to be displayed on the 7-seg display\n\r"); 00031 } 00032 char GetKeyInput(void) 00033 { 00034 char c = pc.getc(); // get keyboard data (note num. ascii range 0x30-0x39) 00035 pc.printf("%c",c); // print ascii value to host PC terminal 00036 return (c&0x0F); // return value as non-ascii (bitmask c with value 0x0F) 00037 } 00038 00039 char SegConvert(char SegValue) // function 'SegConvert' 00040 { 00041 char SegByte=0x00; 00042 switch (SegValue) { //DPGFEDCBA 00043 case 0 : 00044 SegByte = 0x3F; 00045 break; // 00111111 binary 00046 case 1 : 00047 SegByte = 0x06; 00048 break; // 00000110 binary 00049 case 2 : 00050 SegByte = 0x5B; 00051 break; // 01011011 binary 00052 case 3 : 00053 SegByte = 0x4F; 00054 break; // 01001111 binary 00055 case 4 : 00056 SegByte = 0x66; 00057 break; // 01100110 binary 00058 case 5 : 00059 SegByte = 0x6D; 00060 break; // 01101101 binary 00061 case 6 : 00062 SegByte = 0x7D; 00063 break; // 01111101 binary 00064 case 7 : 00065 SegByte = 0x07; 00066 break; // 00000111 binary 00067 case 8 : 00068 SegByte = 0x7F; 00069 break; // 01111111 binary 00070 case 9 : 00071 SegByte = 0x6F; 00072 break; // 01101111 binary 00073 } 00074 return SegByte; 00075 }
Generated on Wed Jul 13 2022 02:51:06 by
1.7.2