Programski_zadatak_23

Dependencies:   Display1602 mbed nRF24L01P

Revision:
2:698c8f9140e6
Parent:
1:3213ce6cd7e1
Child:
3:77408dbd520c
--- a/main.cpp	Sat Jan 23 18:06:49 2016 +0000
+++ b/main.cpp	Sat Jan 23 20:12:32 2016 +0000
@@ -12,11 +12,7 @@
 Serial pc(USBTX, USBRX); //tx, rx
 
 //void start();
-float temp(int ,int, int );
-float voltage(int ,int , int);
-
-
-
+float readTempAndVoltage(int ,int, int , int);
 
 int main() 
 {
@@ -33,9 +29,13 @@
     
     while(1) 
     {
-        wait(1);        
-        t=temp(0xC0,0x55,0x94);
-        wait(1);
+        wait(0.1);        
+        t=readTempAndVoltage(0xC0,0x55,0x94,0);//55
+        wait(0.1);
+        v=readTempAndVoltage(0xC1,0xff,0x94,1);//55
+        
+        //v=readTempAndVoltage(0xC1,0x55,0x94,1);
+        
         //v=voltage(0xC1,0x55,0x94) ;   
         
                
@@ -43,45 +43,45 @@
         
         display.Clear();
         display.SetXY(0,0);
-        display.printf("Temp = %.1f degC", t); // print on screen
-        //display.SetXY(0,1);
-        //display.printf("Voltage = %.1f V", v); // print on screen//wait(1);
+        display.printf("Temp = %.2f   C", t); // print on screen
+        display.SetXY(0,1);
+        display.printf("Voltage = %.2f V", v); // print on screen//wait(1);
         //display.SetXY(0,1);
         //display.printf("Voltage = %.1f V", voltage(0xC1,0x55,0x94)); // print on screen
         
     }
 }
 
-float temp(int config_t0,int config_t1, int addr)
+float readTempAndVoltage(int config_b0,int config_b1, int addr, int mode)
 {
-    float temp;
     char config_t[2]; // transmitt buffer
-    char temp_read[2]; // read buffer 
-    config_t[0] = config_t0;    //0xC1; //config slave to int temp
-    config_t[1] = config_t1;    //0x55; // config data byte1, BOut 
+    char value_read[2]; // read buffer 
+    
     
     MSP430G.write(addr, config_t, 2);
     wait_us(20);
     
-    MSP430G.read(addr, temp_read, 2); //read the two-byte temp data            
-    temp = temp_read[0]+temp_read[1]*256;
-    temp=temp/10;
-    return temp;
-}  
+    if (mode==0)
+        {
+            float temp;
+            config_t[0] = config_b0;    //0xC1; //config slave to int temp
+            config_t[1] = config_b1;    //0x55; // config data byte1, BOut  
+            MSP430G.read(addr, value_read, 2); //read the two-byte temp data 
+            temp = value_read[0]+value_read[1]*256;
+            temp=temp/10.;
+            return temp;
+        }
+    else if(mode==1)
+        {
+            float voltage;
+            config_t[0] = config_b0;    //0xC1; //config slave to int temp
+            config_t[1] = config_b1;    //0x55; // config data byte1, BOut  
+            MSP430G.read(addr, value_read, 2); //read the two-byte temp data 
+            voltage = value_read[0]+value_read[1]*256;
+            voltage = 1.5 * (voltage / 1023);
+            return voltage;
+        }
+    else
+        return 0;
 
-float voltage(int config_v0,int config_v1, int addr)
-{
-    float volts;
-    char config_v[2]; // transmitt buffer
-    char volt_read[2]; // read buffer 
-    config_v[0] = config_v0;    //0xC1; //config slave to int temp
-    config_v[1] = config_v1;    //0x55; // config data byte1, BOut 
-    
-    MSP430G.write(addr, config_v, 2);
-    wait_us(20);
-    
-    MSP430G.read(addr, volt_read, 2); //read the two-byte temp data            
-    volts = volt_read[0]+volt_read[1]*256;
-    
-    return volts;
-}  
+}