SIMPLE PROJECT THAT COMMUNICATE WITH SLAVE , TRY TO GET DATA, ANALYZE IT AND PROVIDE OUTPUT. TWO UART INTERFACE, SEMAPHORE, THREAD COMMUNICATION, LCD INTERFACING,PRIORITY BASED THREAD SWITCHING,HEX TO FLOAT CONVERSION

Dependencies:   TextLCD

Files at this revision

API Documentation at this revision

Comitter:
radhey04ec
Date:
Mon Aug 10 13:17:13 2020 +0000
Parent:
1:bdc3ebd4e52b
Commit message:
FINAL COMMIT PROGRAM TESTED OK

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Aug 09 04:33:50 2020 +0000
+++ b/main.cpp	Mon Aug 10 13:17:13 2020 +0000
@@ -123,9 +123,9 @@
   lcd.locate(0,3);
   lcd.printf("Current = %.2f mA",current);
   lcd.locate(19,3);
-  lcd.printf("ET");
+  lcd.printf(".");
   pc.printf("\n Input Current is = %.2f mA",current);
-  ThisThread::sleep_for(150);   
+  ThisThread::sleep_for(10);   
  }
  }
      
@@ -187,14 +187,17 @@
 
 //PUSH BUTTON INTERRUPT FUNCTION  -- PUSH BUTTON INTERRUPT
 swt.rise(&TEST_PROCESS);  //THIS FUNCTION Call when push button press
-
+wait(5);
+pc.printf("*********************************************************************\n");
 pc.printf("\n STM POWER ON -- DATA INITIALIZATION \n");
 pc.printf("\n PROGRAM CREATED BY : R_AND_D DEPT of KEPL \n");
 pc.printf("\n Program Version 1.0 \n");
 pc.printf("\n Any changes of the program lead toward Board OS Crash or bugs");
-pc.printf("\n Permission require before any Hardware / software changes \n");
-pc.printf("\n RTOS TRYING TO ACCESS THREAD CODE......INITIALIZATIO OF RTOS START.....");
-pc.printf("\n Do not press any Button");
+pc.printf("\n NOTE : Permission require before any Hardware /or software changes \n");
+pc.printf("\n RTOS TRYING TO ACCESS THREAD CODE......INITIALIZATIO OF RTOS START.....\n");
+pc.printf("\n");
+pc.printf("\n Do not press any Button\n");
+pc.printf("\n *******************************************************************\n");
 
 
 //INITIAL ALL LED OFF
@@ -206,8 +209,8 @@
 
 WELCOME_SCREEN(); //TO INITIALIZE DATA
 
-pc.printf("\n Good Luck !!!!");
-pc.printf("\n CURRENT MEASUREMENT UNIT TURNING ON");
+pc.printf("\n \n \n Good Luck !!!! \n");
+pc.printf("\n CURRENT MEASUREMENT UNIT TURNING ON...........\n");
 
 T1.start(CURRENT_MEASUREMENT);
 T2.start(LCD_REFRESH);
@@ -291,7 +294,7 @@
     
     A.release();
     //last fucntion to reset flag and display test result
-    wait(0.150);
+    wait(0.5);
      //CLEAR THE BUFFER BEFORE UART COMM
     //***************TEST - 1 ENTER INTEST MODE AND VERSION READ------------------------------TEST1
     BUFFER_CLEAR();
@@ -302,7 +305,9 @@
     wait(0.10);
     //FETCHING VERSION NUMBER 01.34
     lcd.cls();
+    wait(1);
     lcd.locate(0,0);
+    lcd.printf("");
     lcd.printf("VERSION TEST ON");
     {
         uint8_t j=0;
@@ -323,11 +328,13 @@
             //PRINT DATA ON LCD
             lcd.locate(0,1);
             lcd.printf("VERSION = 1.34");
+            lcd.locate(0,2);
             lcd.printf("VERSION TEST OK");
             //GO FOR NEXT TEST
             NEXT = 1; //READY FOR NEXT TEST
+            CURRENT();
             A.release();
-            wait(2);
+            wait(6);
             
         
         }
