Hisyam Sulaiman
/
lab2part7decreament
decrement
main.cpp@0:78c6e2cff91a, 2018-05-24 (annotated)
- Committer:
- HisyamSulaiman
- Date:
- Thu May 24 02:31:16 2018 +0000
- Revision:
- 0:78c6e2cff91a
decrement
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
HisyamSulaiman | 0:78c6e2cff91a | 1 | #include "mbed.h" |
HisyamSulaiman | 0:78c6e2cff91a | 2 | DigitalIn button (D4); |
HisyamSulaiman | 0:78c6e2cff91a | 3 | |
HisyamSulaiman | 0:78c6e2cff91a | 4 | char i; |
HisyamSulaiman | 0:78c6e2cff91a | 5 | BusOut seg1(D13,D12,D11,D10,D9,D8,D7); |
HisyamSulaiman | 0:78c6e2cff91a | 6 | char segConvert(char SegValue); |
HisyamSulaiman | 0:78c6e2cff91a | 7 | int main (){ |
HisyamSulaiman | 0:78c6e2cff91a | 8 | i=0; |
HisyamSulaiman | 0:78c6e2cff91a | 9 | while(1) { |
HisyamSulaiman | 0:78c6e2cff91a | 10 | |
HisyamSulaiman | 0:78c6e2cff91a | 11 | |
HisyamSulaiman | 0:78c6e2cff91a | 12 | if(button==1) |
HisyamSulaiman | 0:78c6e2cff91a | 13 | { |
HisyamSulaiman | 0:78c6e2cff91a | 14 | i=i+1 ; |
HisyamSulaiman | 0:78c6e2cff91a | 15 | seg1=segConvert(i); |
HisyamSulaiman | 0:78c6e2cff91a | 16 | wait(1); |
HisyamSulaiman | 0:78c6e2cff91a | 17 | while(button==1) |
HisyamSulaiman | 0:78c6e2cff91a | 18 | { |
HisyamSulaiman | 0:78c6e2cff91a | 19 | seg1=segConvert(i); |
HisyamSulaiman | 0:78c6e2cff91a | 20 | } |
HisyamSulaiman | 0:78c6e2cff91a | 21 | if (i==10) |
HisyamSulaiman | 0:78c6e2cff91a | 22 | { |
HisyamSulaiman | 0:78c6e2cff91a | 23 | i=0; |
HisyamSulaiman | 0:78c6e2cff91a | 24 | seg1=segConvert(i); |
HisyamSulaiman | 0:78c6e2cff91a | 25 | } |
HisyamSulaiman | 0:78c6e2cff91a | 26 | else |
HisyamSulaiman | 0:78c6e2cff91a | 27 | { |
HisyamSulaiman | 0:78c6e2cff91a | 28 | i=0; |
HisyamSulaiman | 0:78c6e2cff91a | 29 | seg1=segConvert(i); |
HisyamSulaiman | 0:78c6e2cff91a | 30 | |
HisyamSulaiman | 0:78c6e2cff91a | 31 | } |
HisyamSulaiman | 0:78c6e2cff91a | 32 | |
HisyamSulaiman | 0:78c6e2cff91a | 33 | |
HisyamSulaiman | 0:78c6e2cff91a | 34 | |
HisyamSulaiman | 0:78c6e2cff91a | 35 | |
HisyamSulaiman | 0:78c6e2cff91a | 36 | } |
HisyamSulaiman | 0:78c6e2cff91a | 37 | } |
HisyamSulaiman | 0:78c6e2cff91a | 38 | } |
HisyamSulaiman | 0:78c6e2cff91a | 39 | char segConvert(char SegValue) |
HisyamSulaiman | 0:78c6e2cff91a | 40 | { |
HisyamSulaiman | 0:78c6e2cff91a | 41 | char SegByte=0x00; |
HisyamSulaiman | 0:78c6e2cff91a | 42 | switch (SegValue) |
HisyamSulaiman | 0:78c6e2cff91a | 43 | { |
HisyamSulaiman | 0:78c6e2cff91a | 44 | case 0 : SegByte = 0x1;break; |
HisyamSulaiman | 0:78c6e2cff91a | 45 | case 1 : SegByte = 0x4f;break; |
HisyamSulaiman | 0:78c6e2cff91a | 46 | case 2 : SegByte = 0x12;break; |
HisyamSulaiman | 0:78c6e2cff91a | 47 | case 3 : SegByte = 0x6;break; |
HisyamSulaiman | 0:78c6e2cff91a | 48 | case 4 : SegByte = 0x4c;break; |
HisyamSulaiman | 0:78c6e2cff91a | 49 | case 5 : SegByte = 0x24;break; |
HisyamSulaiman | 0:78c6e2cff91a | 50 | case 6 : SegByte = 0x20;break; |
HisyamSulaiman | 0:78c6e2cff91a | 51 | case 7 : SegByte = 0xf;break; |
HisyamSulaiman | 0:78c6e2cff91a | 52 | case 8 : SegByte = 0x0;break; |
HisyamSulaiman | 0:78c6e2cff91a | 53 | case 9 : SegByte = 0xc;break; |
HisyamSulaiman | 0:78c6e2cff91a | 54 | } |
HisyamSulaiman | 0:78c6e2cff91a | 55 | return SegByte; |
HisyamSulaiman | 0:78c6e2cff91a | 56 | } |
HisyamSulaiman | 0:78c6e2cff91a | 57 |