Κώδικας:
#include <avr/io.h>#include <util/delay.h>
#include <avr/sleep.h>
#include <stdlib.h>
#include <string.h>
#include <avr/eeprom.h>
#include <avr/pgmspace.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>
#include <math.h>
#include <stdint.h>
#include <avr/power.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // RS,E,D4,D5,D6,D7
// ******** config options for your Semiconductor tester
// Every changing of this Makefile will result in new compiling the whole
// programs, if you call make or make upload.
#define MCU atmega328p
#define F_CPU 16000000UL
// Select your language:
// Available languages are: LANG_ENGLISH, LANG_GERMAN, LANG_POLISH, LANG_CZECH, LANG_SLOVAK, LANG_SLOVENE,
// LANG_DUTCH, LANG_BRASIL, LANG_RUSSIAN, LANG_UKRAINIAN
#define LANG_ENGLISH
// The LCD_CYRILLIC option is necessary, if you have a display with cyrillic characterset.
// This lcd-display don't have a character for Ohm and for u (micro).
// Russian language requires a LCD controller with russian characterset and option LCD_CYRILLIC!
//#define LCD_CYRILLIC
// The LCD_DOGM option must be set for support of the DOG-M type of LCD modules with ST7036 controller.
// For this LCD type the contrast must be set with software command.
//#define LCD_DOGM
// Option STRIP_GRID_BOARD selects different board-layout, do not set for standard board!
// The connection of LCD is totally different for both versions.
//#define STRIP_GRID_BOARD
// The WITH_SELFTEST option enables selftest function (only for mega168 or mega328).
// #define WITH_SELFTEST
// AUTO_CAL will enable the autocalibration of zero offset of capacity measurement and
// also the port output resistance values will be find out in SELFTEST section.
// With a external capacitor a additionally correction of reference voltage is figured out for
// low capacity measurement and also for the AUTOSCALE_ADC measurement.
// The AUTO_CAL option is only selectable for mega168 and mega328.
#define AUTO_CAL
// FREQUENCY_50HZ enables a 50 Hz frequency generator for up to one minute at the end of selftests.
//#define FREQUENCY_50HZ
// The WITH_AUTO_REF option enables reading of internal REF-voltage to get factors for the Capacity measuring.
#define WITH_AUTO_REF
// REF_C_KORR corrects the reference Voltage for capacity measurement (<40uF) and has mV units.
// Greater values gives lower capacity results.
#define REF_C_KORR 12
// REF_L_KORR corrects the reference Voltage for inductance measurement and has mV units.
#define REF_L_KORR 40
// C_H_KORR defines a correction of 0.1% units for big capacitor measurement.
// Positive values will reduce measurement results.
#define C_H_KORR 0
// The WITH_UART option enables the software UART (TTL level output at Pin PC3, 26).
// If the option is deselected, PC3 can be used as external voltage input with a
// 10:1 resistor divider.
//#define WITH_UART
// The CAP_EMPTY_LEVEL defines the empty voltage level for capacitors in mV.
// Choose a higher value, if your Tester reports "Cell!" by unloading capacitors.
#define CAP_EMPTY_LEVEL 4
// The AUTOSCALE_ADC option enables the autoscale ADC (ADC use VCC and Bandgap Ref).
#define AUTOSCALE_ADC
#define REF_R_KORR 3
// The ESR_ZERO value define the zero value of ESR measurement (units = 0.01 Ohm).
//#define ESR_ZERO 29
#define ESR_ZERO 20
// NO_AREF_CAP tells your Software, that you have no Capacitor installed at pin AREF (21).
// This enables a shorter wait-time for AUTOSCALE_ADC function.
// A capacitor with 1nF can be used with the option NO_AREF_CAP set.
#define NO_AREF_CAP
// The OP_MHZ option tells the software the Operating Frequency of your ATmega.
// OP_MHZ 16
// Restart from sleep mode will be delayed for 16384 clock tics with crystal mode.
// Operation with the internal RC-Generator or external clock will delay the restart by only 6 clock tics.
// You must specify this with "#define RESTART_DELAY_TICS=6", if you don't use the crystal mode.
//#define RESTART_DELAY_TICS 6
// The USE_EEPROM option specify where you wish to locate fix text and tables.
// If USE_EEPROM is unset, program memory (flash) is taken for fix text and tables.
//#define USE_EEPROM
// Setting EBC_STYPE will select the old style to present the order of Transistor connection (EBC=...).
// Omitting the option will select the 123=... style. Every point is replaced by a character identifying
// type of connected transistor pin (B=Base, E=Emitter, C=Collector, G=Gate, S=Source, D=Drain).
// If you select EBC_STYLE=321 , the style will be 321=... , the inverted order to the 123=... style.
//#define EBC_STYLE
//#define EBC_STYLE 321
// Setting of NO_NANO avoids the use of n as prefix for Farad (nF), the mikro prefix is used insted (uF).
//#define NO_NANO
// The PULLUP_DISABLE option disable the pull-up Resistors of IO-Ports.
// To use this option a external pull-up Resistor (10k to 30k)
// from Pin 13 to VCC must be installed!
#define PULLUP_DISABLE
// The ANZ_MESS option specifies, how often an ADC value is read and accumulated.
// Possible values of ANZ_MESS are 5 to 200.
#define ANZ_MESS 25
// The POWER_OFF option enables the power off function, otherwise loop measurements infinitely
// until power is disconnected with a ON/OFF switch (#define POWER_OFF).
// If you have the tester without the power off transistors, you can deselect POWER_OFF .
// If you have NOT selected the POWER_OFF option with the transistors installed,
// you can stop measuring by holding the key several seconds after a result is
// displayed. After releasing the key, the tester will be shut off by timeout.
// Otherwise you can also specify, after how many measurements without found part
// the tester will shut down (#define POWER_OFF=5).
// The tester will also shut down with found part,
// but successfull measurements are allowed double of the specified number.
// You can specify up to 255 empty measurements (#define POWER_OFF=255).
//#define POWER_OFF 5
//#define POWER_OFF
// Option BAT_CHECK enables the Battery Voltage Check, otherwise the SW Version is displayed instead of Bat.
// BAT_CHECK should be set for battery powered tester version.
//#define BAT_CHECK
// The BAT_OUT option enables Battery Voltage Output on LCD (if BAT_CHECK is selected).
// If your 9V supply has a diode installed, use the BAT_OUT=600 form to specify the
// threshold voltage of your diode to adjust the output value.
// This threshold level is added to LCD-output and does not affect the voltage checking levels.
//#define BAT_OUT 150
// To adjust the warning-level and poor-level of battery check to the capability of a
// low drop voltage regulator, you can specify the Option BAT_POOR=5400 .
// The unit for this option value is 1mV , 5400 means a poor level of 5.4V.
// The warning level is 0.8V higher than the specified poor level (>5.3V).
// The warning level is 0.4V higher than the specified poor level (>2.9V, <=5.3V).
// The warning level is 0.2V higher than the specified poor level (>1.3V, <=2.9V).
// The warning level is 0.1V higher than the specified poor level (<=1.3V).
// Setting the poor level to low values is not recommended for rechargeable Batteries,
// because this increase the danger for deep discharge!!
// #define BAT_POOR 6400
// The sleep mode of the ATmega168 or ATmega328 is normally used by the software to save current.
// You can inhibit this with the option INHIBIT_SLEEP_MODE .
//#define INHIBIT_SLEEP_MODE
// ******** end of selectable options
/* -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- */
// ######## Configuration
#ifndef ADC_PORT
//#define DebugOut 3 // if set, output of voltages of resistor measurements in row 2,3,4
//#define DebugOut 4 // if set, output of voltages of Diode measurement in row 3+4
//#define DebugOut 5 // if set, output of Transistor checks in row 2+3
//#define DebugOut 10 // if set, output of capacity measurements (ReadCapacity) in row 3+4
/*
Port, that is directly connected to the probes.
This Port must have an ADC-Input (ATmega8: PORTC).
The lower pins of this Port must be used for measurements.
Please don't change the definitions of TP1, TP2 and TP3!
The TPREF pin can be connected with a 2.5V precision voltage reference
The TPext can be used with a 10:1 resistor divider as external voltage probe up to 50V
*/
#define ADC_PORT PORTC
#define ADC_DDR DDRC
#define ADC_PIN PINC
#define TP1 0
#define TP2 1
#define TP3 2
#define TPext 3
// Port pin for 2.5V precision reference used for VCC check (optional)
#define TPREF 4
// Port pin for Battery voltage measuring
#define TPBAT 5
/*
exact values of used resistors (Ohm).
The standard value for R_L is 680 Ohm, for R_H 480kOhm.
To calibrate your tester the resistor-values can be adjusted:
*/
#define R_L_VAL 6810 // standard value 680 Ohm, multiplied by 10 for 0.1 Ohm resolution εδω απο 6800 σε 6810
//#define R_L_VAL 6690 // this will be define a 669 Ohm
//#define R_H_VAL 48000 // standard value 480000 Ohm, multiplied by 10, divided by 100
#define R_H_VAL 47900 // this will be define a 479000 Ohm, divided by 100 εδώ πχ από 470κ σε 479κ
#define R_DDR DDRB
#define R_PORT PORTB
/*
Port for the Test resistors
The Resistors must be connected to the lower 6 Pins of the Port in following sequence:
RLx = 680R-resistor for Test-Pin x
RHx = 480k-resistor for Test-Pin x
RL1 an Pin 0
RH1 an Pin 1
RL2 an Pin 2
RH2 an Pin 3
RL3 an Pin 4
RH3 an Pin 5
*/
#define ON_DDR DDRD
#define ON_PORT PORTD
#define ON_PIN_REG PIND
#define ON_PIN 18 // Pin, must be switched to high to switch power on
#ifdef STRIP_GRID_BOARD
// Strip Grid board version
#define RST_PIN 0 // Pin, is switched to low, if push button is pressed
#else
// normal layout version
#define RST_PIN 17 // Pin, is switched to low, if push button is pressed
#endif
// Port(s) / Pins for LCD
#ifdef STRIP_GRID_BOARD
// special Layout for strip grid board
#define HW_LCD_EN_PORT PORTD
#define HW_LCD_EN_PIN 5
#define HW_LCD_RS_PORT PORTD
#define HW_LCD_RS_PIN 7
#define HW_LCD_B4_PORT PORTD
#define HW_LCD_B4_PIN 4
#define HW_LCD_B5_PORT PORTD
#define HW_LCD_B5_PIN 3
#define HW_LCD_B6_PORT PORTD
#define HW_LCD_B6_PIN 2
#define HW_LCD_B7_PORT PORTD
#define HW_LCD_B7_PIN 1
#else
// normal Layout
#define HW_LCD_EN_PORT PORTD
#define HW_LCD_EN_PIN 6
#define HW_LCD_RS_PORT PORTD
#define HW_LCD_RS_PIN 7
#define HW_LCD_B4_PORT PORTD
#define HW_LCD_B4_PIN 5
#define HW_LCD_B5_PORT PORTD
#define HW_LCD_B5_PIN 4
#define HW_LCD_B6_PORT PORTD
#define HW_LCD_B6_PIN 3
#define HW_LCD_B7_PORT PORTD
#define HW_LCD_B7_PIN 2
#endif
// U_VCC defines the VCC Voltage of the ATmega in mV units
#define U_VCC 5000
// integer factors are used to change the ADC-value to mV resolution in ReadADC !
// With the option NO_CAP_HOLD_TIME you specify, that capacitor loaded with 680 Ohm resistor will not
// be tested to hold the voltage same time as load time.
// Otherwise (without this option) the voltage drop during load time is compensated to avoid displaying
// too much capacity for capacitors with internal parallel resistance.
// #define NO_CAP_HOLD_TIME
// U_SCALE can be set to 4 for better resolution of ReadADC function for resistor measurement
#define U_SCALE 4
// R_ANZ_MESS can be set to a higher number of measurements (up to 200) for resistor measurement
#define R_ANZ_MESS 190
// Watchdog
//#define WDT_enabled
/*
If you remove the "#define WDT_enabled" , the Watchdog will not be activated.
This is only for Test or debugging usefull.
For normal operation please activate the Watchdog !
*/
// ######## End of configuration
Τον έχω πειράξει σε κάποια σημεία που έχει να κάνει με την τιμή των αντιστάσεων , πάντα με επιφύλαξη για το πόσο ειναι σωστο αυτο που έκανα επίσης έκανα και κάποιες αλλαγες στο κύκλωμα