Hackster is hosting Hackster Holidays, Ep. 2: Livestream & Giveaway Drawing. Start streaming on Friday!Stream Hackster Holidays, Ep. 2 on Friday!
Shahariar
Published © GPL3+

PSoC 4: The Auto Ranging Multi-Meter

An auto ranging meter with diode/LED, resistance, capacitance, continuity testing capabilities. No Voltage or Current measurements !

IntermediateFull instructions provided4 hours2,997
PSoC 4: The Auto Ranging Multi-Meter

Things used in this project

Hardware components

PSoC 4 Prototyping Kit
Cypress PSoC 4 Prototyping Kit
×1
Breadboard (generic)
Breadboard (generic)
×1
Adafruit LCD 20X4 Char
×1
SparkFun IOIO Breadboard Holder
×1
SparkFun Buzzer
×1

Software apps and online services

PSoC Creator
Cypress PSoC Creator

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Device Pin Map

CY8C049 , PSoC 4 CY4245AXI083

Code

main.c

C/C++
Codes
#include <project.h>

volatile uint32_t us_10=0;  // 10 uSec variable
int current =0;
int voltage =0;
int resistance=0;
uint32_t IDAC_Val=0xff;
int c=4095;    
int j=0; //use as loop counter
int mode =1;

CY_ISR(Timing_ISR_Handler)
{
    us_10++;
    Timer_ClearInterrupt(Timer_TC_INTERRUPT_MASK);

}


uint8_t  sine_wave[256] = {
  0x80, 0x83, 0x86, 0x89, 0x8C, 0x90, 0x93, 0x96,
  0x99, 0x9C, 0x9F, 0xA2, 0xA5, 0xA8, 0xAB, 0xAE,
  0xB1, 0xB3, 0xB6, 0xB9, 0xBC, 0xBF, 0xC1, 0xC4,
  0xC7, 0xC9, 0xCC, 0xCE, 0xD1, 0xD3, 0xD5, 0xD8,
  0xDA, 0xDC, 0xDE, 0xE0, 0xE2, 0xE4, 0xE6, 0xE8,
  0xEA, 0xEB, 0xED, 0xEF, 0xF0, 0xF1, 0xF3, 0xF4,
  0xF5, 0xF6, 0xF8, 0xF9, 0xFA, 0xFA, 0xFB, 0xFC,
  0xFD, 0xFD, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xFE, 0xFD,
  0xFD, 0xFC, 0xFB, 0xFA, 0xFA, 0xF9, 0xF8, 0xF6,
  0xF5, 0xF4, 0xF3, 0xF1, 0xF0, 0xEF, 0xED, 0xEB,
  0xEA, 0xE8, 0xE6, 0xE4, 0xE2, 0xE0, 0xDE, 0xDC,
  0xDA, 0xD8, 0xD5, 0xD3, 0xD1, 0xCE, 0xCC, 0xC9,
  0xC7, 0xC4, 0xC1, 0xBF, 0xBC, 0xB9, 0xB6, 0xB3,
  0xB1, 0xAE, 0xAB, 0xA8, 0xA5, 0xA2, 0x9F, 0x9C,
  0x99, 0x96, 0x93, 0x90, 0x8C, 0x89, 0x86, 0x83,
  0x80, 0x7D, 0x7A, 0x77, 0x74, 0x70, 0x6D, 0x6A,
  0x67, 0x64, 0x61, 0x5E, 0x5B, 0x58, 0x55, 0x52,
  0x4F, 0x4D, 0x4A, 0x47, 0x44, 0x41, 0x3F, 0x3C,
  0x39, 0x37, 0x34, 0x32, 0x2F, 0x2D, 0x2B, 0x28,
  0x26, 0x24, 0x22, 0x20, 0x1E, 0x1C, 0x1A, 0x18,
  0x16, 0x15, 0x13, 0x11, 0x10, 0x0F, 0x0D, 0x0C,
  0x0B, 0x0A, 0x08, 0x07, 0x06, 0x06, 0x05, 0x04,
  0x03, 0x03, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01,
  0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x03,
  0x03, 0x04, 0x05, 0x06, 0x06, 0x07, 0x08, 0x0A,
  0x0B, 0x0C, 0x0D, 0x0F, 0x10, 0x11, 0x13, 0x15,
  0x16, 0x18, 0x1A, 0x1C, 0x1E, 0x20, 0x22, 0x24,
  0x26, 0x28, 0x2B, 0x2D, 0x2F, 0x32, 0x34, 0x37,
  0x39, 0x3C, 0x3F, 0x41, 0x44, 0x47, 0x4A, 0x4D,
  0x4F, 0x52, 0x55, 0x58, 0x5B, 0x5E, 0x61, 0x64,
  0x67, 0x6A, 0x6D, 0x70, 0x74, 0x77, 0x7A, 0x7D
};


void measure_resistance(void);
void measure_continuity(void);
void measure_capacitance(void);
void measure_diode(void);
void measure_inductance(void);


void res_mode(void)
{
        
}
/////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// MAIN LOOP /////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
int main()
{   
    LCD_Start();
    ADC_Start();
    IDAC_Start();
    Timer_Start();
    Timing_ISR_StartEx(Timing_ISR_Handler);
//    CyGlobalIntEnable;
    mode=1;
    IDAC_SetValue(IDAC_Val);
    ADC_StartConvert();
    LCD_Position(1,0);LCD_PrintString(" ! PSoC Auto Range !");
    LCD_Position(2,0);LCD_PrintString("***   LRC Meter  ***");
    CyDelay(2000);
    LCD_ClearDisplay();

    
    for(;;)
    {
    measure_capacitance();
    measure_resistance();
    measure_continuity();
    measure_diode();
        if (mode>4) {mode=1;}
    
  
    } ///////////////////////// Forever for loop ends here /////////////////////////////////*/

} ///////////////////=========== main loop Ends Here ===============/////////////////////////





