Vjezba V_7_6

Dependencies:   mbed

Committer:
jnovosel
Date:
Thu Nov 17 18:02:37 2016 +0000
Revision:
0:16dfd26ae925
vjezba V7_6

Who changed what in which revision?

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