resist

main.cpp

Committer:
david8251
Date:
2017-07-20
Revision:
0:9d598f2be2fd

File content as of revision 0:9d598f2be2fd:

#include "mbed.h"
//---------------------------------

Serial Mod(p9, p10);

void task_resist();

int main()
{    
     while(1){
         task_resist();
        }
}
//----------------------------------------------------------
void task_resist(){ 

int command[8]={0x08, 0x03, 0x00, 0x01, 0x00, 0x02,0x95,0x52};
char receice[8]={0};
int j=0;

        for (int i=0; i<8; i++) {
            while(1)
            {
            if (Mod.writeable())
            {
            Mod.putc(command[i]);
            break;
                }
            }
        }

        for (int i=0; i<8; i++) {
                            while (j<7) {
                                if (Mod.readable()) {
                                    receice[i]= Mod.getc();
                                    if(j>5)
                                    {
                                        printf("Resistance:%.1fΩ\r\n", ((receice[3] << 8) + receice[4])/100.0);
                                        j++;
                                    }
                                    j++;
                                    break;
                                }
                    }
    
        }                        
}