///////////////////////////// FUNCTIONS BODY /////////////////////////////
void measure_resistance()
{
     IDAC_Start();
    unsigned long R=0;
    while (mode==1)
    {
    Buzzer_Write(0);
    IDAC_Val=0xff;
    c=4095;
    
        while((IDAC_Val>0)&&(c>=4000))
        {
    
        IDAC_Val=IDAC_Val-0x01;
        IDAC_SetValue(IDAC_Val);
        CyDelay(3);
        while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}
        c=ADC_GetResult16(0);
        CyDelay(2);
        }   
        
        if (c<4000)
        {
            
            IDAC_SetValue(IDAC_Val);      
            CyDelay(1);
            current= IDAC_Val*1.2;   // in uAmp
            voltage=c*1000/2;        // in uVolt
            resistance = voltage/current;  // Ohms Law to calculate resistanc
            resistance = resistance - 148; // offsetting internal trace resistance of 150 ohms per trace
                
                if (resistance<=0) {resistance = 0;}                  // omitting any negative value
                if (resistance>5000) {resistance = resistance*1.05;} // soft correction to reduce error
                
              LCD_ClearDisplay();
                // 500K IS THE LIMIT FOR RESISTANCE 
             if (resistance<500000)
             {
              //  Show Result on LCD  //     
              LCD_Position(0,0); LCD_PrintString("*  RESISTANCE MODE *");      
              LCD_Position(1,6);LCD_PrintString("o_");LCD_PutChar(LCD_CUSTOM_2);LCD_PutChar(LCD_CUSTOM_3);
              LCD_PutChar(LCD_CUSTOM_2);LCD_PutChar(LCD_CUSTOM_3);LCD_PrintString("_o");
              LCD_Position(2,5); LCD_PrintU32Number(resistance);
              LCD_PrintString(" ");LCD_PutChar(LCD_CUSTOM_0);
              LCD_Position(3,5);LCD_PrintU32Number(resistance/1000);
                    if(resistance%1000>=100)LCD_PrintString(".");
                    else if(resistance%1000>=10)LCD_PrintString(".0");
                    else if(resistance%1000<10)LCD_PrintString(".00");
              LCD_PrintU32Number(resistance%1000);
              LCD_PrintString(" k");
              LCD_PutChar(LCD_CUSTOM_0);
              CyDelay(100); 
             }
            
            else 
             {
              LCD_Position(0,0);LCD_PrintString("*  RESISTANCE MODE *");                      
              LCD_Position(1,6);LCD_PrintString("o_    _o");         
              LCD_Position(2,0); LCD_PrintString("No Resistor Detected");
              LCD_Position(3,0); LCD_PrintString(" Connect Resistor !!");
              CyDelay(100);
              }
            

        
        CyDelay(100);
        // mode exit if user press switch     
            if(LED_Read()==1){mode++;}
        }
        
     
    }
}


void measure_capacitance()
{
   
    while (mode==2)
    {
     // Timer_WritePeriod(10);
        IDAC_Stop();
          while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}
          c=ADC_GetResult16(0);
   
        LCD_ClearDisplay();
        LCD_Position(0,0);
        LCD_PrintString("* CAPACITANCE MODE *");
        LCD_Position(1,2);
        LCD_PrintString("(+) o--  --o (-)");

        IDAC_Start();
        IDAC_Val=100;
        IDAC_SetValue(IDAC_Val);// times 1.2 uA times CHARGE TIME is Q Coulomb charge
   
        int k=0;
        uint16 ADC_Level = 2048 ; // caps will charge through IDAC current upto this level
            while(c<ADC_Level)
            {
                if(k==0) // One time loop 
                {
                LCD_Position(0,0);LCD_PrintString("* CAPACITANCE MODE *");
                LCD_Position(1,2);LCD_PrintString("(+) o--");LCD_PutChar(LCD_CUSTOM_6);
                LCD_PutChar(LCD_CUSTOM_5);LCD_PrintString("--o (-)");

                LCD_Position(2,0);LCD_PrintString("   Measuring.....");
                k++;CyGlobalIntDisable; us_10=0;CyGlobalIntEnable;
                }
                // ADC is measuring voltage across capacitor
                while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}  
                c=ADC_GetResult16(0);
    
            }
    
        CyGlobalIntDisable;  // disabling interrupt to stop updating time
        IDAC_SetValue(0x00); // IDAC current is set 0
        IDAC_Stop();         // IDAC is stopped
        LCD_ClearDisplay();
        
        // Using C = Q/V = I*t/V formula, Capacitance will be calculated and displayed 
                while(c>256)
                {     
                LCD_Position(0,0); LCD_PrintString("* CAPACITANCE MODE *");        
        // Calculation Below //
                
                //  float Charge = IDAC_Val*1.2; // 1.2 uA is the step current               
                //  uint32 Time = us_10/100;  // microsec to milisec
                //  float Volt = ADC_Level/2.0;
                //  Approx Timing Correction for Execution Delay by adding 20% to calculated value (1.2 times)
                
                double nFCaptemp =  1000*1.2*((IDAC_Val*1.2*us_10/100.0)/(ADC_Level/2.0));
                uint32 nFCap = nFCaptemp;
                uint32 Capacitance = nFCap/1000;
              
        
        // Displaying Capacitacne on LCD //
                LCD_Position(1,2);LCD_PrintString("(+) o--  --o (-)");
              //  LCD_PrintString("(+) o--");LCD_PutChar(LCD_CUSTOM_6);LCD_PutChar(LCD_CUSTOM_5);LCD_PrintString("--o (-)");  
                LCD_Position(2,7); LCD_PrintU32Number(Capacitance);LCD_PrintString(" uF ");
                LCD_Position(3,7);; LCD_PrintU32Number(nFCap);LCD_PrintString(" nF ");
    
                CyDelay(500);
                
                // Checks for presence of Capacitance connected to Probe //
                while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}
                c=ADC_GetResult16(0);

                }
        LCD_ClearDisplay();
        // mode exit if user press switch
        if(LED_Read()==1){mode++;}
        
        
    } 

}



