create and send the file to pc
Dependencies: MCP23017 WattBob_TextLCD mbed
Fork of HelloWorld by
Revision 5:27b1b41b2366, committed 2014-02-27
- Comitter:
- haseo1989
- Date:
- Thu Feb 27 18:21:27 2014 +0000
- Parent:
- 4:b5b159adc261
- Child:
- 6:94ee12962e13
- Commit message:
- test each part of tasks
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MCP23017.lib Thu Feb 27 18:21:27 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/jimherd/code/MCP23017/#d57de266cf19
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WattBob_TextLCD.lib Thu Feb 27 18:21:27 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/jimherd/code/WattBob_TextLCD/#3b26cd028e85
--- a/main.cpp Wed Feb 26 11:30:18 2014 +0000 +++ b/main.cpp Thu Feb 27 18:21:27 2014 +0000 @@ -1,11 +1,11 @@ #include "mbed.h" //#include "mon.cpp" -DigitalIn IP1s(p5); -DigitalIn IP1_400ms(p6); -DigitalIn IP2_400ms(p7); -AnalogIn IP1_800ms(p19); -AnalogIn IP2_800ms(p20); +DigitalIn Input1s(p5); +DigitalIn Input1_400ms(p6); +DigitalIn Input2_400ms(p7); +AnalogIn Input1_800ms(p19); +AnalogIn Input2_800ms(p20); DigitalOut bit4(LED1); DigitalOut bit3(LED2); @@ -13,7 +13,7 @@ DigitalOut bit1(LED4); int IP1s,IP400ms1,IP400ms2 = 0; -int IP800ms1[4],IP800ms2[4] = 0; +int IP800ms1[4],IP800ms2[4] = {0,0,0,0}; int freq = 0; int aver_anl1,aver_anl2 = 0; int digi_val = 0; @@ -23,6 +23,7 @@ int flag4task3 = 0; int run_task = 0; int led_show = 0; +timer tmr; int main() { @@ -33,65 +34,95 @@ } // wait(1) -> waiting 10ms -void task1_check_wava1s() // check the square wave per second + + + + +void task1() //works { - IP1s = 0; - for(int i = 0; i < 1000; i++) //the accuracy is 1us - if(IP1s == 1) - IP1s++; //the lasting time of the impulse of square wave -} + float tm_val1 = 0; + tmr.reset(); + + while(Input1s); -void task2_checkDIP400ms() //check the SWes per 400ms + while( !Input1s ); + + tmr.start(); + while(Input1s); + tmr.stop(); + + tm_val1 = tmr.read_us(); + if(tm_val1 != 0.0) + freq = 500000/tm_val1; //the frenquency of the wave + else + freq = 0; + + } + + + +void task2_checkDIP400ms() //check the SWes per 400ms,works { - if( IP1_400ms != 0 ) + if( Input1_400ms != 0 ) IP400ms1 = 1; else IP400ms1 = 0; - if( IP2_400ms !=0 ) + if( Input2_400ms !=0 ) IP400ms2 = 1; - else TP400ms2 = 0; + else IP400ms2 = 0; } -void task3_checkAIP800ms() +void task3_checkAIP800ms() //get analog input, works { - IP800ms1[flag4task3] = IP1_800ms; - IP800ms2[flag4task3] = IP2_800ms; + float para1,para2; + IP800ms1[flag4task3] = Input1_800ms.read(); + IP800ms2[flag4task3] = Input2_800ms.read(); 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; + para1 = (IP800ms1[0] + IP800ms1[1] + IP800ms1[2] + IP800ms1[3])*3.3; + para2 = (IP800ms2[0] + IP800ms2[1] + IP800ms2[2] + IP800ms2[3])*3.3; + aver_anl1 = para1/4; + aver_anl2 = para2/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 +void task4_display2s() //works +{ + int aver,aver1,aver2; +/* get frequency from task 1 */ +// frequency is freq + + +/* get digital value from task2 */ +/* digital number = {IP400ms1,IP400ms2} + - // show out all the values - +*/ +/* get average value from task3,show integers */ +//data type of aver_anl1,aver_anl2 are float + + aver1 = aver_anl1; + aver2 = aver_anl2; + aver = (aver1+aver2)/2; + +/* get error code from task5 */ + ero_code = 3; +/* show them!! */ + + lcd->cls(); + lcd->locate(0,0); + lcd->printf("F=%d Aval=%d",freq,aver); + lcd->locate(1,0); + lcd->printf("Dval=%d%d ErC=%d",IP400ms2,IP400ms1,ero_code); } -void task5_check_SWes1.8s() + + + +void task5_check_SWes() //1.8s { if((IP400ms1 == 1) && (aver_anl1 > aver_anl2)) ero_code = 3; else ero_code = 0; //error code @@ -103,22 +134,22 @@ } -void run_task1.5s() //blink led +void led_task() //blink led 1.5s { led_show = led_show%15; int num_led = led_show; - if(num_led > 7) {num_led = num_led - 8; bit4 = 1 } + 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} + 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} + if(num_led > 1) {num_led = num_led - 2; bit2 = 1;} else bit2 = 0; - bit1 = num; + bit1 = num_led; led_show++; } @@ -127,4 +158,4 @@ { -{ +}
--- a/mon.cpp Wed Feb 26 11:30:18 2014 +0000 +++ b/mon.cpp Thu Feb 27 18:21:27 2014 +0000 @@ -14,11 +14,5 @@ par_port->write_bit(1,BL_BIT); // turn LCD backlight ON lcd->cls(); // clear display lcd->locate(0,0); // set cursor to location (0,0) - top left corner - - int vala=0; - int valb=0; - lcd->printf("f=%dhz,anl=%d ",vala,valb); // print string - lcd->locate(1,0); - lcd->printf("abcdefghijklmnopq"); - for(;;); + } \ No newline at end of file