Mjerenje napona - 03.11

Dependencies:   mbed

Fork of VT1_Pervan by Applied engineering Team

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 void SegInit(void); // function to initialise 7-seg displays
00002 void HostInit(void); // function to initialise the host terminal
00003 char GetKeyInput(void); // function to get a keyboard input from the terminal
00004 char SegConvert(char SegValue); // function to convert a number to a 7-segment byte
00005 #include "mbed.h"
00006 Serial pc(USBTX, USBRX); // comms to host PC
00007 BusOut Seg1(p5,p6,p7,p8,p9,p10,p11,p12); // A,B,C,D,E,F,G,DP
00008 BusOut Seg2(p13,p14,p15,p16,p17,p18,p19,p20); // A,B,C,D,E,F,G,DP
00009 void SegInit(void); // function prototype
00010 void HostInit(void); // function prototype
00011 char GetKeyInput(void); // function prototype
00012 char SegConvert(char SegValue); // function prototype
00013 char data1, data2; // variable declarations
00014 int main() { // main program
00015 SegInit(); // call function to initialise the 7-seg displays
00016 HostInit(); // call function to initialise the host terminal
00017 while (1) { // infinite loop
00018 data2 = GetKeyInput(); // call function to get 1st key press
00019 Seg2=SegConvert(data2); // call function to convert and output
00020 data1 = GetKeyInput(); // call function to get 2nd key press
00021 Seg1=SegConvert(data1); // call function to convert and output
00022 pc.printf(" "); // display spaces between 2 digit numbers
00023 }
00024 }
00025 void SegInit(void) {
00026 Seg1=SegConvert(0); // initialise to zero
00027 Seg2=SegConvert(0); // initialise to zero
00028 }
00029 void HostInit(void) {
00030 pc.printf("\n\rType two digit numbers to be displayed on the 7-seg display\n\r");
00031 }
00032 char GetKeyInput(void) {
00033 char c = pc.getc(); // get keyboard data (note num. ascii range 0x30-0x39)
00034 pc.printf("%c",c); // print ascii value to host PC terminal
00035 return (c&0x0F); // return value as non-ascii (bitmask c with value 0x0F)
00036 }
00037 char SegConvert(char SegValue) { // function 'SegConvert'
00038 char SegByte=0x00;
00039 switch (SegValue) { //DPGFEDCBA
00040 case 0 : SegByte = 0x3F;break; // 00111111 binary
00041 case 1 : SegByte = 0x06;break; // 00000110 binary
00042 case 2 : SegByte = 0x5B;break; // 01011011 binary
00043 case 3 : SegByte = 0x4F;break; // 01001111 binary
00044 case 4 : SegByte = 0x66;break; // 01100110 binary
00045 case 5 : SegByte = 0x6D;break; // 01101101 binary
00046 case 6 : SegByte = 0x7D;break; // 01111101 binary
00047 case 7 : SegByte = 0x07;break; // 00000111 binary
00048 case 8 : SegByte = 0x7F;break; // 01111111 binary
00049 case 9 : SegByte = 0x6F;break; // 01101111 binary
00050 }
00051 return  SegByte;
00052 }