void measure_continuity()
{
    IDAC_Start();
    LCD_ClearDisplay(); 
              //  Show Result on LCD  //     
    LCD_Position(0,0);LCD_PrintString("*  CONTINUITY MODE *");                      
    LCD_Position(1,6);LCD_PrintString("o-    -o");         
    LCD_Position(2,0); LCD_PrintString("   Continuity....  ");
    LCD_Position(3,0); LCD_PrintString("   Not Detected !!  ");
              
    Buzzer_Write(0);
    IDAC_Val=100;
    IDAC_SetValue(IDAC_Val);
    c=100;
    CyDelay(1000);
     while (mode==3)
    {
        
                if (c<50)
              { 
                  while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}
                  c=ADC_GetResult16(0);
                  CyDelay(10);
              LCD_ClearDisplay();
              //  Show Result on LCD  //     
              LCD_Position(0,0); LCD_PrintString("*  CONTINUITY MODE *");      
              LCD_Position(1,6);LCD_PrintString("o------o");
              LCD_Position(2,0); LCD_PrintString("   Continuity....  ");
              LCD_Position(3,0); LCD_PrintString("      Detected !!  ");
              Buzzer_Write(1);
              CyDelay(20); 
             }
            
              if (c>50)  
              {
                    while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}
                    c=ADC_GetResult16(0);
                    CyDelay(10);
              LCD_ClearDisplay(); 
              //  Show Result on LCD  //     
              LCD_Position(0,0);LCD_PrintString("*  CONTINUITY MODE *");                      
              LCD_Position(1,6);LCD_PrintString("o-    -o");         
              LCD_Position(2,0); LCD_PrintString("   Continuity....  ");
              LCD_Position(3,0); LCD_PrintString("   Not Detected !!  ");
              Buzzer_Write(0);
              CyDelay(20);
              }
            

        
        CyDelay(20);
        // mode exit if user press switch     
                  if(LED_Read()==1){mode++;Buzzer_Write(0);}
        
        
     
    }
    
}

//////// diode ///////////////
void measure_diode()
{
    IDAC_Start();
    LCD_ClearDisplay(); 
              //  Show Result on LCD  //     
    LCD_Position(0,0);LCD_PrintString("*    DIODE MODE    *");                      
    LCD_Position(1,6);LCD_PrintString("o--  --o");         
    LCD_Position(2,0); LCD_PrintString("   Diode/LED  ....  ");
    LCD_Position(3,0); LCD_PrintString("   Not Detected !!  ");
              
    Buzzer_Write(0);
    IDAC_Val=255;
    IDAC_SetValue(IDAC_Val);
    c=100;
    CyDelay(1000);
     while (mode==4)
    {
        
                if (c>3850)
              { 
                  while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}
                  c=ADC_GetResult16(0);
                  CyDelay(10);
              LCD_ClearDisplay();
              //  Show Result on LCD  //     
                LCD_Position(0,0);LCD_PrintString("*    DIODE MODE    *");                      
                LCD_Position(1,6);LCD_PrintString("o--  --o");         
                LCD_Position(2,0); LCD_PrintString("   Diode/LED  ....  ");
                LCD_Position(3,0); LCD_PrintString("   Not Detected !!  ");
              Buzzer_Write(0);
              CyDelay(200); 
             }
            
              if (c<3850)  
              {
                    while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}
                    c=ADC_GetResult16(0);
                    CyDelay(10);
              LCD_ClearDisplay(); 
              //  Show Result on LCD  //     
               LCD_Position(0,0);LCD_PrintString("*    DIODE MODE    *");                      
               LCD_Position(1,6);LCD_PrintString("o--");
               LCD_PutChar(LCD_CUSTOM_6);LCD_PutChar(LCD_CUSTOM_4);LCD_PrintString("--o");         
               LCD_Position(2,0); LCD_PrintString("Diode/LED Detected !");
               LCD_Position(3,1); LCD_PrintString("V_fd = ");
               int vfd = c/2; // in mV
               LCD_PrintU32Number(vfd/1000);
                    if(vfd%1000>=100)LCD_PrintString(".");
                    else if(vfd%1000>=10)LCD_PrintString(".0");
                    else if(vfd%1000<10)LCD_PrintString(".00");
              LCD_PrintU32Number(vfd%1000);
              LCD_PrintString(" Volt");
               
            Buzzer_Write(1);
            CyDelay(10);
            Buzzer_Write(0);
              CyDelay(200);
              }
            

        
        CyDelay(20);
        // mode exit if user press switch     
                  if(LED_Read()==1){mode++;Buzzer_Write(0);}
        
        
     
    }
    
}


//////////////////////

void ind_mode(void)
{
    LCD_Position(0,0);
    LCD_PrintString("* INDUCTANCE  MODE *");
    
    LCD_Position(1,6);
        LCD_Position(1,6);
        LCD_PrintString("o-");LCD_PutChar(LCD_CUSTOM_7);LCD_PutChar(LCD_CUSTOM_7);
        LCD_PutChar(LCD_CUSTOM_7);LCD_PutChar(LCD_CUSTOM_7);LCD_PrintString("-o");
    LCD_Position(2,0); LCD_PrintString("  Program for      ");
    LCD_Position(3,0); LCD_PrintString("      SINE Wave  ");    
    CyDelay(100);
    while(mode==3)
    {
      int i=0;
        for(i=0;i<255;i=i+8)
        {
   IDAC_SetValue(sine_wave[i]); // feed from a lookuo table
         }     
     if(LED_Read()==1) {mode++;}// EXIT COND
  
        }
    
    
}

    

PSoC Creator Files

C/C++
Full Code
No preview (download only).

Code Ver 1.5

C/C++
Capacitance, Resistance, Diode/Continuity Ok
#include <project.h>

volatile uint32_t us_10=0;  // 10 uSec variable
int current =0;
int voltage =0;
int resistance=0;
uint32_t IDAC_Val=0xff;
int c=4095;    
int j=0; //use as loop counter
int mode =1;

CY_ISR(Timing_ISR_Handler)
{
    us_10++;
    Timer_ClearInterrupt(Timer_TC_INTERRUPT_MASK);

}


