main.c

Created Diff never expires
/* ************************************************************************
/* ************************************************************************
*
*
* main part
* main part
*
*
* (c) 2012-2020 by Markus Reschke
* (c) 2012-2020 by Markus Reschke
* based on code from Markus Frejek and Karl-Heinz Kübbeler
* based on code from Markus Frejek and Karl-Heinz Kübbeler
*
*
* ************************************************************************ */
* ************************************************************************ */




/*
/*
* local constants
* local constants
*/
*/


/* source management */
/* source management */
#define MAIN_C
#define MAIN_C




/*
/*
* include header files
* include header files
*/
*/


/* local includes */
/* local includes */
#include "config.h" /* global configuration */
#include "config.h" /* global configuration */
#include "common.h" /* common header file */
#include "common.h" /* common header file */
#include "variables.h" /* global variables */
#include "variables.h" /* global variables */
#include "functions.h" /* external functions */
#include "functions.h" /* external functions */
#include "colors.h" /* color definitions */
#include "colors.h" /* color definitions */




/*
/*
* local variables
* local variables
*/
*/


/* program control */
/* program control */
#if CYCLE_MAX < 255
#if CYCLE_MAX < 255
uint8_t MissedParts; /* counter for failed/missed components */
uint8_t MissedParts; /* counter for failed/missed components */
#endif
#endif




/* ************************************************************************
/* ************************************************************************
* output components and errors
* output components and errors
* ************************************************************************ */
* ************************************************************************ */




/*
/*
* show pinout for semiconductors
* show pinout for semiconductors
*
*
* required:
* required:
* - character for pin A
* - character for pin A
* - character for pin B
* - character for pin B
* - character for pin C
* - character for pin C
*/
*/


void Show_SemiPinout(uint8_t A, uint8_t B, uint8_t C)
void Show_SemiPinout(uint8_t A, uint8_t B, uint8_t C)
{
{
uint8_t n; /* counter */
uint8_t n; /* counter */
uint8_t Char; /* character */
uint8_t Char; /* character */
#ifdef SW_PROBE_COLORS
#ifdef SW_PROBE_COLORS
uint16_t Color; /* color value */
uint16_t Color; /* color value */


Color = UI.PenColor; /* save current color */
Color = UI.PenColor; /* save current color */
#endif
#endif


/* display: 123 */
/* display: 123 */
for (n = 0; n <= 2; n++)
for (n = 0; n <= 2; n++)
{
{
Display_ProbeNumber(n);
Display_ProbeNumber(n);
}
}


/* display: = */
/* display: = */
Display_Char('=');
Display_Char('=');


/* display pin IDs */
/* display pin IDs */
for (n = 0; n <= 2; n++) /* loop through probe pins */
for (n = 0; n <= 2; n++) /* loop through probe pins */
{
{
#ifdef SW_PROBE_COLORS
#ifdef SW_PROBE_COLORS
UI.PenColor = ProbeColors[n]; /* set probe color */
UI.PenColor = ProbeColors[n]; /* set probe color */
#endif
#endif


if (n == Semi.A) Char = A; /* probe A - ID A */
if (n == Semi.A) Char = A; /* probe A - ID A */
else if (n == Semi.B) Char = B; /* probe B - ID B */
else if (n == Semi.B) Char = B; /* probe B - ID B */
else Char = C; /* - ID C */
else Char = C; /* - ID C */


Display_Char(Char); /* display ID */
Display_Char(Char); /* display ID */
}
}


#ifdef SW_PROBE_COLORS
#ifdef SW_PROBE_COLORS
UI.PenColor = Color; /* restore old color */
UI.PenColor = Color; /* restore old color */
#endif
#endif
}
}






/*
/*
* show simple pinout
* show simple pinout
*
*
* required:
* required:
* - ID: characters for probes 1, 2 and 3
* - ID: characters for probes 1, 2 and 3
* 0 -> not displayed
* 0 -> not displayed
*/
*/


void Show_SimplePinout(uint8_t ID_1, uint8_t ID_2, uint8_t ID_3)
void Show_SimplePinout(uint8_t ID_1, uint8_t ID_2, uint8_t ID_3)
{
{
uint8_t n; /* counter */
uint8_t n; /* counter */
unsigned char ID[3]; /* component pin IDs */
unsigned char ID[3]; /* component pin IDs */
#ifdef SW_PROBE_COLORS
#ifdef SW_PROBE_COLORS
uint16_t Color; /* color value */
uint16_t Color; /* color value */


Color = UI.PenColor; /* save current color */
Color = UI.PenColor; /* save current color */
#endif
#endif


/* copy probe pin characters/IDs */
/* copy probe pin characters/IDs */
ID[0] = ID_1;
ID[0] = ID_1;
ID[1] = ID_2;
ID[1] = ID_2;
ID[2] = ID_3;
ID[2] = ID_3;


for (n = 0; n <= 2; n++) /* loop through probe pins */
for (n = 0; n <= 2; n++) /* loop through probe pins */
{
{
if (ID[n] != 0) /* display this one */
if (ID[n] != 0) /* display this one */
{
{
Display_ProbeNumber(n);
Display_ProbeNumber(n);
Display_Char(':');
Display_Char(':');


#ifdef SW_PROBE_COLORS
#ifdef SW_PROBE_COLORS
UI.PenColor = ProbeColors[n]; /* set probe color */
UI.PenColor = ProbeColors[n]; /* set probe color */
#endif
#endif


Display_Char(ID[n]);
Display_Char(ID[n]);


#ifdef SW_PROBE_COLORS
#ifdef SW_PROBE_COLORS
UI.PenColor = Color; /* restore old color */
UI.PenColor = Color; /* restore old color */
#endif
#endif


Display_Space();
Display_Space();
}
}
}
}
}
}






#ifdef FUNC_EVALUE
#ifdef FUNC_EVALUE


/*
/*
* show E series norm values
* show E series norm values
*
*
* requires:
* requires:
* - Value: unsigned value
* - Value: unsigned value
* - Scale: exponent/multiplier (* 10^n)
* - Scale: exponent/multiplier (* 10^n)
* - ESeries: E6-192
* - ESeries: E6-192
* - Tolerance: in 0.1%
* - Tolerance: in 0.1%
* - Unit: unit character
* - Unit: unit character
*/
*/