@@ -346,12 +353,16 @@
     } 
     if(NEXT == 1) //****************    RED LED TESTING    *********************
     {
+        float CURRENT_TEMP = 0;
         NEXT = 0;
         lcd.cls();
+        CURRENT();
         A.release();
-        wait(1);
+        wait(2);
         BUFFER_CLEAR();
         lcd.locate(0,0);
+        lcd.printf("");
+        lcd.locate(0,0);
         lcd.printf("RED LED TEST ON");
         pc.printf("\n RED LED TESTING START");
         UT.putc('d');   // RED LED OF SLAVE BOARD ON
@@ -364,6 +375,7 @@
             float LDR_AVG =0;
             float S = 0;
             int8_t z;
+        
             
         for(z = 0; z < 10; z++)
         {
@@ -376,17 +388,22 @@
         LDR_AVG = S /10;
         LDR_VALUE = LDR_AVG;
         }
-        lcd.printf("                   ");
-        lcd.printf("RED LED ON CMD");
+        lcd.printf("RED LED ON COMMAND");
         BUFFER_CLEAR();
         A.release();
-        wait(1);
+        wait(2);
+        A.release();
+        wait(2);
+        CURRENT();
+        A.release();
+        wait(2);
+        CURRENT_TEMP = current;
+        pc.printf("\n RED LED ON TIME CURRENT =     %f",current);
         lcd.locate(0,1);
-        lcd.printf("                   ");
-        lcd.printf("RED LED OFF");
+        lcd.printf("RED LED OFF COMMAND");
         UT.putc('b');
         A.release();
-        wait(1);
+        wait(2);
         response();
         BUFFER_CLEAR();
         pc.printf("RED LED TEST FINISH");
@@ -395,19 +412,17 @@
         if(LDR_VALUE > 0.650)
         {
         lcd.locate(0,0);
+        lcd.printf("");
+        lcd.printf("RED LED TEST OK");
+        lcd.locate(0,1);
         lcd.printf("                   ");
-        lcd.locate(0,0);
-        lcd.printf("RED LED TEST OK");
+        lcd.locate(0,1);
+        lcd.printf("LED ON DETECTED");
         NEXT = 1;
         pc.printf("\n RED LED DETECT SUCCESSFULLY");
                 
         //CLEAR LCD CONTENT
-        lcd.locate(0,1);
-        lcd.printf("                   ");
-        lcd.locate(0,2);
-        lcd.printf("                   ");
-        lcd.locate(0,0);
-        lcd.printf("                   ");
+        wait(6);
         LDR_VALUE = 0;
         }
         else
@@ -419,37 +434,60 @@
 
             
         }