uint8_t  sine_wave[256] = {
  0x80, 0x83, 0x86, 0x89, 0x8C, 0x90, 0x93, 0x96,
  0x99, 0x9C, 0x9F, 0xA2, 0xA5, 0xA8, 0xAB, 0xAE,
  0xB1, 0xB3, 0xB6, 0xB9, 0xBC, 0xBF, 0xC1, 0xC4,
  0xC7, 0xC9, 0xCC, 0xCE, 0xD1, 0xD3, 0xD5, 0xD8,
  0xDA, 0xDC, 0xDE, 0xE0, 0xE2, 0xE4, 0xE6, 0xE8,
  0xEA, 0xEB, 0xED, 0xEF, 0xF0, 0xF1, 0xF3, 0xF4,
  0xF5, 0xF6, 0xF8, 0xF9, 0xFA, 0xFA, 0xFB, 0xFC,
  0xFD, 0xFD, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xFE, 0xFD,
  0xFD, 0xFC, 0xFB, 0xFA, 0xFA, 0xF9, 0xF8, 0xF6,
  0xF5, 0xF4, 0xF3, 0xF1, 0xF0, 0xEF, 0xED, 0xEB,
  0xEA, 0xE8, 0xE6, 0xE4, 0xE2, 0xE0, 0xDE, 0xDC,
  0xDA, 0xD8, 0xD5, 0xD3, 0xD1, 0xCE, 0xCC, 0xC9,
  0xC7, 0xC4, 0xC1, 0xBF, 0xBC, 0xB9, 0xB6, 0xB3,
  0xB1, 0xAE, 0xAB, 0xA8, 0xA5, 0xA2, 0x9F, 0x9C,
  0x99, 0x96, 0x93, 0x90, 0x8C, 0x89, 0x86, 0x83,
  0x80, 0x7D, 0x7A, 0x77, 0x74, 0x70, 0x6D, 0x6A,
  0x67, 0x64, 0x61, 0x5E, 0x5B, 0x58, 0x55, 0x52,
  0x4F, 0x4D, 0x4A, 0x47, 0x44, 0x41, 0x3F, 0x3C,
  0x39, 0x37, 0x34, 0x32, 0x2F, 0x2D, 0x2B, 0x28,
  0x26, 0x24, 0x22, 0x20, 0x1E, 0x1C, 0x1A, 0x18,
  0x16, 0x15, 0x13, 0x11, 0x10, 0x0F, 0x0D, 0x0C,
  0x0B, 0x0A, 0x08, 0x07, 0x06, 0x06, 0x05, 0x04,
  0x03, 0x03, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01,
  0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x03,
  0x03, 0x04, 0x05, 0x06, 0x06, 0x07, 0x08, 0x0A,
  0x0B, 0x0C, 0x0D, 0x0F, 0x10, 0x11, 0x13, 0x15,
  0x16, 0x18, 0x1A, 0x1C, 0x1E, 0x20, 0x22, 0x24,
  0x26, 0x28, 0x2B, 0x2D, 0x2F, 0x32, 0x34, 0x37,
  0x39, 0x3C, 0x3F, 0x41, 0x44, 0x47, 0x4A, 0x4D,
  0x4F, 0x52, 0x55, 0x58, 0x5B, 0x5E, 0x61, 0x64,
  0x67, 0x6A, 0x6D, 0x70, 0x74, 0x77, 0x7A, 0x7D
};


void measure_resistance(void);
void measure_continuity(void);
void measure_capacitance(void);
void measure_diode(void);
void measure_inductance(void);


void res_mode(void)
{
        
}
/////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// MAIN LOOP /////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
int main()
{   
    LCD_Start();
    ADC_Start();
    IDAC_Start();
    Timer_Start();
    Timing_ISR_StartEx(Timing_ISR_Handler);
//    CyGlobalIntEnable;
    mode=1;
    IDAC_SetValue(IDAC_Val);
    ADC_StartConvert();
    LCD_Position(1,0);LCD_PrintString(" ! PSoC Auto Range !");
    LCD_Position(2,0);LCD_PrintString("***   LRC Meter  ***");
    CyDelay(2000);
    LCD_ClearDisplay();

    
    for(;;)
    {
    measure_capacitance();
    measure_resistance();
    measure_continuity();
    measure_diode();
        if (mode>4) {mode=1;}
    
  
    } ///////////////////////// Forever for loop ends here /////////////////////////////////*/

} ///////////////////=========== main loop Ends Here ===============/////////////////////////





///////////////////////////// FUNCTIONS BODY /////////////////////////////
void measure_resistance()
{
     IDAC_Start();
    unsigned long R=0;
    while (mode==1)
    {
    Buzzer_Write(0);
    IDAC_Val=0xff;
    c=4095;
    
        while((IDAC_Val>0)&&(c>=4000))
        {
    
        IDAC_Val=IDAC_Val-0x01;
        IDAC_SetValue(IDAC_Val);
        CyDelay(3);
        while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}
        c=ADC_GetResult16(0);
        CyDelay(2);
        }   
        
        if (c<4000)
        {
            
            IDAC_SetValue(IDAC_Val);      
            CyDelay(1);
            current= IDAC_Val*1.2;   // in uAmp
            voltage=c*1000/2;        // in uVolt
            resistance = voltage/current;  // Ohms Law to calculate resistanc
            resistance = resistance - 148; // offsetting internal trace resistance of 150 ohms per trace
                
                if (resistance<=0) {resistance = 0;}                  // omitting any negative value
                if (resistance>5000) {resistance = resistance*1.05;} // soft correction to reduce error
                
              LCD_ClearDisplay();
                // 500K IS THE LIMIT FOR RESISTANCE 
             if (resistance<500000)
             {
              //  Show Result on LCD  //     
              LCD_Position(0,0); LCD_PrintString("*  RESISTANCE MODE *");      
              LCD_Position(1,6);LCD_PrintString("o_");LCD_PutChar(LCD_CUSTOM_2);LCD_PutChar(LCD_CUSTOM_3);
              LCD_PutChar(LCD_CUSTOM_2);LCD_PutChar(LCD_CUSTOM_3);LCD_PrintString("_o");
              LCD_Position(2,5); LCD_PrintU32Number(resistance);
              LCD_PrintString(" ");LCD_PutChar(LCD_CUSTOM_0);
              LCD_Position(3,5);LCD_PrintU32Number(resistance/1000);
                    if(resistance%1000>=100)LCD_PrintString(".");
                    else if(resistance%1000>=10)LCD_PrintString(".0");
                    else if(resistance%1000<10)LCD_PrintString(".00");
              LCD_PrintU32Number(resistance%1000);
              LCD_PrintString(" k");
              LCD_PutChar(LCD_CUSTOM_0);
              CyDelay(100); 
             }
            
            else 
             {
              LCD_Position(0,0);LCD_PrintString("*  RESISTANCE MODE *");                      
              LCD_Position(1,6);LCD_PrintString("o_    _o");         
              LCD_Position(2,0); LCD_PrintString("No Resistor Detected");
              LCD_Position(3,0); LCD_PrintString(" Connect Resistor !!");
              CyDelay(100);
              }
            

        
        CyDelay(100);
        // mode exit if user press switch     
            if(LED_Read()==1){mode++;}
        }
        
     
    }
}


