VT3_Hrvoje_Škrnjug

Dependencies:   mbed

Committer:
hskrnjug
Date:
Thu Nov 17 19:08:17 2016 +0000
Revision:
0:e248bae24902
VT3_Hrvoje_?krnjug

Who changed what in which revision?

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