Things2Do
Dependencies: DebounceIn PinDetect SI570 Si5351A mbed
Fork of t2d by
main.cpp@20:e498fd789660, 2018-03-12 (annotated)
- Committer:
- aaitihda
- Date:
- Mon Mar 12 15:39:04 2018 +0000
- Revision:
- 20:e498fd789660
- Parent:
- 19:7f10a8469c31
PCB progamming code;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dan | 0:7dec7e9ac085 | 1 | #include "mbed.h" |
davcordova | 19:7f10a8469c31 | 2 | #include "si5351a.h" |
aaitihda | 20:e498fd789660 | 3 | #include "PinDetect.h" |
aaitihda | 20:e498fd789660 | 4 | #include "DebounceIn.h" |
aaitihda | 20:e498fd789660 | 5 | |
aaitihda | 20:e498fd789660 | 6 | #define MIN_FREQ 20000000 |
aaitihda | 20:e498fd789660 | 7 | #define MAX_FREQ 120000000 |
aaitihda | 20:e498fd789660 | 8 | #define STEP_FREQ 100000 |
aaitihda | 20:e498fd789660 | 9 | #define RESET_FREQ 35000000 |
aaitihda | 20:e498fd789660 | 10 | |
aaitihda | 20:e498fd789660 | 11 | // Interrupt on digital pushbutton |
aaitihda | 20:e498fd789660 | 12 | PinDetect buttonReset(p13); |
aaitihda | 20:e498fd789660 | 13 | PinDetect buttonData(p11); |
aaitihda | 20:e498fd789660 | 14 | PinDetect buttonIref(p12); |
aaitihda | 20:e498fd789660 | 15 | PinDetect buttonStep(p23); |
aaitihda | 20:e498fd789660 | 16 | |
davcordova | 19:7f10a8469c31 | 17 | |
aaitihda | 20:e498fd789660 | 18 | // periodic interrupt routines |
aaitihda | 20:e498fd789660 | 19 | Ticker data_out; |
aaitihda | 20:e498fd789660 | 20 | Ticker clock_out; |
davcordova | 19:7f10a8469c31 | 21 | |
aaitihda | 20:e498fd789660 | 22 | // data, clk, iref switch output |
aaitihda | 20:e498fd789660 | 23 | DigitalOut data(p15); |
aaitihda | 20:e498fd789660 | 24 | DigitalOut clk(p14); |
aaitihda | 20:e498fd789660 | 25 | DigitalOut iref_sw(p16); |
aaitihda | 20:e498fd789660 | 26 | |
aaitihda | 20:e498fd789660 | 27 | //Encoder |
aaitihda | 20:e498fd789660 | 28 | DigitalIn A(p22); |
aaitihda | 20:e498fd789660 | 29 | DigitalIn B(p21); |
aaitihda | 20:e498fd789660 | 30 | |
aaitihda | 20:e498fd789660 | 31 | |
aaitihda | 20:e498fd789660 | 32 | // Leds |
aaitihda | 20:e498fd789660 | 33 | DigitalOut led1(LED1); |
aaitihda | 20:e498fd789660 | 34 | DigitalOut led2(LED2); |
aaitihda | 20:e498fd789660 | 35 | DigitalOut led3(LED3); |
aaitihda | 20:e498fd789660 | 36 | DigitalOut led4(LED4); |
aaitihda | 20:e498fd789660 | 37 | |
dan | 0:7dec7e9ac085 | 38 | |
aaitihda | 20:e498fd789660 | 39 | // setup terminal link |
aaitihda | 20:e498fd789660 | 40 | Serial pc(USBTX,USBRX); |
aaitihda | 20:e498fd789660 | 41 | |
aaitihda | 20:e498fd789660 | 42 | // Comparateur Threshold |
aaitihda | 20:e498fd789660 | 43 | AnalogOut Vth(p18); |
aaitihda | 20:e498fd789660 | 44 | |
aaitihda | 20:e498fd789660 | 45 | // communication with Si5351A I2C_SDA=p9 & I2C_SCL=p10 |
aaitihda | 20:e498fd789660 | 46 | I2C i2c(p9, p10); |
davcordova | 19:7f10a8469c31 | 47 | |
aaitihda | 20:e498fd789660 | 48 | // Base clock = 25MHz |
aaitihda | 20:e498fd789660 | 49 | SI5351A ckref(i2c, 25000000UL,SI5351_CRYSTAL_LOAD_8PF,SI5351_CLK_DRIVE_STRENGTH_8MA); |
aaitihda | 20:e498fd789660 | 50 | |
aaitihda | 20:e498fd789660 | 51 | // define local file system |
aaitihda | 20:e498fd789660 | 52 | LocalFileSystem local("local"); |
aaitihda | 20:e498fd789660 | 53 | |
aaitihda | 20:e498fd789660 | 54 | //Interruption function |
aaitihda | 20:e498fd789660 | 55 | void toggle(void); |
aaitihda | 20:e498fd789660 | 56 | void initialisation(void); |
aaitihda | 20:e498fd789660 | 57 | void stepChange(void); |
aaitihda | 20:e498fd789660 | 58 | void reset(void); |
aaitihda | 20:e498fd789660 | 59 | |
davcordova | 19:7f10a8469c31 | 60 | |
aaitihda | 20:e498fd789660 | 61 | //read the data from the .txt file |
aaitihda | 20:e498fd789660 | 62 | uint16_t read_data (int); |
aaitihda | 20:e498fd789660 | 63 | |
aaitihda | 20:e498fd789660 | 64 | //convert decemal to binary |
aaitihda | 20:e498fd789660 | 65 | uint16_t * set_dec2bin (uint16_t); |
aaitihda | 20:e498fd789660 | 66 | |
aaitihda | 20:e498fd789660 | 67 | //send the data to programm the divider |
aaitihda | 20:e498fd789660 | 68 | void send_data (void); |
aaitihda | 20:e498fd789660 | 69 | |
aaitihda | 20:e498fd789660 | 70 | //send the clock to programm the divider |
aaitihda | 20:e498fd789660 | 71 | void send_clk (void); |
aaitihda | 20:e498fd789660 | 72 | |
aaitihda | 20:e498fd789660 | 73 | // turn all the leds off |
aaitihda | 20:e498fd789660 | 74 | void allLedsOff(void); |
aaitihda | 20:e498fd789660 | 75 | |
aaitihda | 20:e498fd789660 | 76 | // turn all the leds on |
aaitihda | 20:e498fd789660 | 77 | void allLedsOn(void); |
aaitihda | 20:e498fd789660 | 78 | |
aaitihda | 20:e498fd789660 | 79 | //Variabeles |
aaitihda | 20:e498fd789660 | 80 | int divider, mode, resetFreq(RESET_FREQ), stepFreq(STEP_FREQ); |
aaitihda | 20:e498fd789660 | 81 | uint16_t *div_bin; // pointer |
aaitihda | 20:e498fd789660 | 82 | int count_data,count_clk,counter(0),stepCount(0),thresholdVoltage(0); |
aaitihda | 20:e498fd789660 | 83 | int aLastState(0); |
dan | 0:7dec7e9ac085 | 84 | |
aaitihda | 20:e498fd789660 | 85 | int main (){ |
aaitihda | 20:e498fd789660 | 86 | |
aaitihda | 20:e498fd789660 | 87 | //Config the interrupt button with the debouncing |
aaitihda | 20:e498fd789660 | 88 | buttonReset.mode(PullUp); |
aaitihda | 20:e498fd789660 | 89 | wait(0.01); |
aaitihda | 20:e498fd789660 | 90 | buttonReset.attach_asserted(&reset); |
aaitihda | 20:e498fd789660 | 91 | |
aaitihda | 20:e498fd789660 | 92 | buttonStep.mode(PullUp); |
aaitihda | 20:e498fd789660 | 93 | wait(0.01); |
aaitihda | 20:e498fd789660 | 94 | buttonStep.attach_asserted(&stepChange); |
aaitihda | 20:e498fd789660 | 95 | |
aaitihda | 20:e498fd789660 | 96 | buttonData.mode(PullUp); |
aaitihda | 20:e498fd789660 | 97 | wait(0.01); |
aaitihda | 20:e498fd789660 | 98 | buttonData.attach_asserted(&toggle); |
aaitihda | 20:e498fd789660 | 99 | |
aaitihda | 20:e498fd789660 | 100 | buttonIref.mode(PullUp); |
aaitihda | 20:e498fd789660 | 101 | wait(0.01); |
aaitihda | 20:e498fd789660 | 102 | buttonIref.attach_asserted(&initialisation); |
aaitihda | 20:e498fd789660 | 103 | |
aaitihda | 20:e498fd789660 | 104 | buttonReset.setSampleFrequency(); |
aaitihda | 20:e498fd789660 | 105 | buttonIref.setSampleFrequency(); |
aaitihda | 20:e498fd789660 | 106 | buttonData.setSampleFrequency(); |
aaitihda | 20:e498fd789660 | 107 | buttonStep.setSampleFrequency(); |
aaitihda | 20:e498fd789660 | 108 | |
aaitihda | 20:e498fd789660 | 109 | //Init the variables |
aaitihda | 20:e498fd789660 | 110 | ckref.set_frequency(SI5351_CLK0, RESET_FREQ); // CLK0=48MHz |
aaitihda | 20:e498fd789660 | 111 | data = 0; |
aaitihda | 20:e498fd789660 | 112 | clk = 0; |
aaitihda | 20:e498fd789660 | 113 | aLastState = A; |
davcordova | 19:7f10a8469c31 | 114 | |
aaitihda | 20:e498fd789660 | 115 | //Getting the data from the file |
aaitihda | 20:e498fd789660 | 116 | divider = read_data(0); |
aaitihda | 20:e498fd789660 | 117 | div_bin = set_dec2bin(divider); |
aaitihda | 20:e498fd789660 | 118 | mode = read_data(1); |
aaitihda | 20:e498fd789660 | 119 | resetFreq = read_data(2)*1000000; |
aaitihda | 20:e498fd789660 | 120 | stepFreq = read_data(3); |
aaitihda | 20:e498fd789660 | 121 | counter = resetFreq; |
aaitihda | 20:e498fd789660 | 122 | thresholdVoltage = read_data(4); |
aaitihda | 20:e498fd789660 | 123 | Vth = ((double)thresholdVoltage/1000) * 0.3f; |
aaitihda | 20:e498fd789660 | 124 | // Loop |
aaitihda | 20:e498fd789660 | 125 | while(1){ |
aaitihda | 20:e498fd789660 | 126 | if (A != aLastState){ |
aaitihda | 20:e498fd789660 | 127 | if(B != A) |
aaitihda | 20:e498fd789660 | 128 | counter = counter + stepFreq; |
aaitihda | 20:e498fd789660 | 129 | else |
aaitihda | 20:e498fd789660 | 130 | counter = counter - stepFreq; |
davcordova | 19:7f10a8469c31 | 131 | } |
aaitihda | 20:e498fd789660 | 132 | aLastState = A; |
aaitihda | 20:e498fd789660 | 133 | if(stepCount == 0){ |
aaitihda | 20:e498fd789660 | 134 | allLedsOff(); |
aaitihda | 20:e498fd789660 | 135 | led1 = 1; |
davcordova | 19:7f10a8469c31 | 136 | } |
aaitihda | 20:e498fd789660 | 137 | else if (stepCount == 1){ |
aaitihda | 20:e498fd789660 | 138 | allLedsOff(); |
aaitihda | 20:e498fd789660 | 139 | led2 = 1; |
aaitihda | 20:e498fd789660 | 140 | } |
aaitihda | 20:e498fd789660 | 141 | else if (stepCount == 2){ |
aaitihda | 20:e498fd789660 | 142 | allLedsOff(); |
aaitihda | 20:e498fd789660 | 143 | led3 = 1; |
davcordova | 19:7f10a8469c31 | 144 | } |
aaitihda | 20:e498fd789660 | 145 | else if (stepCount == 3){ |
aaitihda | 20:e498fd789660 | 146 | allLedsOff(); |
aaitihda | 20:e498fd789660 | 147 | led4 = 1; |
aaitihda | 20:e498fd789660 | 148 | } |
aaitihda | 20:e498fd789660 | 149 | ckref.set_frequency(SI5351_CLK0, counter); |
aaitihda | 20:e498fd789660 | 150 | wait(0.2); |
aaitihda | 20:e498fd789660 | 151 | printf("frequence : %d threshold voltage: %1.2f volts\n\r", counter, Vth.read() * 3.3f); |
aaitihda | 20:e498fd789660 | 152 | } |
aaitihda | 20:e498fd789660 | 153 | } |
davcordova | 19:7f10a8469c31 | 154 | |
aaitihda | 20:e498fd789660 | 155 | void allLedsOff(){ |
aaitihda | 20:e498fd789660 | 156 | led1 = 0; |
aaitihda | 20:e498fd789660 | 157 | led2 = 0; |
aaitihda | 20:e498fd789660 | 158 | led3 = 0; |
aaitihda | 20:e498fd789660 | 159 | led4 = 0; |
aaitihda | 20:e498fd789660 | 160 | } |
davcordova | 19:7f10a8469c31 | 161 | |
aaitihda | 20:e498fd789660 | 162 | void allLedsOn(){ |
aaitihda | 20:e498fd789660 | 163 | led1 = 1; |
aaitihda | 20:e498fd789660 | 164 | led2 = 1; |
aaitihda | 20:e498fd789660 | 165 | led3 = 1; |
aaitihda | 20:e498fd789660 | 166 | led4 = 1; |
aaitihda | 20:e498fd789660 | 167 | } |
aaitihda | 20:e498fd789660 | 168 | |
aaitihda | 20:e498fd789660 | 169 | //Interrupt fonction |
aaitihda | 20:e498fd789660 | 170 | void reset(){ |
aaitihda | 20:e498fd789660 | 171 | counter = resetFreq; |
aaitihda | 20:e498fd789660 | 172 | allLedsOn(); |
aaitihda | 20:e498fd789660 | 173 | wait(0.5); |
aaitihda | 20:e498fd789660 | 174 | allLedsOff(); |
aaitihda | 20:e498fd789660 | 175 | wait(0.2); |
aaitihda | 20:e498fd789660 | 176 | allLedsOn(); |
aaitihda | 20:e498fd789660 | 177 | wait(0.5); |
aaitihda | 20:e498fd789660 | 178 | allLedsOff(); |
aaitihda | 20:e498fd789660 | 179 | } |
aaitihda | 20:e498fd789660 | 180 | |
aaitihda | 20:e498fd789660 | 181 | void initialisation(){ |
aaitihda | 20:e498fd789660 | 182 | iref_sw = 1; |
aaitihda | 20:e498fd789660 | 183 | allLedsOn(); |
aaitihda | 20:e498fd789660 | 184 | wait(5); |
aaitihda | 20:e498fd789660 | 185 | iref_sw = 0; |
aaitihda | 20:e498fd789660 | 186 | allLedsOff(); |
aaitihda | 20:e498fd789660 | 187 | } |
davcordova | 19:7f10a8469c31 | 188 | |
aaitihda | 20:e498fd789660 | 189 | void toggle() { |
davcordova | 19:7f10a8469c31 | 190 | data_out.attach(&send_data, 0.01); |
davcordova | 19:7f10a8469c31 | 191 | wait(0.005); |
davcordova | 19:7f10a8469c31 | 192 | clock_out.attach(&send_clk, 0.005); |
aaitihda | 20:e498fd789660 | 193 | count_data = 0; |
aaitihda | 20:e498fd789660 | 194 | count_clk = 0; |
aaitihda | 20:e498fd789660 | 195 | allLedsOff(); |
aaitihda | 20:e498fd789660 | 196 | led1 = 1; |
aaitihda | 20:e498fd789660 | 197 | wait(0.2); |
aaitihda | 20:e498fd789660 | 198 | led1 = 0; |
aaitihda | 20:e498fd789660 | 199 | led2 = 1; |
aaitihda | 20:e498fd789660 | 200 | wait(0.2); |
aaitihda | 20:e498fd789660 | 201 | led2 = 0; |
aaitihda | 20:e498fd789660 | 202 | led3 = 1; |
aaitihda | 20:e498fd789660 | 203 | wait(0.2); |
aaitihda | 20:e498fd789660 | 204 | led3 = 0; |
aaitihda | 20:e498fd789660 | 205 | led4 = 1; |
aaitihda | 20:e498fd789660 | 206 | wait(0.2); |
aaitihda | 20:e498fd789660 | 207 | led4 = 0; |
davcordova | 19:7f10a8469c31 | 208 | } |
aaitihda | 20:e498fd789660 | 209 | |
aaitihda | 20:e498fd789660 | 210 | void stepChange(){ |
aaitihda | 20:e498fd789660 | 211 | if(stepCount == 3) |
aaitihda | 20:e498fd789660 | 212 | stepCount = 0; |
aaitihda | 20:e498fd789660 | 213 | else |
aaitihda | 20:e498fd789660 | 214 | stepCount++; |
aaitihda | 20:e498fd789660 | 215 | if(stepCount == 0){ |
aaitihda | 20:e498fd789660 | 216 | allLedsOff(); |
aaitihda | 20:e498fd789660 | 217 | stepFreq = stepFreq*1000; |
aaitihda | 20:e498fd789660 | 218 | led1 = 1; |
aaitihda | 20:e498fd789660 | 219 | } |
aaitihda | 20:e498fd789660 | 220 | else if (stepCount == 1){ |
aaitihda | 20:e498fd789660 | 221 | allLedsOff(); |
aaitihda | 20:e498fd789660 | 222 | stepFreq = stepFreq*10000; |
aaitihda | 20:e498fd789660 | 223 | led2 = 1; |
aaitihda | 20:e498fd789660 | 224 | } |
aaitihda | 20:e498fd789660 | 225 | else if (stepCount == 2){ |
aaitihda | 20:e498fd789660 | 226 | allLedsOff(); |
aaitihda | 20:e498fd789660 | 227 | stepFreq = stepFreq*100000; |
aaitihda | 20:e498fd789660 | 228 | led3 = 1; |
aaitihda | 20:e498fd789660 | 229 | } |
aaitihda | 20:e498fd789660 | 230 | else{ |
aaitihda | 20:e498fd789660 | 231 | allLedsOff(); |
aaitihda | 20:e498fd789660 | 232 | stepFreq = stepFreq*1000000; |
aaitihda | 20:e498fd789660 | 233 | led4 = 1; |
aaitihda | 20:e498fd789660 | 234 | } |
aaitihda | 20:e498fd789660 | 235 | } |
aaitihda | 20:e498fd789660 | 236 | |
aaitihda | 20:e498fd789660 | 237 | |
aaitihda | 20:e498fd789660 | 238 | void send_data (void){ |
aaitihda | 20:e498fd789660 | 239 | if(count_data<12){ |
aaitihda | 20:e498fd789660 | 240 | if(mode==0){ |
aaitihda | 20:e498fd789660 | 241 | data= *(div_bin+count_data); |
aaitihda | 20:e498fd789660 | 242 | pc.printf("%d",*(div_bin+count_data)); |
aaitihda | 20:e498fd789660 | 243 | count_data=count_data+1; |
aaitihda | 20:e498fd789660 | 244 | } |
aaitihda | 20:e498fd789660 | 245 | if(mode==1) { |
aaitihda | 20:e498fd789660 | 246 | data= *(div_bin+11-count_data); |
aaitihda | 20:e498fd789660 | 247 | pc.printf("%d",*(div_bin+11-count_data)); |
aaitihda | 20:e498fd789660 | 248 | count_data=count_data+1; |
aaitihda | 20:e498fd789660 | 249 | } |
aaitihda | 20:e498fd789660 | 250 | } |
aaitihda | 20:e498fd789660 | 251 | else |
aaitihda | 20:e498fd789660 | 252 | data=0; |
aaitihda | 20:e498fd789660 | 253 | } |
aaitihda | 20:e498fd789660 | 254 | |
aaitihda | 20:e498fd789660 | 255 | void send_clk (void){ |
aaitihda | 20:e498fd789660 | 256 | if(count_clk<24) { |
aaitihda | 20:e498fd789660 | 257 | clk=!clk; |
aaitihda | 20:e498fd789660 | 258 | count_clk=count_clk+1; |
aaitihda | 20:e498fd789660 | 259 | } |
aaitihda | 20:e498fd789660 | 260 | else { |
aaitihda | 20:e498fd789660 | 261 | clk=0;; |
aaitihda | 20:e498fd789660 | 262 | } |
aaitihda | 20:e498fd789660 | 263 | } |
aaitihda | 20:e498fd789660 | 264 | |
aaitihda | 20:e498fd789660 | 265 | uint16_t read_data (int mode) |
aaitihda | 20:e498fd789660 | 266 | { |
aaitihda | 20:e498fd789660 | 267 | int value; |
aaitihda | 20:e498fd789660 | 268 | int i,j; |
aaitihda | 20:e498fd789660 | 269 | char text[10][10]; // when the file exist and have data |
aaitihda | 20:e498fd789660 | 270 | char line[10]; // it reads line by line |
aaitihda | 20:e498fd789660 | 271 | |
aaitihda | 20:e498fd789660 | 272 | for(i=0; i<10; i++) |
aaitihda | 20:e498fd789660 | 273 | for(j=0; j<10; j++) |
aaitihda | 20:e498fd789660 | 274 | text[i][j] = '\0'; // initializing the vector with null |
aaitihda | 20:e498fd789660 | 275 | for(i=0; i<10; i++) |
aaitihda | 20:e498fd789660 | 276 | line[i] = '\0'; |
aaitihda | 20:e498fd789660 | 277 | |
aaitihda | 20:e498fd789660 | 278 | FILE* fp = fopen ("/local/div_prog.txt","r"); // open file for reading |
aaitihda | 20:e498fd789660 | 279 | if (fp!=NULL){ |
aaitihda | 20:e498fd789660 | 280 | fseek (fp, 0, SEEK_END); |
aaitihda | 20:e498fd789660 | 281 | int size = ftell(fp); |
aaitihda | 20:e498fd789660 | 282 | if (size==0){ |
aaitihda | 20:e498fd789660 | 283 | pc.printf("File is empty\n\r"); |
aaitihda | 20:e498fd789660 | 284 | } |
aaitihda | 20:e498fd789660 | 285 | else{ |
aaitihda | 20:e498fd789660 | 286 | rewind (fp); // restore pointer to the begin of the file |
aaitihda | 20:e498fd789660 | 287 | i=0; |
aaitihda | 20:e498fd789660 | 288 | while ( fgets ( line, sizeof line, fp ) != NULL ){ /* read a line */ |
aaitihda | 20:e498fd789660 | 289 | strcpy(text[i], line); |
aaitihda | 20:e498fd789660 | 290 | printf("array ----> %s", text[i]); |
aaitihda | 20:e498fd789660 | 291 | i++; |
aaitihda | 20:e498fd789660 | 292 | } |
aaitihda | 20:e498fd789660 | 293 | fclose(fp); // close file |
aaitihda | 20:e498fd789660 | 294 | if(mode==0){// Get the divider value |
aaitihda | 20:e498fd789660 | 295 | value=atoi(text[mode]); |
aaitihda | 20:e498fd789660 | 296 | pc.printf("Divider value = %d \n\r",value); // display read data value |
aaitihda | 20:e498fd789660 | 297 | } |
aaitihda | 20:e498fd789660 | 298 | if(mode==1){// Get the Mode (LSB/MSB) |
aaitihda | 20:e498fd789660 | 299 | value=atoi(text[mode]); |
aaitihda | 20:e498fd789660 | 300 | if (value==0) |
aaitihda | 20:e498fd789660 | 301 | pc.printf("LSB Mode \n"); // |
aaitihda | 20:e498fd789660 | 302 | if (value==1) |
aaitihda | 20:e498fd789660 | 303 | pc.printf("MSB Mode \n"); // |
aaitihda | 20:e498fd789660 | 304 | } |
aaitihda | 20:e498fd789660 | 305 | if(mode==2){// Get the Reset frequency in MHz |
aaitihda | 20:e498fd789660 | 306 | value=atoi(text[mode]); |
aaitihda | 20:e498fd789660 | 307 | pc.printf("Reset Frequency = %d \n\r", value); |
aaitihda | 20:e498fd789660 | 308 | } |
aaitihda | 20:e498fd789660 | 309 | if(mode==3){// Get the frequency step |
aaitihda | 20:e498fd789660 | 310 | value=atoi(text[mode]); |
aaitihda | 20:e498fd789660 | 311 | pc.printf("Frequency Step = %d \n\r", value); |
aaitihda | 20:e498fd789660 | 312 | } |
aaitihda | 20:e498fd789660 | 313 | if(mode==4){ |
aaitihda | 20:e498fd789660 | 314 | value=atoi(text[mode]); |
aaitihda | 20:e498fd789660 | 315 | pc.printf("Threshold voltage = %d \n\r",value); |
aaitihda | 20:e498fd789660 | 316 | } |
aaitihda | 20:e498fd789660 | 317 | } |
aaitihda | 20:e498fd789660 | 318 | } |
aaitihda | 20:e498fd789660 | 319 | |
aaitihda | 20:e498fd789660 | 320 | else{ |
aaitihda | 20:e498fd789660 | 321 | int num; |
aaitihda | 20:e498fd789660 | 322 | pc.printf("File does no exist \n\r"); |
aaitihda | 20:e498fd789660 | 323 | pc.printf("Enter the divider value \n: \r"); |
aaitihda | 20:e498fd789660 | 324 | pc.printf("Byte to send LSB(0) or MSB(1)\n: \r"); |
aaitihda | 20:e498fd789660 | 325 | for(i=0; i<2; i++){ //just read to save to lines |
aaitihda | 20:e498fd789660 | 326 | pc.scanf("%s\r", text[i]); |
aaitihda | 20:e498fd789660 | 327 | while (!(sscanf(text[i], "%d\r", &num))){ |
aaitihda | 20:e498fd789660 | 328 | printf("Invalid input '%s'\n\r", text[i]); |
aaitihda | 20:e498fd789660 | 329 | pc.scanf("%s\r", text[i]); |
aaitihda | 20:e498fd789660 | 330 | } |
aaitihda | 20:e498fd789660 | 331 | } |
aaitihda | 20:e498fd789660 | 332 | |
aaitihda | 20:e498fd789660 | 333 | } |
aaitihda | 20:e498fd789660 | 334 | return value; |
aaitihda | 20:e498fd789660 | 335 | } |
aaitihda | 20:e498fd789660 | 336 | |
aaitihda | 20:e498fd789660 | 337 | uint16_t * set_dec2bin (uint16_t read_div) { |
aaitihda | 20:e498fd789660 | 338 | int i; |
aaitihda | 20:e498fd789660 | 339 | static uint16_t r[12]; |
aaitihda | 20:e498fd789660 | 340 | for( i = 0; i < 12; i++ ){ |
aaitihda | 20:e498fd789660 | 341 | r[i]= read_div >> i & 1; |
aaitihda | 20:e498fd789660 | 342 | pc.printf("%d",r[i]); // display read data value |
aaitihda | 20:e498fd789660 | 343 | } |
aaitihda | 20:e498fd789660 | 344 | pc.printf("\n\r"); |
aaitihda | 20:e498fd789660 | 345 | return r; |
aaitihda | 20:e498fd789660 | 346 | } |