![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
create and send the file to pc
Dependencies: MCP23017 WattBob_TextLCD mbed
Fork of HelloWorld by
main.cpp@5:27b1b41b2366, 2014-02-27 (annotated)
- Committer:
- haseo1989
- Date:
- Thu Feb 27 18:21:27 2014 +0000
- Revision:
- 5:27b1b41b2366
- Parent:
- 4:b5b159adc261
- Child:
- 6:94ee12962e13
test each part of tasks
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
simon | 0:fb6bbc10ffa0 | 1 | #include "mbed.h" |
haseo1989 | 4:b5b159adc261 | 2 | //#include "mon.cpp" |
simon | 0:fb6bbc10ffa0 | 3 | |
haseo1989 | 5:27b1b41b2366 | 4 | DigitalIn Input1s(p5); |
haseo1989 | 5:27b1b41b2366 | 5 | DigitalIn Input1_400ms(p6); |
haseo1989 | 5:27b1b41b2366 | 6 | DigitalIn Input2_400ms(p7); |
haseo1989 | 5:27b1b41b2366 | 7 | AnalogIn Input1_800ms(p19); |
haseo1989 | 5:27b1b41b2366 | 8 | AnalogIn Input2_800ms(p20); |
haseo1989 | 3:6cc06b58870b | 9 | |
haseo1989 | 4:b5b159adc261 | 10 | DigitalOut bit4(LED1); |
haseo1989 | 4:b5b159adc261 | 11 | DigitalOut bit3(LED2); |
haseo1989 | 4:b5b159adc261 | 12 | DigitalOut bit2(LED3); |
haseo1989 | 4:b5b159adc261 | 13 | DigitalOut bit1(LED4); |
haseo1989 | 3:6cc06b58870b | 14 | |
haseo1989 | 3:6cc06b58870b | 15 | int IP1s,IP400ms1,IP400ms2 = 0; |
haseo1989 | 5:27b1b41b2366 | 16 | int IP800ms1[4],IP800ms2[4] = {0,0,0,0}; |
haseo1989 | 3:6cc06b58870b | 17 | int freq = 0; |
haseo1989 | 3:6cc06b58870b | 18 | int aver_anl1,aver_anl2 = 0; |
haseo1989 | 3:6cc06b58870b | 19 | int digi_val = 0; |
haseo1989 | 3:6cc06b58870b | 20 | |
haseo1989 | 3:6cc06b58870b | 21 | int ero_code = 0; |
haseo1989 | 3:6cc06b58870b | 22 | |
haseo1989 | 3:6cc06b58870b | 23 | int flag4task3 = 0; |
haseo1989 | 3:6cc06b58870b | 24 | int run_task = 0; |
haseo1989 | 3:6cc06b58870b | 25 | int led_show = 0; |
haseo1989 | 5:27b1b41b2366 | 26 | timer tmr; |
simon | 0:fb6bbc10ffa0 | 27 | |
simon | 0:fb6bbc10ffa0 | 28 | int main() { |
haseo1989 | 3:6cc06b58870b | 29 | |
haseo1989 | 3:6cc06b58870b | 30 | while(1) |
haseo1989 | 3:6cc06b58870b | 31 | { |
haseo1989 | 3:6cc06b58870b | 32 | } |
haseo1989 | 3:6cc06b58870b | 33 | |
haseo1989 | 3:6cc06b58870b | 34 | } |
haseo1989 | 3:6cc06b58870b | 35 | |
haseo1989 | 3:6cc06b58870b | 36 | // wait(1) -> waiting 10ms |
haseo1989 | 5:27b1b41b2366 | 37 | |
haseo1989 | 5:27b1b41b2366 | 38 | |
haseo1989 | 5:27b1b41b2366 | 39 | |
haseo1989 | 5:27b1b41b2366 | 40 | |
haseo1989 | 5:27b1b41b2366 | 41 | void task1() //works |
haseo1989 | 3:6cc06b58870b | 42 | { |
haseo1989 | 5:27b1b41b2366 | 43 | float tm_val1 = 0; |
haseo1989 | 5:27b1b41b2366 | 44 | tmr.reset(); |
haseo1989 | 5:27b1b41b2366 | 45 | |
haseo1989 | 5:27b1b41b2366 | 46 | while(Input1s); |
haseo1989 | 3:6cc06b58870b | 47 | |
haseo1989 | 5:27b1b41b2366 | 48 | while( !Input1s ); |
haseo1989 | 5:27b1b41b2366 | 49 | |
haseo1989 | 5:27b1b41b2366 | 50 | tmr.start(); |
haseo1989 | 5:27b1b41b2366 | 51 | while(Input1s); |
haseo1989 | 5:27b1b41b2366 | 52 | tmr.stop(); |
haseo1989 | 5:27b1b41b2366 | 53 | |
haseo1989 | 5:27b1b41b2366 | 54 | tm_val1 = tmr.read_us(); |
haseo1989 | 5:27b1b41b2366 | 55 | if(tm_val1 != 0.0) |
haseo1989 | 5:27b1b41b2366 | 56 | freq = 500000/tm_val1; //the frenquency of the wave |
haseo1989 | 5:27b1b41b2366 | 57 | else |
haseo1989 | 5:27b1b41b2366 | 58 | freq = 0; |
haseo1989 | 5:27b1b41b2366 | 59 | |
haseo1989 | 5:27b1b41b2366 | 60 | } |
haseo1989 | 5:27b1b41b2366 | 61 | |
haseo1989 | 5:27b1b41b2366 | 62 | |
haseo1989 | 5:27b1b41b2366 | 63 | |
haseo1989 | 5:27b1b41b2366 | 64 | void task2_checkDIP400ms() //check the SWes per 400ms,works |
haseo1989 | 3:6cc06b58870b | 65 | { |
haseo1989 | 5:27b1b41b2366 | 66 | if( Input1_400ms != 0 ) |
haseo1989 | 3:6cc06b58870b | 67 | IP400ms1 = 1; |
haseo1989 | 3:6cc06b58870b | 68 | else IP400ms1 = 0; |
haseo1989 | 3:6cc06b58870b | 69 | |
haseo1989 | 5:27b1b41b2366 | 70 | if( Input2_400ms !=0 ) |
haseo1989 | 3:6cc06b58870b | 71 | IP400ms2 = 1; |
haseo1989 | 5:27b1b41b2366 | 72 | else IP400ms2 = 0; |
haseo1989 | 3:6cc06b58870b | 73 | |
haseo1989 | 3:6cc06b58870b | 74 | } |
haseo1989 | 3:6cc06b58870b | 75 | |
haseo1989 | 5:27b1b41b2366 | 76 | void task3_checkAIP800ms() //get analog input, works |
haseo1989 | 3:6cc06b58870b | 77 | { |
haseo1989 | 5:27b1b41b2366 | 78 | float para1,para2; |
haseo1989 | 5:27b1b41b2366 | 79 | IP800ms1[flag4task3] = Input1_800ms.read(); |
haseo1989 | 5:27b1b41b2366 | 80 | IP800ms2[flag4task3] = Input2_800ms.read(); |
haseo1989 | 3:6cc06b58870b | 81 | |
haseo1989 | 3:6cc06b58870b | 82 | flag4task3++; |
haseo1989 | 3:6cc06b58870b | 83 | flag4task3 = flag4task3%4; |
haseo1989 | 3:6cc06b58870b | 84 | |
haseo1989 | 5:27b1b41b2366 | 85 | para1 = (IP800ms1[0] + IP800ms1[1] + IP800ms1[2] + IP800ms1[3])*3.3; |
haseo1989 | 5:27b1b41b2366 | 86 | para2 = (IP800ms2[0] + IP800ms2[1] + IP800ms2[2] + IP800ms2[3])*3.3; |
haseo1989 | 5:27b1b41b2366 | 87 | aver_anl1 = para1/4; |
haseo1989 | 5:27b1b41b2366 | 88 | aver_anl2 = para2/4; |
haseo1989 | 5:27b1b41b2366 | 89 | } |
haseo1989 | 3:6cc06b58870b | 90 | |
haseo1989 | 5:27b1b41b2366 | 91 | void task4_display2s() //works |
haseo1989 | 5:27b1b41b2366 | 92 | { |
haseo1989 | 5:27b1b41b2366 | 93 | int aver,aver1,aver2; |
haseo1989 | 5:27b1b41b2366 | 94 | /* get frequency from task 1 */ |
haseo1989 | 5:27b1b41b2366 | 95 | // frequency is freq |
haseo1989 | 5:27b1b41b2366 | 96 | |
haseo1989 | 5:27b1b41b2366 | 97 | |
haseo1989 | 5:27b1b41b2366 | 98 | /* get digital value from task2 */ |
haseo1989 | 5:27b1b41b2366 | 99 | /* digital number = {IP400ms1,IP400ms2} |
haseo1989 | 5:27b1b41b2366 | 100 | |
haseo1989 | 3:6cc06b58870b | 101 | |
haseo1989 | 5:27b1b41b2366 | 102 | */ |
haseo1989 | 5:27b1b41b2366 | 103 | /* get average value from task3,show integers */ |
haseo1989 | 5:27b1b41b2366 | 104 | //data type of aver_anl1,aver_anl2 are float |
haseo1989 | 5:27b1b41b2366 | 105 | |
haseo1989 | 5:27b1b41b2366 | 106 | aver1 = aver_anl1; |
haseo1989 | 5:27b1b41b2366 | 107 | aver2 = aver_anl2; |
haseo1989 | 5:27b1b41b2366 | 108 | aver = (aver1+aver2)/2; |
haseo1989 | 5:27b1b41b2366 | 109 | |
haseo1989 | 5:27b1b41b2366 | 110 | /* get error code from task5 */ |
haseo1989 | 5:27b1b41b2366 | 111 | ero_code = 3; |
haseo1989 | 5:27b1b41b2366 | 112 | /* show them!! */ |
haseo1989 | 5:27b1b41b2366 | 113 | |
haseo1989 | 5:27b1b41b2366 | 114 | lcd->cls(); |
haseo1989 | 5:27b1b41b2366 | 115 | lcd->locate(0,0); |
haseo1989 | 5:27b1b41b2366 | 116 | lcd->printf("F=%d Aval=%d",freq,aver); |
haseo1989 | 5:27b1b41b2366 | 117 | lcd->locate(1,0); |
haseo1989 | 5:27b1b41b2366 | 118 | lcd->printf("Dval=%d%d ErC=%d",IP400ms2,IP400ms1,ero_code); |
haseo1989 | 3:6cc06b58870b | 119 | |
haseo1989 | 3:6cc06b58870b | 120 | } |
haseo1989 | 3:6cc06b58870b | 121 | |
haseo1989 | 5:27b1b41b2366 | 122 | |
haseo1989 | 5:27b1b41b2366 | 123 | |
haseo1989 | 5:27b1b41b2366 | 124 | |
haseo1989 | 5:27b1b41b2366 | 125 | void task5_check_SWes() //1.8s |
haseo1989 | 3:6cc06b58870b | 126 | { |
haseo1989 | 3:6cc06b58870b | 127 | if((IP400ms1 == 1) && (aver_anl1 > aver_anl2)) ero_code = 3; |
haseo1989 | 3:6cc06b58870b | 128 | else ero_code = 0; //error code |
haseo1989 | 3:6cc06b58870b | 129 | |
haseo1989 | 3:6cc06b58870b | 130 | if(IP400ms2 == 1) |
haseo1989 | 3:6cc06b58870b | 131 | run_task = 1; |
haseo1989 | 3:6cc06b58870b | 132 | else |
haseo1989 | 3:6cc06b58870b | 133 | run_task = 0; |
haseo1989 | 3:6cc06b58870b | 134 | |
haseo1989 | 3:6cc06b58870b | 135 | } |
haseo1989 | 3:6cc06b58870b | 136 | |
haseo1989 | 5:27b1b41b2366 | 137 | void led_task() //blink led 1.5s |
haseo1989 | 3:6cc06b58870b | 138 | { |
haseo1989 | 3:6cc06b58870b | 139 | led_show = led_show%15; |
haseo1989 | 3:6cc06b58870b | 140 | |
haseo1989 | 3:6cc06b58870b | 141 | int num_led = led_show; |
haseo1989 | 3:6cc06b58870b | 142 | |
haseo1989 | 5:27b1b41b2366 | 143 | if(num_led > 7) {num_led = num_led - 8; bit4 = 1; } |
haseo1989 | 3:6cc06b58870b | 144 | else bit4 = 0; |
haseo1989 | 3:6cc06b58870b | 145 | |
haseo1989 | 5:27b1b41b2366 | 146 | if(num_led > 3) {num_led = num_led - 4; bit3 = 1;} |
haseo1989 | 3:6cc06b58870b | 147 | else bit3 = 0; |
haseo1989 | 3:6cc06b58870b | 148 | |
haseo1989 | 5:27b1b41b2366 | 149 | if(num_led > 1) {num_led = num_led - 2; bit2 = 1;} |
haseo1989 | 3:6cc06b58870b | 150 | else bit2 = 0; |
haseo1989 | 3:6cc06b58870b | 151 | |
haseo1989 | 5:27b1b41b2366 | 152 | bit1 = num_led; |
haseo1989 | 3:6cc06b58870b | 153 | |
haseo1989 | 3:6cc06b58870b | 154 | led_show++; |
haseo1989 | 3:6cc06b58870b | 155 | } |
haseo1989 | 3:6cc06b58870b | 156 | |
haseo1989 | 3:6cc06b58870b | 157 | void task6_updated5s() //update A.Frequency value B.digital input values C.Filtered analogue values |
haseo1989 | 3:6cc06b58870b | 158 | { |
haseo1989 | 3:6cc06b58870b | 159 | |
haseo1989 | 3:6cc06b58870b | 160 | |
haseo1989 | 5:27b1b41b2366 | 161 | } |