Vježba 7.4
Dependencies: mbed
main.cpp@0:bb76d7021216, 2016-11-17 (annotated)
- Committer:
- imihalj
- Date:
- Thu Nov 17 17:35:13 2016 +0000
- Revision:
- 0:bb76d7021216
- Child:
- 1:d9a5781cd7ce
1 verzija
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 | 0:bb76d7021216 | 3 | char SegConvert(char SegValue); // function prototype |
imihalj | 0:bb76d7021216 | 4 | int main() // main program |
imihalj | 0:bb76d7021216 | 5 | { |
imihalj | 0:bb76d7021216 | 6 | while (1) { // infinite loop |
imihalj | 0:bb76d7021216 | 7 | for (char i=0; i<10; i++) { |
imihalj | 0:bb76d7021216 | 8 | Seg1=SegConvert(i); |
imihalj | 0:bb76d7021216 | 9 | wait(0.2); |
imihalj | 0:bb76d7021216 | 10 | } |
imihalj | 0:bb76d7021216 | 11 | } |
imihalj | 0:bb76d7021216 | 12 | } |
imihalj | 0:bb76d7021216 | 13 | char SegConvert(char SegValue) // function 'SegConvert' |
imihalj | 0:bb76d7021216 | 14 | { |
imihalj | 0:bb76d7021216 | 15 | char SegByte=0x00; |
imihalj | 0:bb76d7021216 | 16 | switch (SegValue) { //DPGFEDCBA |
imihalj | 0:bb76d7021216 | 17 | case 0 : |
imihalj | 0:bb76d7021216 | 18 | SegByte = 0x3F; |
imihalj | 0:bb76d7021216 | 19 | break; // 00111111 binary |
imihalj | 0:bb76d7021216 | 20 | case 1 : |
imihalj | 0:bb76d7021216 | 21 | SegByte = 0x06; |
imihalj | 0:bb76d7021216 | 22 | break; // 00000110 binary |
imihalj | 0:bb76d7021216 | 23 | case 2 : |
imihalj | 0:bb76d7021216 | 24 | SegByte = 0x5B; |
imihalj | 0:bb76d7021216 | 25 | break; // 01011011 binary |
imihalj | 0:bb76d7021216 | 26 | case 3 : |
imihalj | 0:bb76d7021216 | 27 | SegByte = 0x4F; |
imihalj | 0:bb76d7021216 | 28 | break; // 01001111 binary |
imihalj | 0:bb76d7021216 | 29 | case 4 : |
imihalj | 0:bb76d7021216 | 30 | SegByte = 0x66; |
imihalj | 0:bb76d7021216 | 31 | break; // 01100110 binary |
imihalj | 0:bb76d7021216 | 32 | case 5 : |
imihalj | 0:bb76d7021216 | 33 | SegByte = 0x6D; |
imihalj | 0:bb76d7021216 | 34 | break; // 01101101 binary |
imihalj | 0:bb76d7021216 | 35 | case 6 : |
imihalj | 0:bb76d7021216 | 36 | SegByte = 0x7D; |
imihalj | 0:bb76d7021216 | 37 | break; // 01111101 binary |
imihalj | 0:bb76d7021216 | 38 | case 7 : |
imihalj | 0:bb76d7021216 | 39 | SegByte = 0x07; |
imihalj | 0:bb76d7021216 | 40 | break; // 00000111 binary |
imihalj | 0:bb76d7021216 | 41 | case 8 : |
imihalj | 0:bb76d7021216 | 42 | SegByte = 0x7F; |
imihalj | 0:bb76d7021216 | 43 | break; // 01111111 binary |
imihalj | 0:bb76d7021216 | 44 | case 9 : |
imihalj | 0:bb76d7021216 | 45 | SegByte = 0x6F; |
imihalj | 0:bb76d7021216 | 46 | break; // 01101111 binary |
imihalj | 0:bb76d7021216 | 47 | } |
imihalj | 0:bb76d7021216 | 48 | return SegByte; |
imihalj | 0:bb76d7021216 | 49 | } |