void measure_capacitance()
{
   
    while (mode==2)
    {
     // Timer_WritePeriod(10);
        IDAC_Stop();
          while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}
          c=ADC_GetResult16(0);
   
        LCD_ClearDisplay();
        LCD_Position(0,0);
        LCD_PrintString("* CAPACITANCE MODE *");
        LCD_Position(1,2);
        LCD_PrintString("(+) o--  --o (-)");

        IDAC_Start();
        IDAC_Val=100;
        IDAC_SetValue(IDAC_Val);// times 1.2 uA times CHARGE TIME is Q Coulomb charge
   
        int k=0;
        uint16 ADC_Level = 2048 ; // caps will charge through IDAC current upto this level
            while(c<ADC_Level)
            {
                if(k==0) // One time loop 
                {
                LCD_Position(0,0);LCD_PrintString("* CAPACITANCE MODE *");
                LCD_Position(1,2);LCD_PrintString("(+) o--");LCD_PutChar(LCD_CUSTOM_6);
                LCD_PutChar(LCD_CUSTOM_5);LCD_PrintString("--o (-)");

                LCD_Position(2,0);LCD_PrintString("   Measuring.....");
                k++;CyGlobalIntDisable; us_10=0;CyGlobalIntEnable;
                }
                // ADC is measuring voltage across capacitor
                while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}  
                c=ADC_GetResult16(0);
    
            }
    
        CyGlobalIntDisable;  // disabling interrupt to stop updating time
        IDAC_SetValue(0x00); // IDAC current is set 0
        IDAC_Stop();         // IDAC is stopped
        LCD_ClearDisplay();
        
        // Using C = Q/V = I*t/V formula, Capacitance will be calculated and displayed 
                while(c>256)
                {     
                LCD_Position(0,0); LCD_PrintString("* CAPACITANCE MODE *");        
        // Calculation Below //
                
                //  float Charge = IDAC_Val*1.2; // 1.2 uA is the step current               
                //  uint32 Time = us_10/100;  // microsec to milisec
                //  float Volt = ADC_Level/2.0;
                //  Approx Timing Correction for Execution Delay by adding 20% to calculated value (1.2 times)
                
                double nFCaptemp =  1000*1.2*((IDAC_Val*1.2*us_10/100.0)/(ADC_Level/2.0));
                uint32 nFCap = nFCaptemp;
                uint32 Capacitance = nFCap/1000;
              
        
        // Displaying Capacitacne on LCD //
                LCD_Position(1,2);LCD_PrintString("(+) o--  --o (-)");
              //  LCD_PrintString("(+) o--");LCD_PutChar(LCD_CUSTOM_6);LCD_PutChar(LCD_CUSTOM_5);LCD_PrintString("--o (-)");  
                LCD_Position(2,7); LCD_PrintU32Number(Capacitance);LCD_PrintString(" uF ");
                LCD_Position(3,7);; LCD_PrintU32Number(nFCap);LCD_PrintString(" nF ");
    
                CyDelay(500);
                
                // Checks for presence of Capacitance connected to Probe //
                while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}
                c=ADC_GetResult16(0);

                }
        LCD_ClearDisplay();
        // mode exit if user press switch
        if(LED_Read()==1){mode++;}
        
        
    } 

}



void measure_continuity()
{
    IDAC_Start();
    LCD_ClearDisplay(); 
              //  Show Result on LCD  //     
    LCD_Position(0,0);LCD_PrintString("*  CONTINUITY MODE *");                      
    LCD_Position(1,6);LCD_PrintString("o-    -o");         
    LCD_Position(2,0); LCD_PrintString("   Continuity....  ");
    LCD_Position(3,0); LCD_PrintString("   Not Detected !!  ");
              
    Buzzer_Write(0);
    IDAC_Val=100;
    IDAC_SetValue(IDAC_Val);
    c=100;
    CyDelay(1000);
     while (mode==3)
    {
        
                if (c<50)
              { 
                  while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}
                  c=ADC_GetResult16(0);
                  CyDelay(10);
              LCD_ClearDisplay();
              //  Show Result on LCD  //     
              LCD_Position(0,0); LCD_PrintString("*  CONTINUITY MODE *");      
              LCD_Position(1,6);LCD_PrintString("o------o");
              LCD_Position(2,0); LCD_PrintString("   Continuity....  ");
              LCD_Position(3,0); LCD_PrintString("      Detected !!  ");
              Buzzer_Write(1);
              CyDelay(20); 
             }
            
              if (c>50)  
              {
                    while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}
                    c=ADC_GetResult16(0);
                    CyDelay(10);
              LCD_ClearDisplay(); 
              //  Show Result on LCD  //     
              LCD_Position(0,0);LCD_PrintString("*  CONTINUITY MODE *");                      
              LCD_Position(1,6);LCD_PrintString("o-    -o");         
              LCD_Position(2,0); LCD_PrintString("   Continuity....  ");
              LCD_Position(3,0); LCD_PrintString("   Not Detected !!  ");
              Buzzer_Write(0);
              CyDelay(20);
              }
            

        
        CyDelay(20);
        // mode exit if user press switch     
                  if(LED_Read()==1){mode++;Buzzer_Write(0);}
        
        
     
    }
    
}