void Show_ENormValues(uint32_t Value, int8_t Scale, uint8_t ESeries, uint8_t Tolerance, unsigned char Unit)
void Show_ENormValues(uint32_t Value, int8_t Scale, uint8_t ESeries, uint8_t Tolerance, unsigned char Unit)
{
{
uint8_t n; /* number of norm values (1 or 2) */
uint8_t n; /* number of norm values (1 or 2) */
uint8_t Pos; /* char x position */
uint8_t Pos; /* char x position */
uint8_t Temp; /* temporary value */
uint8_t Temp; /* temporary value */




/*
/*
* get E series norm values
* get E series norm values
* - 1st: Semi.I_value, Semi.I_scale
* - 1st: Semi.I_value, Semi.I_scale
* - 2nd: Semi.C_value, Semi.C_scale
* - 2nd: Semi.C_value, Semi.C_scale
*/
*/


n = GetENormValue(Value, Scale, ESeries, Tolerance);
n = GetENormValue(Value, Scale, ESeries, Tolerance);




/*
/*
* show E series and tolerance
* show E series and tolerance
*/
*/


Display_NextLine(); /* move to next line */
Display_NextLine(); /* move to next line */


/* display E series */
/* display E series */
Display_Char('E'); /* display: E */
Display_Char('E'); /* display: E */
Display_FullValue(ESeries, 0 , 0); /* display E series */
Display_FullValue(ESeries, 0 , 0); /* display E series */


Display_Space(); /* display: " " */
Display_Space(); /* display: " " */


/* display tolerance */
/* display tolerance */
Temp = Tolerance; /* copy tolerance */
Temp = Tolerance; /* copy tolerance */
Pos = 0; /* reset decimal places */
Pos = 0; /* reset decimal places */


if (Temp < 10) /* < 1% */
if (Temp < 10) /* < 1% */
{
{
Pos = 1; /* one decimal place */
Pos = 1; /* one decimal place */
}
}
Temp /= 10; /* scale to 1 */
Temp /= 10; /* scale to 1 */


Display_FullValue(Temp, Pos, '%'); /* display tolerance */
Display_FullValue(Temp, Pos, '%'); /* display tolerance */


Display_Space(); /* display: " " */
Display_Space(); /* display: " " */




/*
/*
* show norm values
* show norm values
*/
*/


if (n) /* got norm value(s) */
if (n) /* got norm value(s) */
{
{
Pos = UI.CharPos_X; /* get current char position */
Pos = UI.CharPos_X; /* get current char position */


/* display first norm value */
/* display first norm value */
Display_EValue(Semi.I_value, Semi.I_scale, Unit);
Display_EValue(Semi.I_value, Semi.I_scale, Unit);


if (n == 2) /* got two norm values */
if (n == 2) /* got two norm values */
{
{
/* move to next line at same position (after E series) */
/* move to next line at same position (after E series) */
Display_NextLine();
Display_NextLine();
LCD_CharPos(Pos, UI.CharPos_Y);
LCD_CharPos(Pos, UI.CharPos_Y);


/* display second norm value */
/* display second norm value */
Display_EValue(Semi.C_value, Semi.C_scale, Unit);
Display_EValue(Semi.C_value, Semi.C_scale, Unit);
}
}
}
}
else /* no norm value */
else /* no norm value */
{
{
Display_Char('-'); /* display: - */
Display_Char('-'); /* display: - */
}
}
}
}


#endif
#endif






#ifdef FUNC_COLORCODE
#ifdef FUNC_COLORCODE


/*
/*
* show E series norm value color-codes
* show E series norm value color-codes
*
*
* requires:
* requires:
* - Value: unsigned value
* - Value: unsigned value
* - Scale: exponent/multiplier (* 10^n)
* - Scale: exponent/multiplier (* 10^n)
* - ESeries: E6-192
* - ESeries: E6-192
* - Tolerance: in 0.1%
* - Tolerance: in 0.1%
* - TolBand: color of tolerance band
* - TolBand: color of tolerance band
*/
*/


