create and send the file to pc
Dependencies: MCP23017 WattBob_TextLCD mbed
Fork of HelloWorld by
Diff: main.cpp
- Revision:
- 3:6cc06b58870b
- Parent:
- 2:47c808c02920
- Child:
- 4:b5b159adc261
diff -r 47c808c02920 -r 6cc06b58870b main.cpp --- a/main.cpp Wed Feb 12 15:22:57 2014 +0000 +++ b/main.cpp Fri Feb 14 12:50:29 2014 +0000 @@ -3,14 +3,127 @@ DigitalIn 1sIP(p5); DigitalIn 400msIP1(p6); DigitalIn 400msIP2(p7); -AnalogIn 800msIP1(p8); -AnalogIn 800msIP2(p9); +AnalogIn 800msIP1(p19); +AnalogIn 800msIP2(p20); + +DIgitalOut bit4(LED1); +DIgitalOut bit3(LED2); +DIgitalOut bit2(LED3); +DIgitalOut bit1(LED4); + +int IP1s,IP400ms1,IP400ms2 = 0; +int IP800ms1[4],IP800ms2[4] = 0; +int freq = 0; +int aver_anl1,aver_anl2 = 0; +int digi_val = 0; + +int ero_code = 0; + +int flag4task3 = 0; +int run_task = 0; +int led_show = 0; int main() { - while(1) { - myled = 1; - wait(0.2); - myled = 0; - wait(0.2); - } + + while(1) + { + } + +} + +// wait(1) -> waiting 10ms +void task1_check_wava1s() // check the square wave per second +{ + IP1s = 0; + for(int i = 0; i < 1000; i++) //the accuracy is 1us + if(1sIP == 1) + IP1s++; //the lasting time of the impulse of square wave +} + +void task2_checkDIP400ms() //check the SWes per 400ms +{ + if( 400msIP1 != 0 ) + IP400ms1 = 1; + else IP400ms1 = 0; + + if( 400msIP2 !=0 ) + IP400ms2 = 1; + else TP400ms2 = 0; + +} + +void task3_checkAIP800ms() +{ + IP800ms1[flag4task3] = 800msIP1; + IP800ms2[flag4task3] = 800msIP2; + + flag4task3++; + flag4task3 = flag4task3%4; } + +void task4_display2s() +{ + double freq2; + freq2 = 1/IP1s; + freq2 = freq2*1000000; + freq = freq2/1; //frenquency of square wave + + double aver_anl3,aver_anl4 = 0; + aver_anl3 = IP800ms1[0] + IP800ms1[1] + IP800ms1[2] + IP800ms1[3]; + aver_nal3 = aver_anl3/4; + + aver_nal1 = aver_anl3/1; //averaging analog input1 + + aver_anl4 = IP800ms2[0] + IP800ms2[1] + IP800ms2[2] + IP800ms2[3]; + aver_nal4 = aver_anl4/4; + + aver_nal2 = aver_anl4/1; //averaging analog input2 + + if ( IP400ms2 ==0 && IP400ms1 ==0 ) digi_val = 00; + else if ( IP400ms2 ==0 && IP400ms1 ==1 ) digi_val = 01; + else if ( IP400ms2 ==1 && IP400ms1 ==0 ) digi_val = 10; + else digi_val = 11; + // digital value + + // show out all the values + + +} + +void task5_check_SWes1.8s() +{ + if((IP400ms1 == 1) && (aver_anl1 > aver_anl2)) ero_code = 3; + else ero_code = 0; //error code + + if(IP400ms2 == 1) + run_task = 1; + else + run_task = 0; + +} + +void run_task1.5s() //blink led +{ + led_show = led_show%15; + + int num_led = led_show; + + if(num_led > 7) {num_led = num_led - 8; bit4 = 1 } + else bit4 = 0; + + if(num_led > 3) {num_led = num_led - 4; bit3 = 1} + else bit3 = 0; + + if(num_led > 1) {num_led = num_led - 2; bit2 = 1} + else bit2 = 0; + + bit1 = num; + + led_show++; +} + +void task6_updated5s() //update A.Frequency value B.digital input values C.Filtered analogue values +{ + + +{