Mjerenje napona - 03.11

Dependencies:   mbed

Fork of VT1_Pervan by Applied engineering Team

Committer:
fpervan
Date:
Thu Nov 17 19:34:57 2016 +0000
Revision:
6:4c46c5ba3aa3
Parent:
5:0406c84a3d6f
Child:
7:90c8a704c9f0
VT3_Filip_Pervan

Who changed what in which revision?

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