//////// diode ///////////////
void measure_diode()
{
    IDAC_Start();
    LCD_ClearDisplay(); 
              //  Show Result on LCD  //     
    LCD_Position(0,0);LCD_PrintString("*    DIODE MODE    *");                      
    LCD_Position(1,6);LCD_PrintString("o--  --o");         
    LCD_Position(2,0); LCD_PrintString("   Diode/LED  ....  ");
    LCD_Position(3,0); LCD_PrintString("   Not Detected !!  ");
              
    Buzzer_Write(0);
    IDAC_Val=255;
    IDAC_SetValue(IDAC_Val);
    c=100;
    CyDelay(1000);
     while (mode==4)
    {
        
                if (c>3850)
              { 
                  while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}
                  c=ADC_GetResult16(0);
                  CyDelay(10);
              LCD_ClearDisplay();
              //  Show Result on LCD  //     
                LCD_Position(0,0);LCD_PrintString("*    DIODE MODE    *");                      
                LCD_Position(1,6);LCD_PrintString("o--  --o");         
                LCD_Position(2,0); LCD_PrintString("   Diode/LED  ....  ");
                LCD_Position(3,0); LCD_PrintString("   Not Detected !!  ");
              Buzzer_Write(0);
              CyDelay(200); 
             }
            
              if (c<3850)  
              {
                    while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}
                    c=ADC_GetResult16(0);
                    CyDelay(10);
              LCD_ClearDisplay(); 
              //  Show Result on LCD  //     
               LCD_Position(0,0);LCD_PrintString("*    DIODE MODE    *");                      
               LCD_Position(1,6);LCD_PrintString("o--");
               LCD_PutChar(LCD_CUSTOM_6);LCD_PutChar(LCD_CUSTOM_4);LCD_PrintString("--o");         
               LCD_Position(2,0); LCD_PrintString("Diode/LED Detected !");
               LCD_Position(3,1); LCD_PrintString("V_fd = ");
               int vfd = c/2; // in mV
               LCD_PrintU32Number(vfd/1000);
                    if(vfd%1000>=100)LCD_PrintString(".");
                    else if(vfd%1000>=10)LCD_PrintString(".0");
                    else if(vfd%1000<10)LCD_PrintString(".00");
              LCD_PrintU32Number(vfd%1000);
              LCD_PrintString(" Volt");
               
            Buzzer_Write(1);
            CyDelay(10);
            Buzzer_Write(0);
              CyDelay(200);
              }
            

        
        CyDelay(20);
        // mode exit if user press switch     
                  if(LED_Read()==1){mode++;Buzzer_Write(0);}
        
        
     
    }
    
}


//////////////////////

void ind_mode(void)
{
    LCD_Position(0,0);
    LCD_PrintString("* INDUCTANCE  MODE *");
    
    LCD_Position(1,6);
        LCD_Position(1,6);
        LCD_PrintString("o-");LCD_PutChar(LCD_CUSTOM_7);LCD_PutChar(LCD_CUSTOM_7);
        LCD_PutChar(LCD_CUSTOM_7);LCD_PutChar(LCD_CUSTOM_7);LCD_PrintString("-o");
    LCD_Position(2,0); LCD_PrintString("  Program for      ");
    LCD_Position(3,0); LCD_PrintString("      SINE Wave  ");    
    CyDelay(100);
    while(mode==3)
    {
      int i=0;
        for(i=0;i<255;i=i+8)
        {
   IDAC_SetValue(sine_wave[i]); // feed from a lookuo table
         }     
     if(LED_Read()==1) {mode++;}// EXIT COND
  
        }
    
    
}

    

Code Ver 1.6

C/C++
Provision for Inductance
#include <project.h>

volatile uint32_t us_10=0;  // 10 uSec variable
int current =0;
int voltage =0;
int resistance=0;
uint32_t IDAC_Val=0xff;
int c=4095;    
int j=0; //use as loop counter
int mode =1;

CY_ISR(Timing_ISR_Handler)
{
    us_10++;
    Timer_ClearInterrupt(Timer_TC_INTERRUPT_MASK);

}


uint8_t  sine_wave[256] = {
  0x80, 0x83, 0x86, 0x89, 0x8C, 0x90, 0x93, 0x96,
  0x99, 0x9C, 0x9F, 0xA2, 0xA5, 0xA8, 0xAB, 0xAE,
  0xB1, 0xB3, 0xB6, 0xB9, 0xBC, 0xBF, 0xC1, 0xC4,
  0xC7, 0xC9, 0xCC, 0xCE, 0xD1, 0xD3, 0xD5, 0xD8,
  0xDA, 0xDC, 0xDE, 0xE0, 0xE2, 0xE4, 0xE6, 0xE8,
  0xEA, 0xEB, 0xED, 0xEF, 0xF0, 0xF1, 0xF3, 0xF4,
  0xF5, 0xF6, 0xF8, 0xF9, 0xFA, 0xFA, 0xFB, 0xFC,
  0xFD, 0xFD, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xFE, 0xFD,
  0xFD, 0xFC, 0xFB, 0xFA, 0xFA, 0xF9, 0xF8, 0xF6,
  0xF5, 0xF4, 0xF3, 0xF1, 0xF0, 0xEF, 0xED, 0xEB,
  0xEA, 0xE8, 0xE6, 0xE4, 0xE2, 0xE0, 0xDE, 0xDC,
  0xDA, 0xD8, 0xD5, 0xD3, 0xD1, 0xCE, 0xCC, 0xC9,
  0xC7, 0xC4, 0xC1, 0xBF, 0xBC, 0xB9, 0xB6, 0xB3,
  0xB1, 0xAE, 0xAB, 0xA8, 0xA5, 0xA2, 0x9F, 0x9C,
  0x99, 0x96, 0x93, 0x90, 0x8C, 0x89, 0x86, 0x83,
  0x80, 0x7D, 0x7A, 0x77, 0x74, 0x70, 0x6D, 0x6A,
  0x67, 0x64, 0x61, 0x5E, 0x5B, 0x58, 0x55, 0x52,
  0x4F, 0x4D, 0x4A, 0x47, 0x44, 0x41, 0x3F, 0x3C,
  0x39, 0x37, 0x34, 0x32, 0x2F, 0x2D, 0x2B, 0x28,
  0x26, 0x24, 0x22, 0x20, 0x1E, 0x1C, 0x1A, 0x18,
  0x16, 0x15, 0x13, 0x11, 0x10, 0x0F, 0x0D, 0x0C,
  0x0B, 0x0A, 0x08, 0x07, 0x06, 0x06, 0x05, 0x04,
  0x03, 0x03, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01,
  0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x03,
  0x03, 0x04, 0x05, 0x06, 0x06, 0x07, 0x08, 0x0A,
  0x0B, 0x0C, 0x0D, 0x0F, 0x10, 0x11, 0x13, 0x15,
  0x16, 0x18, 0x1A, 0x1C, 0x1E, 0x20, 0x22, 0x24,
  0x26, 0x28, 0x2B, 0x2D, 0x2F, 0x32, 0x34, 0x37,
  0x39, 0x3C, 0x3F, 0x41, 0x44, 0x47, 0x4A, 0x4D,
  0x4F, 0x52, 0x55, 0x58, 0x5B, 0x5E, 0x61, 0x64,
  0x67, 0x6A, 0x6D, 0x70, 0x74, 0x77, 0x7A, 0x7D
};


void measure_resistance(void);
void measure_continuity(void);
void measure_capacitance(void);
void measure_diode(void);
void measure_inductance(void);