void Show_ENormCodes(uint32_t Value, int8_t Scale, uint8_t ESeries, uint8_t Tolerance, uint16_t TolBand)
void Show_ENormCodes(uint32_t Value, int8_t Scale, uint8_t ESeries, uint8_t Tolerance, uint16_t TolBand)
{
{
uint8_t n; /* number of norm values (1 or 2) */
uint8_t n; /* number of norm values (1 or 2) */
uint8_t Pos; /* char x position */
uint8_t Pos; /* char x position */


/*
/*
* tolerance band
* tolerance band
* - resistor
* - resistor
* 20% 10% 5% 2% 1% 0.5% 0.25% 0.1% 0.05%
* 20% 10% 5% 2% 1% 0.5% 0.25% 0.1% 0.05%
* none silver gold red brown green blue violet grey
* none silver gold red brown green blue violet grey
* - inductor
* - inductor
* 20% 10% 5% 4% 3% 2% 1% 0.5% 0.25% 0.1% 0.05%
* 20% 10% 5% 4% 3% 2% 1% 0.5% 0.25% 0.1% 0.05%
* black silver gold yellow orange red brown green blue violet grey
* black silver gold yellow orange red brown green blue violet grey
* - caps: many different schemas
* - caps: many different schemas
*
*
* multiplier reference
* multiplier reference
* - R: 0 (10^0) -> 1 Ohms
* - R: 0 (10^0) -> 1 Ohms
* C: -12 (10^-12) -> 1 pF
* C: -12 (10^-12) -> 1 pF
* L: -6 (10^-6) -> 1 µH
* L: -6 (10^-6) -> 1 µH
* - ref_scale as function argument?
* - ref_scale as function argument?
* scale = scale - ref_scale
* scale = scale - ref_scale
*/
*/


/*
/*
* get E series norm values
* get E series norm values
* - 1st: Semi.I_value, Semi.I_scale
* - 1st: Semi.I_value, Semi.I_scale
* - 2nd: Semi.C_value, Semi.C_scale
* - 2nd: Semi.C_value, Semi.C_scale
*/
*/


n = GetENormValue(Value, Scale, ESeries, Tolerance);
n = GetENormValue(Value, Scale, ESeries, Tolerance);




/*
/*
* show E series
* show E series
*/
*/


Display_NextLine(); /* move to next line */
Display_NextLine(); /* move to next line */


/* display E series */
/* display E series */
Display_Char('E'); /* display: E */
Display_Char('E'); /* display: E */
Display_FullValue(ESeries, 0 , 0); /* display E series */
Display_FullValue(ESeries, 0 , 0); /* display E series */


Display_Space(); /* display: " " */
Display_Space(); /* display: " " */




/*
/*
* show color-codes of norm values
* show color-codes of norm values
*/
*/


if (n) /* got norm value(s) */
if (n) /* got norm value(s) */
{
{
Pos = UI.CharPos_X; /* get current char position */
Pos = UI.CharPos_X; /* get current char position */


/* display color-code of first norm value */
/* display color-code of first norm value */
Display_ColorCode(Semi.I_value, Semi.I_scale, TolBand);
Display_ColorCode(Semi.I_value, Semi.I_scale, TolBand);


if (n == 2) /* got two norm values */
if (n == 2) /* got two norm values */
{
{
/* move to next line at same position (after E series) */
/* move to next line at same position (after E series) */
Display_NextLine();
Display_NextLine();
LCD_CharPos(Pos, UI.CharPos_Y);
LCD_CharPos(Pos, UI.CharPos_Y);


/* display color-code of second norm value */
/* display color-code of second norm value */
Display_ColorCode(Semi.C_value, Semi.C_scale, TolBand);
Display_ColorCode(Semi.C_value, Semi.C_scale, TolBand);
}
}
}
}




#if 0
#if 0
/*
/*
* color testing
* color testing
*/
*/


uint16_t Color;
uint16_t Color;


Display_NextLine();
Display_NextLine();


/* first 5 colors plus gold */
/* first 5 colors plus gold */
n = 0;
n = 0;
while (n < 5)
while (n < 5)
{
{
Color = DATA_read_word((uint16_t *)&ColorCode_table[n]);
Color = DATA_read_word((uint16_t *)&ColorCode_table[n]);
LCD_Band(Color, ALIGN_LEFT);
LCD_Band(Color, ALIGN_LEFT);
n++;
n++;
}
}
LCD_Band(COLOR_CODE_GOLD, ALIGN_RIGHT);
LCD_Band(COLOR_CODE_GOLD, ALIGN_RIGHT);


Display_NextLine();
Display_NextLine();


/* last 5 colors plus silver */
/* last 5 colors plus silver */
while (n < 10)
while (n < 10)
{
{
Color = DATA_read_word((uint16_t *)&ColorCode_table[n]);
Color = DATA_read_word((uint16_t *)&ColorCode_table[n]);
LCD_Band(Color, ALIGN_LEFT);
LCD_Band(Color, ALIGN_LEFT);
n++;
n++;
}
}
LCD_Band(COLOR_CODE_SILVER, ALIGN_RIGHT);
LCD_Band(COLOR_CODE_SILVER, ALIGN_RIGHT);


TestKey(0, CURSOR_BLINK);
TestKey(0, CURSOR_BLINK);
#endif
#endif
}
}


#endif
#endif






/*
/*
* show failed test
* show failed test
*/
*/


void Show_Fail(void)
void Show_Fail(void)
{
{
/* display info */
/* display info */
Display_EEString(Failed1_str); /* display: No component */
Display_EEString(Failed1_str); /* display: No component */
Display_NL_EEString(Failed2_str); /* display: found! */
Display_NL_EEString(Failed2_str); /* display: found! */


#if CYCLE_MAX < 255
#if CYCLE_MAX < 255
MissedParts++; /* increase counter */
MissedParts++; /* increase counter */
#endif
#endif
}
}






/*
/*
* show error
* show error
*/
*/


void Show_Error()
void Show_Error()
{
{
if (Check.Type == TYPE_DISCHARGE) /* discharge failed */
if (Check.Type == TYPE_DISCHARGE) /* discharge failed */
{
{
Display_EEString(DischargeFailed_str); /* display: Battery? */
Display_EEString(DischargeFailed_str); /* display: Battery? */


/* display probe number and remaining voltage */
/* display probe number and remaining voltage */
Display_NextLine();
Display_NextLine();
Display_ProbeNumber(Check.Probe);
Display_ProbeNumber(Check.Probe);
Display_Char(':');
Display_Char(':');
Display_Space();
Display_Space();
Display_Value(Check.U, -3, 'V');
Display_Value(Check.U, -3, 'V');
}
}
else if (Check.Type == TYPE_DETECTION) /* detection error */
else if (Check.Type == TYPE_DETECTION) /* detection error */
{
{
/* simply display: No component found! */
/* simply display: No component found! */
Show_Fail();
Show_Fail();
}
}
}
}






/*
/*
* show single (first) resistor
* show single (first) resistor
*
*
* requires:
* requires:
* - ID1: pin ID #1 character
* - ID1: pin ID #1 character
* - ID2: pin ID #2 character
* - ID2: pin ID #2 character
*/
*/


void Show_SingleResistor(uint8_t ID1, uint8_t ID2)
void Show_SingleResistor(uint8_t ID1, uint8_t ID2)
{
{
Resistor_Type *Resistor; /* pointer to resistor */
Resistor_Type *Resistor; /* pointer to resistor */


Resistor = &Resistors[0]; /* pointer to first resistor */
Resistor = &Resistors[0]; /* pointer to first resistor */


/* show pinout */
/* show pinout */
Display_Char(ID1);
Display_Char(ID1);
Display_EEString(Resistor_str);
Display_EEString(Resistor_str);
Display_Char(ID2);
Display_Char(ID2);


/* show resistance value */
/* show resistance value */
Display_Space();
Display_Space();
Display_Value(Resistor->Value, Resistor->Scale, LCD_CHAR_OMEGA);
Display_Value(Resistor->Value, Resistor->Scale, LCD_CHAR_OMEGA);
}
}






/*
/*
* show resistor(s)
* show resistor(s)
*/
*/