-        
+        wait_ms(200);
+        if(CURRENT_TEMP < 12.0 || CURRENT_TEMP > 20.5)
+        {
+         pc.printf("\n OVER OR UNDER CURRENT ERROR \n");
+         pc.printf("\n This Error at time of LED on/off process \n");
+         NEXT = 0;
+         ERROR_FLAG = 1;
+         CURRENT_TEMP =0;
+         error(7);
+         
+         }      
 
     }
     if(NEXT == 1)//**********************************CALIBRATION ON
     {
         NEXT =0;
-        lcd.locate(0,1);
-        lcd.printf("                   ");
-        lcd.locate(0,2);
+        pc.printf("\n CALIBRATION ON ");
+        lcd.locate(0,0);
         lcd.printf("                   ");
         lcd.locate(0,0);
-        lcd.printf("                   ");
-        pc.printf("\n CALIBRATION ON ");
         lcd.printf("CALIBRATION ON");
         lcd.locate(0,1);
-        lcd.printf("PROCESSING");
+        lcd.printf("                   ");
+        lcd.locate(0,1);
+        wait(1);
+        lcd.printf("In PROGRESS....");
+        pc.printf("\n CALIBRATION PROCESS IN PROGRESS");
         BUFFER_CLEAR();
         UT.putc('c');
         A.release();
-        wait(3);
+        wait(5);
         UT.putc('s');
         A.release();
         wait(1);
         lcd.locate(0,2);
+        lcd.printf("                   ");
+        lcd.locate(0,2);
         pc.printf("\n CALIBRATION COMPLETE");
         lcd.printf("DATA SAVE OK");
+        lcd.locate(0,1);
+        lcd.printf("                   ");
+        lcd.locate(0,1);
+        lcd.printf("CALIBRATION DONE");
+        A.release();
+        wait(3);
+        A.release();
+        wait(4);
         NEXT = 1;
         
     }
     if(NEXT ==1)//*****************************BATTERY VOLTAGE TEST
     {
+        uint32_t G_VAL = 0;
+        float vol = 0;
         NEXT =0;
         ERROR_FLAG = 0;
         lcd.locate(0,1);
@@ -459,15 +497,87 @@
         lcd.locate(0,0);
         lcd.printf("                   ");
         lcd.locate(0,0);
-        lcd.printf("Voltage test");
+        lcd.printf("Voltage Test ON");
         pc.printf("\n VOLTAGE TEST BEGIN");
         BUFFER_CLEAR();
         UT.putc('A');
         A.release();
         wait(1);
         response();
+        //DECODE DATA >>>>>>>>>>>>>>>>>>>>>>>BATTERY VOLTAGE <<<<<<<<<<<<<<<<<<<
+        {
+        uint8_t b=0;
+        char temp_buf[5];
+        pc.puts("\n \n \n DECODE BATTERY VOLTAGE: ");
+       for(b=1;b<5;b++)
+       {
+            pc.putc(rxBuffer[b]);
+            temp_buf[b-1] = rxBuffer[b];
+        }
+        temp_buf[4] = '\n';
+        
+        //*****************************HEX TO DEC*******************************
+    {
+    int base = 1; 
+      
+    int dec_val = 0;
+    int i1;
+      
+    // Extracting characters as digits from last character 
+    for (i1=3; i1>=0; i1--) 
+    {    
+        // if character lies in '0'-'9', converting  
+        // it to integral 0-9 by subtracting 48 from 
+        // ASCII value. 
+        if (temp_buf[i1]>='0' && temp_buf[i1]<='9') 
+        { 
+            dec_val += (temp_buf[i1] - 48)*base; 
+                  
+            // incrementing base by power 
+            base = base * 16; 
+        } 
+  
+        // if character lies in 'A'-'F' , converting  
+        // it to integral 10 - 15 by subtracting 55  
+        // from ASCII value 
+        else if (temp_buf[i1]>='A' && temp_buf[i1]<='F') 
+        { 
+            dec_val += (temp_buf[i1] - 55)*base;
+               base = base*16; 
+        } 
+
+        }
+        pc.printf("\n value = %d",dec_val);
+        G_VAL = dec_val;
+        }
+        }
+        pc.printf("\n GVAL %d",G_VAL);
+        float T1;
+        T1 = (float)(G_VAL/65535.0);
+        pc.printf("\n T1 = %f",T1);
+        float T2;
+        T2 = (float)(T1*3.6);
+        pc.printf("\n T2 = %f",T2);
+        vol = (23.68 * (T2/10));
+        pc.printf("\n VOLTAGE LEVEL = %f",vol);
+        lcd.locate(0,2);
+        lcd.printf("                   ");
+        lcd.locate(0,2);
+        lcd.printf("Voltage = %.2f V",vol);
+        G_VAL = 0;
+        BUFFER_CLEAR();
+        wait(5);
+        if(vol >= 6 || vol <= 4.5)
+        {
+         NEXT = 0;
+         ERROR_FLAG = 1;
+         error(10);   
+        }
+        else
+        {
         NEXT = 1;
-        
+        ERROR_FLAG = 0;
+        }
 
         
     }
@@ -478,21 +588,22 @@
         NEXT = 0;
         pc.printf("\n CURRENT TEST START");
         A.release();
-        wait(1);
+        wait(2);
         CURRENT();
         lcd.locate(0,1);
         lcd.printf("                   ");