void res_mode(void)
{
        
}
/////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// MAIN LOOP /////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
int main()
{   
    LCD_Start();
    ADC_Start();
    IDAC_Start();
    Timer_Start();
    Timing_ISR_StartEx(Timing_ISR_Handler);
//    CyGlobalIntEnable;
    mode=1;
    IDAC_SetValue(IDAC_Val);
    ADC_StartConvert();
    LCD_Position(1,0);LCD_PrintString(" ! PSoC Auto Range !");
    LCD_Position(2,0);LCD_PrintString("***   LRC Meter  ***");
    CyDelay(2000);
    LCD_ClearDisplay();

    
    for(;;)
    {
    measure_capacitance();
    measure_resistance();
    measure_continuity();
    measure_diode();
        if (mode>4) {mode=1;}
    
  
    } ///////////////////////// Forever for loop ends here /////////////////////////////////*/

} ///////////////////=========== main loop Ends Here ===============/////////////////////////





///////////////////////////// FUNCTIONS BODY /////////////////////////////
void measure_resistance()
{
     IDAC_Start();
    unsigned long R=0;
    while (mode==1)
    {
    Buzzer_Write(0);
    IDAC_Val=0xff;
    c=4095;
    
        while((IDAC_Val>0)&&(c>=4000))
        {
    
        IDAC_Val=IDAC_Val-0x01;
        IDAC_SetValue(IDAC_Val);
        CyDelay(3);
        while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}
        c=ADC_GetResult16(0);
        CyDelay(2);
        }   
        
        if (c<4000)
        {
            
            IDAC_SetValue(IDAC_Val);      
            CyDelay(1);
            current= IDAC_Val*1.2;   // in uAmp
            voltage=c*1000/2;        // in uVolt
            resistance = voltage/current;  // Ohms Law to calculate resistanc
            resistance = resistance - 148; // offsetting internal trace resistance of 150 ohms per trace
                
                if (resistance<=0) {resistance = 0;}                  // omitting any negative value
                if (resistance>5000) {resistance = resistance*1.05;} // soft correction to reduce error
                
              LCD_ClearDisplay();
                // 500K IS THE LIMIT FOR RESISTANCE 
             if (resistance<500000)
             {
              //  Show Result on LCD  //     
              LCD_Position(0,0); LCD_PrintString("*  RESISTANCE MODE *");      
              LCD_Position(1,6);LCD_PrintString("o_");LCD_PutChar(LCD_CUSTOM_2);LCD_PutChar(LCD_CUSTOM_3);
              LCD_PutChar(LCD_CUSTOM_2);LCD_PutChar(LCD_CUSTOM_3);LCD_PrintString("_o");
              LCD_Position(2,5); LCD_PrintU32Number(resistance);
              LCD_PrintString(" ");LCD_PutChar(LCD_CUSTOM_0);
              LCD_Position(3,5);LCD_PrintU32Number(resistance/1000);
                    if(resistance%1000>=100)LCD_PrintString(".");
                    else if(resistance%1000>=10)LCD_PrintString(".0");
                    else if(resistance%1000<10)LCD_PrintString(".00");
              LCD_PrintU32Number(resistance%1000);
              LCD_PrintString(" k");
              LCD_PutChar(LCD_CUSTOM_0);
              CyDelay(100); 
             }
            
            else 
             {
              LCD_Position(0,0);LCD_PrintString("*  RESISTANCE MODE *");                      
              LCD_Position(1,6);LCD_PrintString("o_    _o");         
              LCD_Position(2,0); LCD_PrintString("No Resistor Detected");
              LCD_Position(3,0); LCD_PrintString(" Connect Resistor !!");
              CyDelay(100);
              }
            

        
        CyDelay(100);
        // mode exit if user press switch     
            if(LED_Read()==1){mode++;}
        }
        
     
    }
}


void measure_capacitance()
{
   
    while (mode==2)
    {
     // Timer_WritePeriod(10);
        IDAC_Stop();
          while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}
          c=ADC_GetResult16(0);
   
        LCD_ClearDisplay();
        LCD_Position(0,0);
        LCD_PrintString("* CAPACITANCE MODE *");
        LCD_Position(1,2);
        LCD_PrintString("(+) o--  --o (-)");

        IDAC_Start();
        IDAC_Val=100;
        IDAC_SetValue(IDAC_Val);// times 1.2 uA times CHARGE TIME is Q Coulomb charge
   
        int k=0;
        uint16 ADC_Level = 2048 ; // caps will charge through IDAC current upto this level
            while(c<ADC_Level)
            {
                if(k==0) // One time loop 
                {
                LCD_Position(0,0);LCD_PrintString("* CAPACITANCE MODE *");
                LCD_Position(1,2);LCD_PrintString("(+) o--");LCD_PutChar(LCD_CUSTOM_6);
                LCD_PutChar(LCD_CUSTOM_5);LCD_PrintString("--o (-)");

                LCD_Position(2,0);LCD_PrintString("   Measuring.....");
                k++;CyGlobalIntDisable; us_10=0;CyGlobalIntEnable;
                }
                // ADC is measuring voltage across capacitor
                while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}  
                c=ADC_GetResult16(0);
    
            }
    
        CyGlobalIntDisable;  // disabling interrupt to stop updating time
        IDAC_SetValue(0x00); // IDAC current is set 0
        IDAC_Stop();         // IDAC is stopped
        LCD_ClearDisplay();
        
        // Using C = Q/V = I*t/V formula, Capacitance will be calculated and displayed 
                while(c>256)
                {     
                LCD_Position(0,0); LCD_PrintString("* CAPACITANCE MODE *");        
        // Calculation Below //
                
                //  float Charge = IDAC_Val*1.2; // 1.2 uA is the step current               
                //  uint32 Time = us_10/100;  // microsec to milisec
                //  float Volt = ADC_Level/2.0;
                //  Approx Timing Correction for Execution Delay by adding 20% to calculated value (1.2 times)
                
                double nFCaptemp =  1000*1.2*((IDAC_Val*1.2*us_10/100.0)/(ADC_Level/2.0));
                uint32 nFCap = nFCaptemp;
                uint32 Capacitance = nFCap/1000;
              
        
        // Displaying Capacitacne on LCD //
                LCD_Position(1,2);LCD_PrintString("(+) o--  --o (-)");
              //  LCD_PrintString("(+) o--");LCD_PutChar(LCD_CUSTOM_6);LCD_PutChar(LCD_CUSTOM_5);LCD_PrintString("--o (-)");  
                LCD_Position(2,7); LCD_PrintU32Number(Capacitance);LCD_PrintString(" uF ");
                LCD_Position(3,7);; LCD_PrintU32Number(nFCap);LCD_PrintString(" nF ");
    
                CyDelay(500);
                
                // Checks for presence of Capacitance connected to Probe //
                while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}
                c=ADC_GetResult16(0);

                }
        LCD_ClearDisplay();
        // mode exit if user press switch
        if(LED_Read()==1){mode++;}
        
        
    } 

}