void Show_Resistor(void)
void Show_Resistor(void)
{
{
Resistor_Type *R1; /* pointer to resistor #1 */
Resistor_Type *R1; /* pointer to resistor #1 */
Resistor_Type *R2; /* pointer to resistor #2 */
Resistor_Type *R2; /* pointer to resistor #2 */
uint8_t Pin; /* ID of common pin */
uint8_t Pin; /* ID of common pin */


R1 = &Resistors[0]; /* pointer to first resistor */
R1 = &Resistors[0]; /* pointer to first resistor */


if (Check.Resistors == 1) /* single resistor */
if (Check.Resistors == 1) /* single resistor */
{
{
R2 = NULL; /* disable second resistor */
R2 = NULL; /* disable second resistor */
Pin = R1->A; /* make B the first pin */
Pin = R1->A; /* make B the first pin */
}
}
else /* multiple resistors */
else /* multiple resistors */
{
{
R2 = R1;
R2 = R1;
R2++; /* pointer to second resistor */
R2++; /* pointer to second resistor */
#ifdef UI_SERIAL_COMMANDS
#ifdef UI_SERIAL_COMMANDS
/* set data for remote commands */
/* set data for remote commands */
Info.Quantity = 2; /* got two */
Info.Quantity = 2; /* got two */
#endif
#endif


if (Check.Resistors == 3) /* three resistors */
if (Check.Resistors == 3) /* three resistors */
{
{
Resistor_Type *Rmax; /* pointer to largest resistor */
Resistor_Type *Rmax; /* pointer to largest resistor */


/*
/*
* 3 resistors mean 2 single resistors and both resistors in series.
* 3 resistors mean 2 single resistors and both resistors in series.
* So we have to single out that series resistor by finding the
* So we have to single out that series resistor by finding the
* largest resistor.
* largest resistor.
*/
*/


Rmax = R1; /* starting point */
Rmax = R1; /* starting point */
for (Pin = 1; Pin <= 2; Pin++)
for (Pin = 1; Pin <= 2; Pin++)
{
{
if (CmpValue(R2->Value, R2->Scale, Rmax->Value, Rmax->Scale) == 1)
if (CmpValue(R2->Value, R2->Scale, Rmax->Value, Rmax->Scale) == 1)
{
{
Rmax = R2; /* update largest one */
Rmax = R2; /* update largest one */
}
}


R2++; /* next one */
R2++; /* next one */
}
}


/* get the two smaller resistors */
/* get the two smaller resistors */
if (R1 == Rmax) R1++;
if (R1 == Rmax) R1++;
R2 = R1;
R2 = R1;
R2++;
R2++;
if (R2 == Rmax) R2++;
if (R2 == Rmax) R2++;
}
}


/* find common pin of both resistors */
/* find common pin of both resistors */
if ((R1->A == R2->A) || (R1->A == R2->B))
if ((R1->A == R2->A) || (R1->A == R2->B))
{
{
Pin = R1->A; /* pin A */
Pin = R1->A; /* pin A */
}
}
else
else
{
{
Pin = R1->B; /* pin B */
Pin = R1->B; /* pin B */
}
}
}
}


#ifdef UI_SERIAL_COMMANDS
#ifdef UI_SERIAL_COMMANDS
/* set data for remote commands */
/* set data for remote commands */
Info.Comp1 = (void *)R1; /* link first resistor */
Info.Comp1 = (void *)R1; /* link first resistor */
Info.Comp2 = (void *)R2; /* link second resistor */
Info.Comp2 = (void *)R2; /* link second resistor */
#endif
#endif




/*
/*
* display the pins
* display the pins
*/
*/


/* first resistor */
/* first resistor */
if (R1->A != Pin) /* A is not common pin */
if (R1->A != Pin) /* A is not common pin */
{
{
Display_ProbeNumber(R1->A); /* display pin A */
Display_ProbeNumber(R1->A); /* display pin A */
}
}
else /* single resistor or A is common pin */
else /* single resistor or A is common pin */
{
{
Display_ProbeNumber(R1->B); /* display pin B */
Display_ProbeNumber(R1->B); /* display pin B */
}
}


Display_EEString(Resistor_str);
Display_EEString(Resistor_str);
Display_ProbeNumber(Pin); /* display common pin */
Display_ProbeNumber(Pin); /* display common pin */


if (R2) /* second resistor */
if (R2) /* second resistor */
{
{
Display_EEString(Resistor_str);
Display_EEString(Resistor_str);


if (R2->A != Pin) /* A is not common pin */
if (R2->A != Pin) /* A is not common pin */
{
{
Display_ProbeNumber(R2->A); /* display pin A */
Display_ProbeNumber(R2->A); /* display pin A */
}
}
else /* A is common pin */
else /* A is common pin */
{
{
Display_ProbeNumber(R2->B); /* display pin B */
Display_ProbeNumber(R2->B); /* display pin B */
}
}
}
}




/*
/*
* display the values
* display the values
*/
*/


/* first resistor */
/* first resistor */
Display_NextLine();
Display_NextLine();
Display_Value(R1->Value, R1->Scale, LCD_CHAR_OMEGA);
Display_Value(R1->Value, R1->Scale, LCD_CHAR_OMEGA);


if (R2) /* second resistor */
if (R2) /* second resistor */
{
{
Display_Space();
Display_Space();
Display_Value(R2->Value, R2->Scale, LCD_CHAR_OMEGA);
Display_Value(R2->Value, R2->Scale, LCD_CHAR_OMEGA);
}
}
#ifdef SW_INDUCTOR
#ifdef SW_INDUCTOR
else /* single resistor */
else /* single resistor */
{
{
/* get inductance and display if relevant */
/* get inductance and display if relevant */
if (MeasureInductor(R1) == 1) /* inductor */
if (MeasureInductor(R1) == 1) /* inductor */
{
{
Display_Space();
Display_Space();
Display_Value(Inductor.Value, Inductor.Scale, 'H');
Display_Value(Inductor.Value, Inductor.Scale, 'H');


#ifdef UI_SERIAL_COMMANDS
#ifdef UI_SERIAL_COMMANDS
/* set data for remote commands */
/* set data for remote commands */
Info.Flags |= INFO_R_L; /* inductance measured */
Info.Flags |= INFO_R_L; /* inductance measured */
#endif
#endif


#ifdef SW_L_E6_T
#ifdef SW_L_E6_T
/* show E series norm values for E6 20% */
/* show E series norm values for E6 20% */
Show_ENormValues(Inductor.Value, Inductor.Scale, E6, 200, 'H');
Show_ENormValues(Inductor.Value, Inductor.Scale, E6, 200, 'H');
#endif
#endif


#ifdef SW_L_E12_T
#ifdef SW_L_E12_T
/* show E series norm values for E12 10% */
/* show E series norm values for E12 10% */
Show_ENormValues(Inductor.Value, Inductor.Scale, E12, 100, 'H');
Show_ENormValues(Inductor.Value, Inductor.Scale, E12, 100, 'H');
#endif
#endif
}
}
#ifdef SW_R_EXX
#ifdef SW_R_EXX
else /* no inductance */
else /* no inductance */
{
{
#ifdef SW_R_E24_5_T
#ifdef SW_R_E24_5_T
/* show E series norm values for E24 5% */
/* show E series norm values for E24 5% */
Show_ENormValues(R1->Value, R1->Scale, E24, 50, LCD_CHAR_OMEGA);
Show_ENormValues(R1->Value, R1->Scale, E24, 50, LCD_CHAR_OMEGA);
#endif
#endif


#ifdef SW_R_E24_5_CC
#ifdef SW_R_E24_5_CC
/* show E series norm value color-codes for E24 5% */
/* show E series norm value color-codes for E24 5% */
Show_ENormCodes(R1->Value, R1->Scale, E24, 50, COLOR_CODE_GOLD);
Show_ENormCodes(R1->Value, R1->Scale, E24, 50, COLOR_CODE_GOLD);
#endif
#endif


#ifdef SW_R_E24_1_T
#ifdef SW_R_E24_1_T
/* show E series norm values for E24 1% */
/* show E series norm values for E24 1% */
Show_ENormValues(R1->Value, R1->Scale, E24, 10, LCD_CHAR_OMEGA);
Show_ENormValues(R1->Value, R1->Scale, E24, 10, LCD_CHAR_OMEGA);
#endif
#endif


#ifdef SW_R_E24_1_CC
#ifdef SW_R_E24_1_CC
/* show E series norm value color-codes for E24 1% */
/* show E series norm value color-codes for E24 1% */
Show_ENormCodes(R1->Value, R1->Scale, E24, 10, COLOR_CODE_BROWN);
Show_ENormCodes(R1->Value, R1->Scale, E24, 10, COLOR_CODE_BROWN);
#endif
#endif


#ifdef SW_R_E96_T
#ifdef SW_R_E96_T
/* show E series norm values for E96 1% */
/* show E series norm values for E96 1% */
Show_ENormValues(R1->Value, R1->Scale, E96, 10, LCD_CHAR_OMEGA);
Show_ENormValues(R1->Value, R1->Scale, E96, 10, LCD_CHAR_OMEGA);
#endif
#endif


#ifdef SW_R_E96_CC
#ifdef SW_R_E96_CC
/* show E series norm value color-codes for E96 1% */
/* show E series norm value color-codes for E96 1% */
Show_ENormCodes(R1->Value, R1->Scale, E96, 10, COLOR_CODE_BROWN);
Show_ENormCodes(R1->Value, R1->Scale, E96, 10, COLOR_CODE_BROWN);
#endif
#endif
}
}
#endif
#endif
}
}
#elif defined (SW_R_EXX)
#elif defined (SW_R_EXX)
else /* single resistor */
else /* single resistor */
{
{
#ifdef SW_R_E24_5_T
#ifdef SW_R_E24_5_T
/* show E series norm values for E24 5% */
/* show E series norm values for E24 5% */
Show_ENormValues(R1->Value, R1->Scale, E24, 50, LCD_CHAR_OMEGA);
Show_ENormValues(R1->Value, R1->Scale, E24, 50, LCD_CHAR_OMEGA);
#endif
#endif


#ifdef SW_R_E24_5_CC
#ifdef SW_R_E24_5_CC
/* show E series norm value color-codes for E24 5% */
/* show E series norm value color-codes for E24 5% */
Show_ENormCodes(R1->Value, R1->Scale, E24, 50, COLOR_CODE_GOLD);
Show_ENormCodes(R1->Value, R1->Scale, E24, 50, COLOR_CODE_GOLD);
#endif
#endif


#ifdef SW_R_E24_1_T
#ifdef SW_R_E24_1_T
/* show E series norm values for E24 1% */
/* show E series norm values for E24 1% */
Show_ENormValues(R1->Value, R1->Scale, E24, 10, LCD_CHAR_OMEGA);
Show_ENormValues(R1->Value, R1->Scale, E24, 10, LCD_CHAR_OMEGA);
#endif
#endif


#ifdef SW_R_E24_1_CC
#ifdef SW_R_E24_1_CC
/* show E series norm value color-codes for E24 1% */
/* show E series norm value color-codes for E24 1% */
Show_ENormCodes(R1->Value, R1->Scale, E24, 10, COLOR_CODE_BROWN);
Show_ENormCodes(R1->Value, R1->Scale, E24, 10, COLOR_CODE_BROWN);
#endif
#endif


#ifdef SW_R_E96_T
#ifdef SW_R_E96_T
/* show E series norm values for E96 1% */
/* show E series norm values for E96 1% */
Show_ENormValues(R1->Value, R1->Scale, E96, 10, LCD_CHAR_OMEGA);
Show_ENormValues(R1->Value, R1->Scale, E96, 10, LCD_CHAR_OMEGA);
#endif
#endif


#ifdef SW_R_E96_CC
#ifdef SW_R_E96_CC
/* show E series norm value color-codes for E96 1% */
/* show E series norm value color-codes for E96 1% */
Show_ENormCodes(R1->Value, R1->Scale, E96, 10, COLOR_CODE_BROWN);
Show_ENormCodes(R1->Value, R1->Scale, E96, 10, COLOR_CODE_BROWN);
#endif
#endif
}
}
#endif
#endif
}
}




