Program broji od 0 - 9, prikazuje broj na 7 segmentnom displeju te binarni zapis tog broja je prikazan pomocu 4 zelene LED diode. U pozadini za vrijeme izvršavanja programa bijela LED dioda blinka što znaći da program radi ispravno. Kod interupta bijela LED se gasi, displej pokazuje broj na kojem je izvršen interupt te se jedna zelena LED dioda upali i ugasi 10 puta, nakon toga program nastavlja s brojenjem tamo gdje je stao.
Dependencies: Blink
OPIS: Sklop broji od 0 - 9, broj se prikazuje na 7 segmentnom displayu i u binarnom obliku preko 4 zelene LED diode. Kod izvođenja programa u pozadini blinka bijela LED dioda. Kada se pritisne integrirano tipkalo (interupt) na mbed plocici program se zaustavlja, prva zelena LED dioda upali se i ugasi 10 puta, a nakon toga program nastavlja gdje je i stao.
main.cpp@1:9889ea717cf8, 2021-02-19 (annotated)
- Committer:
- ikelekovi
- Date:
- Fri Feb 19 09:51:23 2021 +0000
- Revision:
- 1:9889ea717cf8
- Parent:
- 0:84d0732e7f5d
Konstrukcijski
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ikelekovi | 0:84d0732e7f5d | 1 | #include "mbed.h" |
ikelekovi | 0:84d0732e7f5d | 2 | #include "Blink.h" |
ikelekovi | 0:84d0732e7f5d | 3 | //Definiranje ulaza |
ikelekovi | 0:84d0732e7f5d | 4 | InterruptIn button(USER_BUTTON); |
ikelekovi | 0:84d0732e7f5d | 5 | |
ikelekovi | 0:84d0732e7f5d | 6 | //Definiranje tajmera |
ikelekovi | 0:84d0732e7f5d | 7 | Timer debounce; |
ikelekovi | 0:84d0732e7f5d | 8 | Timer Prekid1; |
ikelekovi | 0:84d0732e7f5d | 9 | Timer Prekid2; |
ikelekovi | 0:84d0732e7f5d | 10 | Ticker flipper; |
ikelekovi | 0:84d0732e7f5d | 11 | |
ikelekovi | 0:84d0732e7f5d | 12 | //Definifanje izlaza |
ikelekovi | 0:84d0732e7f5d | 13 | LED led1(D11); |
ikelekovi | 0:84d0732e7f5d | 14 | LED led2(D12); |
ikelekovi | 0:84d0732e7f5d | 15 | LED led3(D13); |
ikelekovi | 0:84d0732e7f5d | 16 | LED led4(D14); |
ikelekovi | 0:84d0732e7f5d | 17 | LED led5(D15); |
ikelekovi | 0:84d0732e7f5d | 18 | BusOut Seg1(D2,D3,D4,D5,D6,D7,D8,D9); |
ikelekovi | 0:84d0732e7f5d | 19 | |
ikelekovi | 0:84d0732e7f5d | 20 | //Definiranje funkcija |
ikelekovi | 0:84d0732e7f5d | 21 | char SegConvert(int SegValue); |
ikelekovi | 0:84d0732e7f5d | 22 | void Binary (int g); |
ikelekovi | 0:84d0732e7f5d | 23 | void prekid(void); |
ikelekovi | 0:84d0732e7f5d | 24 | |
ikelekovi | 0:84d0732e7f5d | 25 | //Funkcija upravljanja s 7 segmentnim displeom |
ikelekovi | 0:84d0732e7f5d | 26 | char SegConvert(int SegValue) { |
ikelekovi | 0:84d0732e7f5d | 27 | char SegByte=0x00; |
ikelekovi | 0:84d0732e7f5d | 28 | switch (SegValue) { |
ikelekovi | 0:84d0732e7f5d | 29 | case 0 : SegByte = 0x3F;break; |
ikelekovi | 0:84d0732e7f5d | 30 | case 1 : SegByte = 0x06;break; |
ikelekovi | 0:84d0732e7f5d | 31 | case 2 : SegByte = 0x5B;break; |
ikelekovi | 0:84d0732e7f5d | 32 | case 3 : SegByte = 0x4F;break; |
ikelekovi | 0:84d0732e7f5d | 33 | case 4 : SegByte = 0x66;break; |
ikelekovi | 0:84d0732e7f5d | 34 | case 5 : SegByte = 0x6D;break; |
ikelekovi | 0:84d0732e7f5d | 35 | case 6 : SegByte = 0x7D;break; |
ikelekovi | 0:84d0732e7f5d | 36 | case 7 : SegByte = 0x07;break; |
ikelekovi | 0:84d0732e7f5d | 37 | case 8 : SegByte = 0x7F;break; |
ikelekovi | 0:84d0732e7f5d | 38 | case 9 : SegByte = 0x6F;break; |
ikelekovi | 0:84d0732e7f5d | 39 | } |
ikelekovi | 0:84d0732e7f5d | 40 | return SegByte; |
ikelekovi | 0:84d0732e7f5d | 41 | } |
ikelekovi | 0:84d0732e7f5d | 42 | |
ikelekovi | 0:84d0732e7f5d | 43 | //Funkcija prekida |
ikelekovi | 0:84d0732e7f5d | 44 | void prekid() |
ikelekovi | 0:84d0732e7f5d | 45 | { |
ikelekovi | 0:84d0732e7f5d | 46 | if(debounce.read_ms()>200){ |
ikelekovi | 0:84d0732e7f5d | 47 | led1.status(0); |
ikelekovi | 0:84d0732e7f5d | 48 | led2.status(0); |
ikelekovi | 0:84d0732e7f5d | 49 | led3.status(0); |
ikelekovi | 0:84d0732e7f5d | 50 | led4.status(0); |
ikelekovi | 0:84d0732e7f5d | 51 | while(Prekid1.read()<=10){ |
ikelekovi | 0:84d0732e7f5d | 52 | Prekid1.start(); |
ikelekovi | 0:84d0732e7f5d | 53 | Prekid2.start(); |
ikelekovi | 0:84d0732e7f5d | 54 | if(Prekid2.read_ms()>=500) |
ikelekovi | 0:84d0732e7f5d | 55 | { |
ikelekovi | 0:84d0732e7f5d | 56 | led1.flip(); |
ikelekovi | 0:84d0732e7f5d | 57 | Prekid2.stop(); |
ikelekovi | 0:84d0732e7f5d | 58 | Prekid2.reset(); |
ikelekovi | 0:84d0732e7f5d | 59 | } |
ikelekovi | 0:84d0732e7f5d | 60 | } |
ikelekovi | 0:84d0732e7f5d | 61 | Prekid1.stop(); |
ikelekovi | 0:84d0732e7f5d | 62 | Prekid1.reset(); |
ikelekovi | 0:84d0732e7f5d | 63 | } |
ikelekovi | 0:84d0732e7f5d | 64 | debounce.reset(); |
ikelekovi | 0:84d0732e7f5d | 65 | } |
ikelekovi | 0:84d0732e7f5d | 66 | |
ikelekovi | 0:84d0732e7f5d | 67 | //Funkcija odredivanja stanja LED |
ikelekovi | 0:84d0732e7f5d | 68 | void Binary (int g) |
ikelekovi | 0:84d0732e7f5d | 69 | { |
ikelekovi | 0:84d0732e7f5d | 70 | switch (g) { |
ikelekovi | 0:84d0732e7f5d | 71 | case 0: { |
ikelekovi | 0:84d0732e7f5d | 72 | break; |
ikelekovi | 0:84d0732e7f5d | 73 | } |
ikelekovi | 0:84d0732e7f5d | 74 | case 1: { |
ikelekovi | 0:84d0732e7f5d | 75 | led1.flip(); |
ikelekovi | 0:84d0732e7f5d | 76 | break; |
ikelekovi | 0:84d0732e7f5d | 77 | } |
ikelekovi | 0:84d0732e7f5d | 78 | case 2: { |
ikelekovi | 0:84d0732e7f5d | 79 | led2.flip(); |
ikelekovi | 0:84d0732e7f5d | 80 | break; |
ikelekovi | 0:84d0732e7f5d | 81 | } |
ikelekovi | 0:84d0732e7f5d | 82 | case 3: { |
ikelekovi | 0:84d0732e7f5d | 83 | led1.flip(); |
ikelekovi | 0:84d0732e7f5d | 84 | led2.flip(); |
ikelekovi | 0:84d0732e7f5d | 85 | break; |
ikelekovi | 0:84d0732e7f5d | 86 | } |
ikelekovi | 0:84d0732e7f5d | 87 | case 4: { |
ikelekovi | 0:84d0732e7f5d | 88 | led3.flip(); |
ikelekovi | 0:84d0732e7f5d | 89 | break; |
ikelekovi | 0:84d0732e7f5d | 90 | } |
ikelekovi | 0:84d0732e7f5d | 91 | case 5: { |
ikelekovi | 0:84d0732e7f5d | 92 | led1.flip(); |
ikelekovi | 0:84d0732e7f5d | 93 | led3.flip(); |
ikelekovi | 0:84d0732e7f5d | 94 | break; |
ikelekovi | 0:84d0732e7f5d | 95 | } |
ikelekovi | 0:84d0732e7f5d | 96 | case 6: { |
ikelekovi | 0:84d0732e7f5d | 97 | led3.flip(); |
ikelekovi | 0:84d0732e7f5d | 98 | led2.flip(); |
ikelekovi | 0:84d0732e7f5d | 99 | break; |
ikelekovi | 0:84d0732e7f5d | 100 | } |
ikelekovi | 0:84d0732e7f5d | 101 | case 7: { |
ikelekovi | 0:84d0732e7f5d | 102 | led1.flip(); |
ikelekovi | 0:84d0732e7f5d | 103 | led2.flip(); |
ikelekovi | 0:84d0732e7f5d | 104 | led3.flip(); |
ikelekovi | 0:84d0732e7f5d | 105 | break; |
ikelekovi | 0:84d0732e7f5d | 106 | } |
ikelekovi | 0:84d0732e7f5d | 107 | case 8: { |
ikelekovi | 0:84d0732e7f5d | 108 | led4.flip(); |
ikelekovi | 0:84d0732e7f5d | 109 | break; |
ikelekovi | 0:84d0732e7f5d | 110 | } |
ikelekovi | 0:84d0732e7f5d | 111 | case 9: { |
ikelekovi | 0:84d0732e7f5d | 112 | led1.flip(); |
ikelekovi | 0:84d0732e7f5d | 113 | led4.flip(); |
ikelekovi | 0:84d0732e7f5d | 114 | break; |
ikelekovi | 0:84d0732e7f5d | 115 | } |
ikelekovi | 0:84d0732e7f5d | 116 | } |
ikelekovi | 0:84d0732e7f5d | 117 | } |
ikelekovi | 0:84d0732e7f5d | 118 | |
ikelekovi | 0:84d0732e7f5d | 119 | //funkcija Ticker-a |
ikelekovi | 0:84d0732e7f5d | 120 | void flip(){ |
ikelekovi | 0:84d0732e7f5d | 121 | led5.flip(); |
ikelekovi | 0:84d0732e7f5d | 122 | } |
ikelekovi | 0:84d0732e7f5d | 123 | |
ikelekovi | 0:84d0732e7f5d | 124 | //main funkcija |
ikelekovi | 0:84d0732e7f5d | 125 | int main() |
ikelekovi | 0:84d0732e7f5d | 126 | { |
ikelekovi | 0:84d0732e7f5d | 127 | debounce.start(); |
ikelekovi | 0:84d0732e7f5d | 128 | button.rise(&prekid); |
ikelekovi | 0:84d0732e7f5d | 129 | flipper.attach(&flip,0.2); |
ikelekovi | 0:84d0732e7f5d | 130 | int i; |
ikelekovi | 0:84d0732e7f5d | 131 | while(1){ |
ikelekovi | 0:84d0732e7f5d | 132 | for (i=0;i<10;i++){ |
ikelekovi | 0:84d0732e7f5d | 133 | led1.status(0); |
ikelekovi | 0:84d0732e7f5d | 134 | led2.status(0); |
ikelekovi | 0:84d0732e7f5d | 135 | led3.status(0); |
ikelekovi | 0:84d0732e7f5d | 136 | led4.status(0); |
ikelekovi | 0:84d0732e7f5d | 137 | Seg1=SegConvert(i); |
ikelekovi | 0:84d0732e7f5d | 138 | Binary(i); |
ikelekovi | 0:84d0732e7f5d | 139 | wait_ms(1000); |
ikelekovi | 0:84d0732e7f5d | 140 | } |
ikelekovi | 0:84d0732e7f5d | 141 | } |
ikelekovi | 0:84d0732e7f5d | 142 | } |