void measure_continuity()
{
    IDAC_Start();
    LCD_ClearDisplay(); 
              //  Show Result on LCD  //     
    LCD_Position(0,0);LCD_PrintString("*  CONTINUITY MODE *");                      
    LCD_Position(1,6);LCD_PrintString("o-    -o");         
    LCD_Position(2,0); LCD_PrintString("   Continuity....  ");
    LCD_Position(3,0); LCD_PrintString("   Not Detected !!  ");
              
    Buzzer_Write(0);
    IDAC_Val=100;
    IDAC_SetValue(IDAC_Val);
    c=100;
    CyDelay(1000);
     while (mode==3)
    {
        
                if (c<50)
              { 
                  while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}
                  c=ADC_GetResult16(0);
                  CyDelay(10);
              LCD_ClearDisplay();
              //  Show Result on LCD  //     
              LCD_Position(0,0); LCD_PrintString("*  CONTINUITY MODE *");      
              LCD_Position(1,6);LCD_PrintString("o------o");
              LCD_Position(2,0); LCD_PrintString("   Continuity....  ");
              LCD_Position(3,0); LCD_PrintString("      Detected !!  ");
              Buzzer_Write(1);
              CyDelay(20); 
             }
            
              if (c>50)  
              {
                    while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}
                    c=ADC_GetResult16(0);
                    CyDelay(10);
              LCD_ClearDisplay(); 
              //  Show Result on LCD  //     
              LCD_Position(0,0);LCD_PrintString("*  CONTINUITY MODE *");                      
              LCD_Position(1,6);LCD_PrintString("o-    -o");         
              LCD_Position(2,0); LCD_PrintString("   Continuity....  ");
              LCD_Position(3,0); LCD_PrintString("   Not Detected !!  ");
              Buzzer_Write(0);
              CyDelay(20);
              }
            

        
        CyDelay(20);
        // mode exit if user press switch     
                  if(LED_Read()==1){mode++;Buzzer_Write(0);}
        
        
     
    }
    
}

//////// diode ///////////////
void measure_diode()
{
    IDAC_Start();
    LCD_ClearDisplay(); 
              //  Show Result on LCD  //     
    LCD_Position(0,0);LCD_PrintString("*    DIODE MODE    *");                      
    LCD_Position(1,6);LCD_PrintString("o--  --o");         
    LCD_Position(2,0); LCD_PrintString("   Diode/LED  ....  ");
    LCD_Position(3,0); LCD_PrintString("   Not Detected !!  ");
              
    Buzzer_Write(0);
    IDAC_Val=255;
    IDAC_SetValue(IDAC_Val);
    c=100;
    CyDelay(1000);
     while (mode==4)
    {
        
                if (c>3850)
              { 
                  while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}
                  c=ADC_GetResult16(0);
                  CyDelay(10);
              LCD_ClearDisplay();
              //  Show Result on LCD  //     
                LCD_Position(0,0);LCD_PrintString("*    DIODE MODE    *");                      
                LCD_Position(1,6);LCD_PrintString("o--  --o");         
                LCD_Position(2,0); LCD_PrintString("   Diode/LED  ....  ");
                LCD_Position(3,0); LCD_PrintString("   Not Detected !!  ");
              Buzzer_Write(0);
              CyDelay(200); 
             }
            
              if (c<3850)  
              {
                    while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}
                    c=ADC_GetResult16(0);
                    CyDelay(10);
              LCD_ClearDisplay(); 
              //  Show Result on LCD  //     
               LCD_Position(0,0);LCD_PrintString("*    DIODE MODE    *");                      
               LCD_Position(1,6);LCD_PrintString("o--");
               LCD_PutChar(LCD_CUSTOM_6);LCD_PutChar(LCD_CUSTOM_4);LCD_PrintString("--o");         
               LCD_Position(2,0); LCD_PrintString("Diode/LED Detected !");
               LCD_Position(3,1); LCD_PrintString("V_fd = ");
               int vfd = c/2; // in mV
               LCD_PrintU32Number(vfd/1000);
                    if(vfd%1000>=100)LCD_PrintString(".");
                    else if(vfd%1000>=10)LCD_PrintString(".0");
                    else if(vfd%1000<10)LCD_PrintString(".00");
              LCD_PrintU32Number(vfd%1000);
              LCD_PrintString(" Volt");
               
            Buzzer_Write(1);
            CyDelay(10);
            Buzzer_Write(0);
              CyDelay(200);
              }
            

        
        CyDelay(20);
        // mode exit if user press switch     
                  if(LED_Read()==1){mode++;Buzzer_Write(0);}
        
        
     
    }
    
}


//////////////////////

void ind_mode(void)
{
    LCD_Position(0,0);
    LCD_PrintString("* INDUCTANCE  MODE *");
    
    LCD_Position(1,6);
        LCD_Position(1,6);
        LCD_PrintString("o-");LCD_PutChar(LCD_CUSTOM_7);LCD_PutChar(LCD_CUSTOM_7);
        LCD_PutChar(LCD_CUSTOM_7);LCD_PutChar(LCD_CUSTOM_7);LCD_PrintString("-o");
    LCD_Position(2,0); LCD_PrintString("  Program for      ");
    LCD_Position(3,0); LCD_PrintString("      SINE Wave  ");    
    CyDelay(100);
    while(mode==3)
    {
      int i=0;
        for(i=0;i<255;i=i+8)
        {
   IDAC_SetValue(sine_wave[i]); // feed from a lookuo table
         }     
     if(LED_Read()==1) {mode++;}// EXIT COND
  
        }
    
    
}

    

Credits

Shahariar

Shahariar

74 projects • 266 followers
"What Kills a 'Great life' is a 'Good Life', which is Living a Life Inside While Loop"

Comments