/*
/*
* show capacitor
* show capacitor
*/
*/


void Show_Capacitor(void)
void Show_Capacitor(void)
{
{
Capacitor_Type *MaxCap; /* pointer to largest cap */
Capacitor_Type *MaxCap; /* pointer to largest cap */
Capacitor_Type *Cap; /* pointer to cap */
Capacitor_Type *Cap; /* pointer to cap */
#if defined (SW_ESR) || defined (SW_OLD_ESR)
#if defined (SW_ESR) || defined (SW_OLD_ESR)
uint16_t ESR; /* ESR (in 0.01 Ohms) */
uint16_t ESR; /* ESR (in 0.01 Ohms) */
#endif
#endif
uint8_t Counter; /* loop counter */
uint8_t Counter; /* loop counter */


/* find largest cap */
/* find largest cap */
MaxCap = &Caps[0]; /* pointer to first cap */
MaxCap = &Caps[0]; /* pointer to first cap */
Cap = MaxCap;
Cap = MaxCap;


for (Counter = 1; Counter <= 2; Counter++)
for (Counter = 1; Counter <= 2; Counter++)
{
{
Cap++; /* next cap */
Cap++; /* next cap */


if (CmpValue(Cap->Value, Cap->Scale, MaxCap->Value, MaxCap->Scale) == 1)
if (CmpValue(Cap->Value, Cap->Scale, MaxCap->Value, MaxCap->Scale) == 1)
{
{
MaxCap = Cap;
MaxCap = Cap;
}
}
}
}


#ifdef UI_SERIAL_COMMANDS
#ifdef UI_SERIAL_COMMANDS
/* set data for remote commands */
/* set data for remote commands */
Info.Comp1 = (void *)MaxCap; /* link largest cap */
Info.Comp1 = (void *)MaxCap; /* link largest cap */
#endif
#endif


/* display pinout */
/* display pinout */
Display_ProbeNumber(MaxCap->A); /* display pin #1 */
Display_ProbeNumber(MaxCap->A); /* display pin #1 */
Display_EEString(Cap_str); /* display capacitor symbol */
Display_EEString(Cap_str); /* display capacitor symbol */
Display_ProbeNumber(MaxCap->B); /* display pin #2 */
Display_ProbeNumber(MaxCap->B); /* display pin #2 */


/* show capacitance */
/* show capacitance */
Display_NextLine(); /* move to next line */
Display_NextLine(); /* move to next line */
Display_Value(MaxCap->Value, MaxCap->Scale, 'F');
Display_Value(MaxCap->Value, MaxCap->Scale, 'F');


#if defined (SW_ESR) || defined (SW_OLD_ESR)
#if defined (SW_ESR) || defined (SW_OLD_ESR)
/* show ESR */
/* show ESR */
ESR = MeasureESR(MaxCap); /* measure ESR */
ESR = MeasureESR(MaxCap); /* measure ESR */
if (ESR < UINT16_MAX) /* if successfull */
if (ESR < UINT16_MAX) /* if successfull */
{
{
Display_Space();
Display_Space();
Display_Value(ESR, -2, LCD_CHAR_OMEGA); /* display ESR */
Display_Value(ESR, -2, LCD_CHAR_OMEGA); /* display ESR */
}
}
#ifdef UI_SERIAL_COMMANDS
#ifdef UI_SERIAL_COMMANDS
/* set data for remote commands */
/* set data for remote commands */
Info.Val1 = ESR; /* copy ESR */
Info.Val1 = ESR; /* copy ESR */
#endif
#endif
#endif
#endif


/* show discharge leakage current */
/* show discharge leakage current */
if (MaxCap->I_leak > 0)
if (MaxCap->I_leak > 0)
{
{
Display_NL_EEString_Space(I_leak_str);
Display_NL_EEString_Space(I_leak_str);
Display_Value(MaxCap->I_leak, -8, 'A'); /* in 10nA */
Display_Value(MaxCap->I_leak, -8, 'A'); /* in 10nA */
}
}


#ifdef SW_C_E6_T
#ifdef SW_C_E6_T
/* show E series norm values for E6 20% */
/* show E series norm values for E6 20% */
Show_ENormValues(MaxCap->Value, MaxCap->Scale, E6, 200, 'F');
Show_ENormValues(MaxCap->Value, MaxCap->Scale, E6, 200, 'F');
#endif
#endif


#ifdef SW_C_E12_T
#ifdef SW_C_E12_T
/* show E series norm values for E12 10% */
/* show E series norm values for E12 10% */
Show_ENormValues(MaxCap->Value, MaxCap->Scale, E12, 100, 'F');
Show_ENormValues(MaxCap->Value, MaxCap->Scale, E12, 100, 'F');
#endif
#endif
}
}






