create and send the file to pc

Dependencies:   MCP23017 WattBob_TextLCD mbed

Fork of HelloWorld by Simon Ford

main.cpp

Committer:
haseo1989
Date:
2014-02-27
Revision:
5:27b1b41b2366
Parent:
4:b5b159adc261
Child:
6:94ee12962e13

File content as of revision 5:27b1b41b2366:

#include "mbed.h"
//#include "mon.cpp"

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);
DigitalOut  bit2(LED3);
DigitalOut  bit1(LED4);

int IP1s,IP400ms1,IP400ms2 = 0;
int IP800ms1[4],IP800ms2[4] = {0,0,0,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;
timer tmr;

int main() {
    
    while(1)
    {
        }                  
    
}

// wait(1) -> waiting 10ms




void task1()                        //works
{
    float tm_val1 = 0;
    tmr.reset();
    
    while(Input1s);

    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( Input1_400ms != 0 )
        IP400ms1 = 1;
    else IP400ms1 = 0;
    
    if( Input2_400ms !=0 )
        IP400ms2 = 1;
    else IP400ms2 = 0;
    
}

void task3_checkAIP800ms()                          //get analog input, works
{   
    float para1,para2;
    IP800ms1[flag4task3] = Input1_800ms.read();
    IP800ms2[flag4task3] = Input2_800ms.read();
    
    flag4task3++;
    flag4task3 = flag4task3%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;
}  
    
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} 


*/
/*           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_SWes()                             //1.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 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; }
    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;
    
    led_show++;
}

void task6_updated5s()                              //update  A.Frequency value  B.digital input values  C.Filtered analogue values 
{                                                           
                                                            

}