Prvi test iz Praktikuma iz mikrokontrolera - ETF 2021
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 // Uvoz datoteka 00002 #include "mbed.h" 00003 00004 //Definisanje direktiva i glavnih promenljivih 00005 #define BR0 0x01 //10000 0001 00006 #define BR1 0x4F //10100 1111 00007 #define BR2 0x12 //10001 0010 00008 #define BR3 0x06 //10000 0110 00009 #define BR4 0x4C //10100 1100 00010 #define BR5 0x24 //10010 0100 00011 #define BR6 0x20 //10010 0000 00012 #define BR7 0x0F //10000 1111 00013 #define BR8 0x00 //10000 0000 00014 #define BR9 0x04 //10000 0100 00015 00016 // A B C D E F G 00017 BusOut display(PB_3, PB_4, PB_5, PB_10, PA_8, PA_9, PA_10); 00018 00019 DigitalOut SEL1(PB_6); 00020 DigitalOut SEL2(PC_7); 00021 DigitalIn SW1(PC_9); 00022 DigitalIn SW2(PC_8); 00023 //Pomocne funkcije 00024 00025 //Glavna funkija 00026 int main() 00027 { 00028 int broj = 0; 00029 SEL1.write(1); 00030 SEL2.write(0); 00031 display = BR0; 00032 while(true) 00033 { 00034 00035 if(SW1 == 0) 00036 { 00037 wait_ms(100); 00038 if(broj != 15) 00039 { 00040 broj++; 00041 } 00042 else 00043 { 00044 broj=0; 00045 } 00046 } 00047 00048 if(SW2 == 0) 00049 { 00050 wait_ms(100); 00051 if(broj != 0) 00052 { 00053 broj--; 00054 } 00055 else 00056 { 00057 broj=15; 00058 } 00059 } 00060 00061 if(broj == 0) 00062 { 00063 SEL1.write(1); 00064 SEL2.write(0); 00065 display = BR0; 00066 wait_ms(200); 00067 00068 } 00069 if(broj == 1) 00070 { 00071 SEL1.write(1); 00072 SEL2.write(0); 00073 display = BR1; 00074 wait_ms(200); 00075 } 00076 if(broj == 2) 00077 { 00078 SEL1.write(1); 00079 SEL2.write(0); 00080 display = BR2; 00081 wait_ms(200); 00082 } 00083 if(broj == 3) 00084 { 00085 SEL1.write(1); 00086 SEL2.write(0); 00087 display = BR3; 00088 wait_ms(200); 00089 } 00090 if(broj == 4) 00091 { 00092 SEL1.write(1); 00093 SEL2.write(0); 00094 display = BR4; 00095 wait_ms(200); 00096 } 00097 if(broj == 5) 00098 { 00099 SEL1.write(1); 00100 SEL2.write(0); 00101 display = BR5; 00102 wait_ms(200); 00103 } 00104 if(broj == 6) 00105 { 00106 SEL1.write(1); 00107 SEL2.write(0); 00108 display = BR6; 00109 wait_ms(200); 00110 } 00111 if(broj == 7) 00112 { 00113 SEL1.write(1); 00114 SEL2.write(0); 00115 display = BR7; 00116 wait_ms(200); 00117 } 00118 if(broj == 8) 00119 { 00120 SEL1.write(1); 00121 SEL2.write(0); 00122 display = BR8; 00123 wait_ms(200); 00124 } 00125 if(broj == 9) 00126 { 00127 SEL1.write(1); 00128 SEL2.write(0); 00129 display = BR9; 00130 wait_ms(200); 00131 } 00132 if(broj == 10) 00133 { 00134 SEL1.write(0); 00135 SEL2.write(1); 00136 display = BR1; 00137 wait_ms(10); 00138 SEL1.write(1); 00139 SEL2.write(0); 00140 display = BR0; 00141 wait_ms(10); 00142 00143 } 00144 if(broj == 11) 00145 { 00146 SEL1.write(0); 00147 SEL2.write(1); 00148 display = BR1; 00149 wait_ms(10); 00150 SEL1.write(1); 00151 SEL2.write(0); 00152 display = BR1; 00153 wait_ms(10); 00154 00155 } 00156 if(broj == 12) 00157 { 00158 SEL1.write(0); 00159 SEL2.write(1); 00160 display = BR1; 00161 wait_ms(10); 00162 SEL1.write(1); 00163 SEL2.write(0); 00164 display = BR2; 00165 wait_ms(10); 00166 00167 } 00168 if(broj == 13) 00169 { 00170 SEL1.write(0); 00171 SEL2.write(1); 00172 display = BR1; 00173 wait_ms(10); 00174 SEL1.write(1); 00175 SEL2.write(0); 00176 display = BR3; 00177 wait_ms(10); 00178 00179 } 00180 if(broj == 14) 00181 { 00182 SEL1.write(0); 00183 SEL2.write(1); 00184 display = BR1; 00185 wait_ms(10); 00186 SEL1.write(1); 00187 SEL2.write(0); 00188 display = BR4; 00189 wait_ms(10); 00190 00191 } 00192 if(broj == 15) 00193 { 00194 SEL1.write(0); 00195 SEL2.write(1); 00196 display = BR1; 00197 wait_ms(10); 00198 SEL1.write(1); 00199 SEL2.write(0); 00200 display = BR5; 00201 wait_ms(10); 00202 00203 } 00204 00205 00206 00207 00208 00209 00210 00211 00212 00213 00214 } 00215 } 00216
Generated on Sat Jul 30 2022 09:17:43 by
1.7.2