/*
/*
* show current (leakage or whatever) of semiconductor
* show current (leakage or whatever) of semiconductor
*
*
* Mapping for Semi structure:
* Mapping for Semi structure:
* - I_value - current
* - I_value - current
* - I_scale - scale for current (10^x)
* - I_scale - scale for current (10^x)
*/
*/


void Show_SemiCurrent(const unsigned char *String)
void Show_SemiCurrent(const unsigned char *String)
{
{
if (CmpValue(Semi.I_value, Semi.I_scale, 50, -9) >= 0) /* show if >=50nA */
if (CmpValue(Semi.I_value, Semi.I_scale, 50, -9) >= 0) /* show if >=50nA */
{
{
Display_NL_EEString_Space(String); /* display: <string> */
Display_NL_EEString_Space(String); /* display: <string> */
Display_Value(Semi.I_value, Semi.I_scale, 'A'); /* display current */
Display_Value(Semi.I_value, Semi.I_scale, 'A'); /* display current */
}
}
}
}






#ifndef UI_SERIAL_COMMANDS
#ifndef UI_SERIAL_COMMANDS


/*
/*
* display capacitance of a diode
* display capacitance of a diode
*
*
* requires:
* requires:
* - pointer to diode structure
* - pointer to diode structure
*/
*/


void Show_Diode_Cap(Diode_Type *Diode)
void Show_Diode_Cap(Diode_Type *Diode)
{
{
/* get capacitance (reversed direction) */
/* get capacitance (reversed direction) */
MeasureCap(Diode->C, Diode->A, 0);
MeasureCap(Diode->C, Diode->A, 0);


/* and show capacitance */
/* and show capacitance */
Display_Value(Caps[0].Value, Caps[0].Scale, 'F');
Display_Value(Caps[0].Value, Caps[0].Scale, 'F');
}
}


#endif
#endif






/*
/*
* show diode
* show diode
*/
*/