-        lcd.locate(0,2);
-        lcd.printf("                   ");
-        lcd.locate(0,0);
-        lcd.printf("                   ");
         lcd.locate(0,1);
         lcd.printf("CURRENT = %f",current);
         if(current > 6.5)
         {
+            CURRENT();
+            wait(2);
+        }
+        if(current > 6.5)
+        {
             error(2);
             NEXT = 0;
-            ERROR_FLAG = 1;
+            ERROR_FLAG = 1;   
         }
         else
         {
@@ -539,7 +650,7 @@
 RED_LED =0;
 BLUE_LED =0;
 BUZZER = 1;
-wait(0.1);
+wait(0.5);
 BUZZER =0;
 wait(3);
 }
@@ -550,6 +661,7 @@
 GREEN_LED = 1U;
 pc.printf("\n PCB AXV 001 TEST COMPLETED : TEST STATUS - PASS \n");
 pc.printf("\n ******************************END OF TEST************************************ \n");
+pc.printf("Total Test = %u",PCB_COUNTER);
 pc.printf("\n  \n \n");
 pc.printf("\n PLUG NEW BOARD AND PRESS THE BUTTON");
 pc.printf("\n \n \n");
@@ -564,7 +676,7 @@
  GREEN_LED=0;
  BLUE_LED=0;
  BUZZER = 1;
- wait(1);
+ wait(3);
  BUZZER =0;
  lcd.cls();
  lcd.locate(0,0);
@@ -588,17 +700,28 @@
 if(error_number == 2)
 {
  lcd.locate(0,1);
+ lcd.printf("                   ");
+ lcd.locate(0,1);
  lcd.printf("OVER CURRENT ");
  pc.printf("\n ERROR CODE = 0X2");
  pc.printf("\n OVER CURRENT ERROR");
  pc.printf("\n POSSIBLE SOLUTION");
  pc.printf("\n TRY TO WASH BOARD AGAIN and RECHECK");
- wait(3);
+ wait(10);
+ lcd.locate(0,1);
+ lcd.printf("");
+ CURRENT();
+ A.release();
+ wait(10);
+ 
 }
 if(error_number == 5)
 {
     pc.printf("\n ERROR NUMBER = 0X5");
     pc.printf("\n RED LED DETECTION FAIL");
+    lcd.locate(0,1);
+    lcd.printf("                   ");
+    lcd.locate(0,1);
     lcd.printf("LED TEST FAIL");
     A.release();
     wait(1);
@@ -609,6 +732,26 @@
     pc.printf("\n contact to HOD");
     
 }
+if(error_number == 7)
+{
+    lcd.locate(0,1);
+    lcd.printf("                   ");
+    lcd.locate(0,1);
+    lcd.printf("LED Curr. Outer range");
+    pc.printf("\n LED TAKING OUTER RANGE CURRENT \n");
+    A.release();
+    wait(2);
+    
+}
+if(error_number == 10)
+{
+    pc.printf("\n SUPPLY VOLTAGE ERROR \n");
+    lcd.locate(0,1);
+    lcd.printf("                   ");
+    lcd.locate(0,1);
+    lcd.printf("SUPP. VOLTAGE ERROR");
+    wait(5);
+}
     
 }
     
@@ -663,8 +806,8 @@
 lcd.locate(13,0);
 lcd.printf("..");
 lcd.locate(0,1);
-lcd.printf("Veryfied.........");
-wait_ms(3000);
+lcd.printf("INITIALIZATION...");
+wait_ms(4000);
 pc.printf("\n LCD COMMUNICATION Successful \n");
 lcd.cls();
 lcd.locate(0,0);
@@ -701,14 +844,15 @@
     pc.printf("\n NEW TEST START");
     wait(8); //8 SECOND 
     lcd.locate(0,1);
-    lcd.printf("BOARD SCANING..");
+    lcd.printf("TEST SETUP ON");
     pc.printf("\n BOARD SCANNING...");
     wait(8);
     lcd.locate(0,2);
-    lcd.printf("COMMUNICATING...");
+    lcd.printf("MAKING CONNECTION");
     pc.printf("\n COMMUNICATION ESTABLISHMENT \n");
     wait(5);
-    lcd.printf("READY FOR TEST");
+    lcd.locate(0,3);
+    lcd.printf("READY FOR TESTING");
     wait(5);
     lcd.cls();
     lcd.locate(0,0);