VT3_Dean_Fraj

Dependencies:   mbed

Committer:
dfraj
Date:
Thu Nov 17 18:04:17 2016 +0000
Revision:
0:2963997f2a2f
VT3_Dean_Fraj

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dfraj 0:2963997f2a2f 1 #include "mbed.h"
dfraj 0:2963997f2a2f 2 Serial pc(USBTX, USBRX); // comms to host PC
dfraj 0:2963997f2a2f 3 BusOut Seg1(p5,p6,p7,p8,p9,p10,p11,p12); // A,B,C,D,E,F,G,DP
dfraj 0:2963997f2a2f 4 BusOut Seg2(p13,p14,p15,p16,p17,p18,p19,p20); // A,B,C,D,E,F,G,DP
dfraj 0:2963997f2a2f 5 void SegInit(void); // function prototype
dfraj 0:2963997f2a2f 6 void HostInit(void); // function prototype
dfraj 0:2963997f2a2f 7 char GetKeyInput(void); // function prototype
dfraj 0:2963997f2a2f 8 char SegConvert(char SegValue); // function prototype
dfraj 0:2963997f2a2f 9 char data1, data2; // variable declarations
dfraj 0:2963997f2a2f 10 int main() // main program
dfraj 0:2963997f2a2f 11 {
dfraj 0:2963997f2a2f 12 SegInit(); // call function to initialise the 7-seg displays
dfraj 0:2963997f2a2f 13 HostInit(); // call function to initialise the host terminal
dfraj 0:2963997f2a2f 14 while (1) { // infinite loop
dfraj 0:2963997f2a2f 15 data2 = GetKeyInput(); // call function to get 1st key press
dfraj 0:2963997f2a2f 16 Seg2=SegConvert(data2); // call function to convert and output
dfraj 0:2963997f2a2f 17 data1 = GetKeyInput(); // call function to get 2nd key press
dfraj 0:2963997f2a2f 18 Seg1=SegConvert(data1); // call function to convert and output
dfraj 0:2963997f2a2f 19 pc.printf(" "); // display spaces between 2 digit numbers
dfraj 0:2963997f2a2f 20 }
dfraj 0:2963997f2a2f 21 }
dfraj 0:2963997f2a2f 22
dfraj 0:2963997f2a2f 23 void SegInit(void)
dfraj 0:2963997f2a2f 24 {
dfraj 0:2963997f2a2f 25 Seg1=SegConvert(0); // initialise to zero
dfraj 0:2963997f2a2f 26 Seg2=SegConvert(0); // initialise to zero
dfraj 0:2963997f2a2f 27 }
dfraj 0:2963997f2a2f 28 void HostInit(void)
dfraj 0:2963997f2a2f 29 {
dfraj 0:2963997f2a2f 30 pc.printf("\n\rType two digit numbers to be displayed on the 7-seg display\n\r");
dfraj 0:2963997f2a2f 31 }
dfraj 0:2963997f2a2f 32 char GetKeyInput(void)
dfraj 0:2963997f2a2f 33 {
dfraj 0:2963997f2a2f 34 char c = pc.getc(); // get keyboard data (note num. ascii range 0x30-0x39)
dfraj 0:2963997f2a2f 35 pc.printf("%c",c); // print ascii value to host PC terminal
dfraj 0:2963997f2a2f 36 return (c&0x0F); // return value as non-ascii (bitmask c with value 0x0F)
dfraj 0:2963997f2a2f 37 }
dfraj 0:2963997f2a2f 38
dfraj 0:2963997f2a2f 39 char SegConvert(char SegValue) // function 'SegConvert'
dfraj 0:2963997f2a2f 40 {
dfraj 0:2963997f2a2f 41 char SegByte=0x00;
dfraj 0:2963997f2a2f 42 switch (SegValue) { //DPGFEDCBA
dfraj 0:2963997f2a2f 43 case 0 :
dfraj 0:2963997f2a2f 44 SegByte = 0x3F;
dfraj 0:2963997f2a2f 45 break; // 00111111 binary
dfraj 0:2963997f2a2f 46 case 1 :
dfraj 0:2963997f2a2f 47 SegByte = 0x06;
dfraj 0:2963997f2a2f 48 break; // 00000110 binary
dfraj 0:2963997f2a2f 49 case 2 :
dfraj 0:2963997f2a2f 50 SegByte = 0x5B;
dfraj 0:2963997f2a2f 51 break; // 01011011 binary
dfraj 0:2963997f2a2f 52 case 3 :
dfraj 0:2963997f2a2f 53 SegByte = 0x4F;
dfraj 0:2963997f2a2f 54 break; // 01001111 binary
dfraj 0:2963997f2a2f 55 case 4 :
dfraj 0:2963997f2a2f 56 SegByte = 0x66;
dfraj 0:2963997f2a2f 57 break; // 01100110 binary
dfraj 0:2963997f2a2f 58 case 5 :
dfraj 0:2963997f2a2f 59 SegByte = 0x6D;
dfraj 0:2963997f2a2f 60 break; // 01101101 binary
dfraj 0:2963997f2a2f 61 case 6 :
dfraj 0:2963997f2a2f 62 SegByte = 0x7D;
dfraj 0:2963997f2a2f 63 break; // 01111101 binary
dfraj 0:2963997f2a2f 64 case 7 :
dfraj 0:2963997f2a2f 65 SegByte = 0x07;
dfraj 0:2963997f2a2f 66 break; // 00000111 binary
dfraj 0:2963997f2a2f 67 case 8 :
dfraj 0:2963997f2a2f 68 SegByte = 0x7F;
dfraj 0:2963997f2a2f 69 break; // 01111111 binary
dfraj 0:2963997f2a2f 70 case 9 :
dfraj 0:2963997f2a2f 71 SegByte = 0x6F;
dfraj 0:2963997f2a2f 72 break; // 01101111 binary
dfraj 0:2963997f2a2f 73 }
dfraj 0:2963997f2a2f 74 return SegByte;
dfraj 0:2963997f2a2f 75 }