void Show_Diode(void)
void Show_Diode(void)
{
{
Diode_Type *D1; /* pointer to diode #1 */
Diode_Type *D1; /* pointer to diode #1 */
Diode_Type *D2 = NULL; /* pointer to diode #2 */
Diode_Type *D2 = NULL; /* pointer to diode #2 */
uint8_t CapFlag = 1; /* flag for capacitance output */
uint8_t CapFlag = 1; /* flag for capacitance output */
uint8_t A = 5; /* ID of common anode */
uint8_t A = 5; /* ID of common anode */
uint8_t C = 5; /* ID of common cothode */
uint8_t C = 5; /* ID of common cothode */
uint8_t R_Pin1 = 5; /* B_E resistor's pin #1 */
uint8_t R_Pin1 = 5; /* B_E resistor's pin #1 */
uint8_t R_Pin2 = 5; /* B_E resistor's pin #2 */
uint8_t R_Pin2 = 5; /* B_E resistor's pin #2 */
uint8_t n; /* counter */
uint8_t n; /* counter */
uint8_t m; /* counter */
uint8_t m; /* counter */


D1 = &Diodes[0]; /* pointer to first diode */
D1 = &Diodes[0]; /* pointer to first diode */


/*
/*
* figure out which diodes to display
* figure out which diodes to display
*/
*/


if (Check.Diodes == 1) /* single diode */
if (Check.Diodes == 1) /* single diode */
{
{
C = D1->C; /* make cathode first pin */
C = D1->C; /* make cathode first pin */
}
}
else if (Check.Diodes == 2) /* two diodes */
else if (Check.Diodes == 2) /* two diodes */
{
{
D2 = D1;
D2 = D1;
D2++; /* pointer to second diode */
D2++; /* pointer to second diode */


if (D1->A == D2->A) /* common anode */
if (D1->A == D2->A) /* common anode */
{
{
A = D1->A; /* save common anode */
A = D1->A; /* save common anode */


/* possible PNP BJT with low value B-E resistor and flyback diode */
/* possible PNP BJT with low value B-E resistor and flyback diode */
R_Pin1 = D1->C;
R_Pin1 = D1->C;
R_Pin2 = D2->C;
R_Pin2 = D2->C;
}
}
else if (D1->C == D2->C) /* common cathode */
else if (D1->C == D2->C) /* common cathode */
{
{
C = D1->C; /* save common cathode */
C = D1->C; /* save common cathode */


/* possible NPN BJT with low value B-E resistor and flyback diode */
/* possible NPN BJT with low value B-E resistor and flyback diode */
R_Pin1 = D1->A;
R_Pin1 = D1->A;
R_Pin2 = D2->A;
R_Pin2 = D2->A;
}
}
else if ((D1->A == D2->C) && (D1->C == D2->A)) /* anti-parallel */
else if ((D1->A == D2->C) && (D1->C == D2->A)) /* anti-parallel */
{
{
A = D1->A; /* anode and cathode */
A = D1->A; /* anode and cathode */
C = A; /* are the same */
C = A; /* are the same */
CapFlag = 0; /* skip capacitance */
CapFlag = 0; /* skip capacitance */
}
}
}
}
else if (Check.Diodes == 3) /* three diodes */
else if (Check.Diodes == 3) /* three diodes */
{
{
/*
/*
* Two diodes in series are detected as a virtual third diode:
* Two diodes in series are detected as a virtual third diode:
* - Check for any possible way the 2 diodes could be connected in series.
* - Check for any possible way the 2 diodes could be connected in series.
* - Only once the cathode of diode #1 matches the anode of diode #2.
* - Only once the cathode of diode #1 matches the anode of diode #2.
*/
*/


for (n = 0; n <= 2; n++) /* loop for first diode */
for (n = 0; n <= 2; n++) /* loop for first diode */
{
{
D1 = &Diodes[n]; /* get pointer of first diode */
D1 = &Diodes[n]; /* get pointer of first diode */


for (m = 0; m <= 2; m++) /* loop for second diode */
for (m = 0; m <= 2; m++) /* loop for second diode */
{
{
D2 = &Diodes[m]; /* get pointer of second diode */
D2 = &Diodes[m]; /* get pointer of second diode */


if (n != m) /* don't check same diode :-) */
if (n != m) /* don't check same diode :-) */
{
{
if (D1->C == D2->A) /* got match */
if (D1->C == D2->A) /* got match */
{
{
n = 5; /* end loops */
n = 5; /* end loops */
m = 5;
m = 5;
}
}
}
}
}
}
}
}


if (n < 5) D2 = NULL; /* no match found */
if (n < 5) D2 = NULL; /* no match found */
C = D1->C; /* cathode of first diode */
C = D1->C; /* cathode of first diode */
A = 3; /* in series mode */
A = 3; /* in series mode */
}
}
else /* too much diodes */
else /* too much diodes */
{
{
Display_EEString(Diode_AC_str); /* display: -|>|- */
Display_EEString(Diode_AC_str); /* display: -|>|- */
Display_Space(); /* display space */
Display_Space(); /* display space */
Display_Char(Check.Diodes + '0'); /* display number of diodes found */
Display_Char(Check.Diodes + '0'); /* display number of diodes found */
#ifdef UI_SERIAL_COMMANDS
#ifdef UI_SERIAL_COMMANDS
/* set data for remote commands */
/* set data for remote commands */
Info.Quantity = Check.Diodes; /* set quantity */
Info.Quantity = Check.Diodes; /* set quantity */
#endif
#endif


return;
return;
}
}


#ifdef UI_SERIAL_COMMANDS
#ifdef UI_SERIAL_COMMANDS
/* set data for remote commands */
/* set data for remote commands */
Info.Comp1 = (void *)D1; /* link first diode */
Info.Comp1 = (void *)D1; /* link first diode */
Info.Comp2 = (void *)D2; /* link second diode */
Info.Comp2 = (void *)D2; /* link second diode */
#endif
#endif




/*
/*
* display pins
* display pins
*/
*/


/* first diode */
/* first diode */
if (A < 3) /* common anode: show C first */
if (A < 3) /* common anode: show C first */
{
{
Display_ProbeNumber(D1->C); /* show C */
Display_ProbeNumber(D1->C); /* show C */
Display_EEString(Diode_CA_str); /* show -|<- */
Display_EEString(Diode_CA_str); /* show -|<- */
Display_ProbeNumber(A); /* show A */
Display_ProbeNumber(A); /* show A */
}
}
else /* common cathode: show A first */
else /* common cathode: show A first */
{
{
Display_ProbeNumber(D1->A); /* show A */
Display_ProbeNumber(D1->A); /* show A */
Display_EEString(Diode_AC_str); /* show ->|- */
Display_EEString(Diode_AC_str); /* show ->|- */
Display_ProbeNumber(C); /* show C */
Display_ProbeNumber(C); /* show C */
}
}


if (D2) /* second diode */
if (D2) /* second diode */
{
{
if (A <= 3) /* common anode or in-series */
if (A <= 3) /* common anode or in-series */
{
{
Display_EEString(Diode_AC_str); /* show ->|- */
Display_EEString(Diode_AC_str); /* show ->|- */
}
}
else /* common cathode */
else /* common cathode */
{
{
Display_EEString(Diode_CA_str); /* show -|<- */
Display_EEString(Diode_CA_str); /* show -|<- */
}
}


if (A == C) /* anti parallel */
if (A == C) /* anti parallel */
{
{
n = D2->A; /* get anode */
n = D2->A; /* get anode */
}
}
else if (A <= 3) /* common anode or in-series */
else if (A <= 3) /* common anode or in-series */
{
{
n = D2->C; /* get cathode */
n = D2->C; /* get cathode */
}
}
else /* common cathode */
else /* common cathode */
{
{
n = D2->A; /* get anode */
n = D2->A; /* get anode */
}
}


Display_ProbeNumber(n); /* display pin */
Display_ProbeNumber(n); /* display pin */


#ifdef UI_SERIAL_COMMANDS
#ifdef UI_SERIAL_COMMANDS
/* set data for remote commands */
/* set data for remote commands */
Info.Quantity = 2; /* got two */
Info.Quantity = 2; /* got two */
#endif
#endif
}
}


/* check for B-E resistor of possible BJT */
/* check for B-E resistor of possible BJT */
if (R_Pin1 < 5) /* possible BJT */
if (R_Pin1 < 5) /* possible BJT */
{
{
/* B-E resistor below 25kOhms */
/* B-E resistor below 25kOhms */
if (CheckSingleResistor(R_Pin1, R_Pin2, 25) == 1)
if (CheckSingleResistor(R_Pin1, R_Pin2, 25) == 1)
{
{
/* show: PNP/NPN? */
/* show: PNP/NPN? */
Display_Space();
Display_Space();
if (A < 3) /* PNP */
if (A < 3) /* PNP */
{
{
Display_EEString(PNP_str);
Display_EEString(PNP_str);
#ifdef UI_SERIAL_COMMANDS
#ifdef UI_SERIAL_COMMANDS
/* set data for remote commands */
/* set data for remote commands */
Info.Flags |= INFO_D_R_BE | INFO_D_BJT_PNP; /* R_BE & PNP */
Info.Flags |= INFO_D_R_BE | INFO_D_BJT_PNP; /* R_BE & PNP */
#endif
#endif
}
}
else /* NPN */
else /* NPN */
{
{
Display_EEString(NPN_str);
Display_EEString(NPN_str);
#ifdef UI_SERIAL_COMMANDS
#ifdef UI_SERIAL_COMMANDS
/* set data for remote commands */
/* set data for remote commands */
Info.Flags |= INFO_D_R_BE | INFO_D_BJT_NPN; /* R_BE & NPN */
Info.Flags |= INFO_D_R_BE | INFO_D_BJT_NPN; /* R_BE & NPN */
#endif
#endif
}
}
Display_Char('?');
Display_Char('?');


Display_NextLine(); /* move to line #2 */
Display_NextLine(); /* move to line #2 */
R_Pin1 += '1'; /* convert pin ID to character */
R_Pin1 += '1'; /* convert pin ID to character */
R_Pin2 += '1';
R_Pin2 += '1';
Show_SingleResistor(R_Pin1, R_Pin2); /* show resistor */
Show_SingleResistor(R_Pin1, R_Pin2); /* show resistor */
CapFlag = 0; /* skip capacitance */
CapFlag = 0; /* skip capacitance */
}
}
}
}




/*
/*
* display:
* display:
* - Uf (forward voltage)
* - Uf (forward voltage)
* - reverse leakage current (for single diodes)
* - reverse leakage current (for single diodes)
* - capacitance (not for anti-parallel diodes)
* - capacitance (not for anti-parallel diodes)
*/
*/


/* display Uf */
/* display Uf */
Display_NL_EEString_Space(Vf_str); /* display: Vf */
Display_NL_EEString_Space(Vf_str); /* display: Vf */


/* first diode */
/* first diode */
Display_Value(D1->V_f, -3, 'V'); /* in mV */
Display_Value(D1->V_f, -3, 'V'); /* in mV */


Display_Space();
Display_Space();


/* display low current Uf and reverse leakage current for a single diode */
/* display low current Uf and reverse leakage current for a single diode */
if (D2 == NULL) /* single diode */
if (D2 == NULL) /* single diode */
{
{
/* display low current Uf if it's quite low (Ge/Schottky diode) */
/* display low current Uf if it's quite low (Ge/Schottky diode) */
if (D1->V_f2 < 250) /* < 250mV */
if (D1->V_f2 < 250) /* < 250mV */
{
{
Display_Char('(');
Display_Char('(');
Display_Value(D1->V_f2, 0, 0); /* no unit */
Display_Value(D1->V_f2, 0, 0); /* no unit */
Display_Char(')');
Display_Char(')');
}
}


/* reverse leakage current */
/* reverse leakage current */
UpdateProbes(D1->C, D1->A, 0); /* reverse diode */
UpdateProbes(D1->C, D1->A, 0); /* reverse diode */
GetLeakageCurrent(1); /* get current */
GetLeakageCurrent(1); /* get current */
Show_SemiCurrent(I_R_str); /* display I_R */
Show_SemiCurrent(I_R_str); /* display I_R */


#ifdef UI_SERIAL_COMMANDS
#ifdef UI_SERIAL_COMMANDS
/* set data for remote commands */
/* set data for remote commands */
Info.Flags |= INFO_D_I_R; /* measured I_R */
Info.Flags |= INFO_D_I_R; /* measured I_R */
#endif
#endif
}
}
else /* two diodes */
else /* two diodes */
{
{
/* show Uf of second diode */
/* show Uf of second diode */
Display_Value(D2->V_f, -3, 'V');
Display_Value(D2->V_f, -3, 'V');
}
}


/* display capacitance */
/* display capacitance */
if (CapFlag == 1) /* if feasable */
if (CapFlag == 1) /* if feasable */
{
{
Display_NL_EEString_Space(DiodeCap_s
Display_NL_EEString_Space(DiodeCap_s