Vježba 7.4
Dependencies: mbed
main.cpp@1:d9a5781cd7ce, 2016-11-17 (annotated)
- Committer:
- imihalj
- Date:
- Thu Nov 17 17:49:11 2016 +0000
- Revision:
- 1:d9a5781cd7ce
- Parent:
- 0:bb76d7021216
radi
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
imihalj | 0:bb76d7021216 | 1 | #include "mbed.h" |
imihalj | 0:bb76d7021216 | 2 | BusOut Seg1(p5,p6,p7,p8,p9,p10,p11,p12); // A,B,C,D,E,F,G,DP |
imihalj | 1:d9a5781cd7ce | 3 | BusOut Seg2(p13,p14,p15,p16,p17,p18,p19,p20); |
imihalj | 0:bb76d7021216 | 4 | char SegConvert(char SegValue); // function prototype |
imihalj | 0:bb76d7021216 | 5 | int main() // main program |
imihalj | 0:bb76d7021216 | 6 | { |
imihalj | 0:bb76d7021216 | 7 | while (1) { // infinite loop |
imihalj | 1:d9a5781cd7ce | 8 | for (char j=0; j<10; j++) { // counter loop 1 |
imihalj | 1:d9a5781cd7ce | 9 | Seg2=SegConvert(j); // tens column |
imihalj | 1:d9a5781cd7ce | 10 | for (char i=0; i<10; i++) { // counter loop 2 |
imihalj | 1:d9a5781cd7ce | 11 | Seg1=SegConvert(i); // units column |
imihalj | 1:d9a5781cd7ce | 12 | wait(0.2); |
imihalj | 1:d9a5781cd7ce | 13 | } |
imihalj | 0:bb76d7021216 | 14 | } |
imihalj | 0:bb76d7021216 | 15 | } |
imihalj | 0:bb76d7021216 | 16 | } |
imihalj | 0:bb76d7021216 | 17 | char SegConvert(char SegValue) // function 'SegConvert' |
imihalj | 0:bb76d7021216 | 18 | { |
imihalj | 0:bb76d7021216 | 19 | char SegByte=0x00; |
imihalj | 0:bb76d7021216 | 20 | switch (SegValue) { //DPGFEDCBA |
imihalj | 0:bb76d7021216 | 21 | case 0 : |
imihalj | 0:bb76d7021216 | 22 | SegByte = 0x3F; |
imihalj | 0:bb76d7021216 | 23 | break; // 00111111 binary |
imihalj | 0:bb76d7021216 | 24 | case 1 : |
imihalj | 0:bb76d7021216 | 25 | SegByte = 0x06; |
imihalj | 0:bb76d7021216 | 26 | break; // 00000110 binary |
imihalj | 0:bb76d7021216 | 27 | case 2 : |
imihalj | 0:bb76d7021216 | 28 | SegByte = 0x5B; |
imihalj | 0:bb76d7021216 | 29 | break; // 01011011 binary |
imihalj | 0:bb76d7021216 | 30 | case 3 : |
imihalj | 0:bb76d7021216 | 31 | SegByte = 0x4F; |
imihalj | 0:bb76d7021216 | 32 | break; // 01001111 binary |
imihalj | 0:bb76d7021216 | 33 | case 4 : |
imihalj | 0:bb76d7021216 | 34 | SegByte = 0x66; |
imihalj | 0:bb76d7021216 | 35 | break; // 01100110 binary |
imihalj | 0:bb76d7021216 | 36 | case 5 : |
imihalj | 0:bb76d7021216 | 37 | SegByte = 0x6D; |
imihalj | 0:bb76d7021216 | 38 | break; // 01101101 binary |
imihalj | 0:bb76d7021216 | 39 | case 6 : |
imihalj | 0:bb76d7021216 | 40 | SegByte = 0x7D; |
imihalj | 0:bb76d7021216 | 41 | break; // 01111101 binary |
imihalj | 0:bb76d7021216 | 42 | case 7 : |
imihalj | 0:bb76d7021216 | 43 | SegByte = 0x07; |
imihalj | 0:bb76d7021216 | 44 | break; // 00000111 binary |
imihalj | 0:bb76d7021216 | 45 | case 8 : |
imihalj | 0:bb76d7021216 | 46 | SegByte = 0x7F; |
imihalj | 0:bb76d7021216 | 47 | break; // 01111111 binary |
imihalj | 0:bb76d7021216 | 48 | case 9 : |
imihalj | 0:bb76d7021216 | 49 | SegByte = 0x6F; |
imihalj | 0:bb76d7021216 | 50 | break; // 01101111 binary |
imihalj | 0:bb76d7021216 | 51 | } |
imihalj | 0:bb76d7021216 | 52 | return SegByte; |
imihalj | 0:bb76d7021216 | 53 | } |