Схема прибора:
Исходный код, в нем нужно изменить строки AdrHi : byte = 12;
litr : array [0..AdrHi] of byte = (0,5,10,15,20,25,30,35,40,45,50,55,60); на AdrHi : byte = 4;
litr : array [0..AdrHi] of byte = (0,40,60,80);
и добавить включение точки в 1 разряде (пока на макетке подкинул точку через резистор на общий провод)
Спойлер
program bakometr;const
stNormal : byte = 1;
stCalibr : byte = 2;
AdrHi : byte = 12;
litr : array [0..AdrHi] of byte = (0,5,10,15,20,25,30,35,40,45,50,55,60);
var
C1 : sbit at porta.5;
C2 : sbit at porta.2;
i,j,cc: byte;
V : word; absolute 0x30;
Vhi : byte; absolute 0x31;
VLo : byte; absolute 0x30;
L10,L1:byte;
dat : array [0..AdrHi] of byte;
mode : byte;
calibrN : byte;
procedure Led(i: byte);
begin
if I=0 then begin
portc:=$04;
porta.4:=0;
end;
if I=1 then begin
portc:=$2D;
porta.4:=1;
end;
if I=2 then begin
portc:=$22;
porta.4:=0;
end;
if I=3 then begin
portc:=$28;
porta.4:=0;
end;
if I=4 then begin
portc:=$09;
porta.4:=1;
end;
if I=5 then begin
portc:=$18;
porta.4:=0;
end;
if I=6 then begin
portc:=$10;
porta.4:=0;
end;
if I=7 then begin
portc:=$0D;
porta.4:=0;
end;
if I=8 then begin
portc:=$00;
porta.4:=0;
end;
if I=9 then begin
portc:=$08;
porta.4:=0;
end;
end;
procedure delay10;
begin
delay_ms(10);
end;
procedure ReadData;
begin
for i := 0 to AdrHi do dat:=EEPROM_Read(i);
end;
begin
porta := %00010000;
trisa := %11001011;
portc := $FF;
trisc := 0;
wpua := 1;
cmcon := $07;
ansel := 2;
adcon0:= 4;
adcon1:= $30;
mode:=stNormal;
ReadData;
ADC_Init;
i:=0;
while true do
begin
inc(I);
if mode = stNormal then
begin
if (i.7) and (V<6) then
begin
C1:=0;
C2:=0;
end;
if i=0 then
begin
V:=ADC_Read(1);
V:=V shr 2;
if V<=dat[AdrHi]
then V:=litr[adrHi]
else begin
if V>=dat[0]
then V:=litr[0]
else begin
for j:=0 to AdrHi-1 do
if (V<=dat[j]) and (V>dat[j+1]) then cc:=j;
if cc=AdrHi
then V:=Litr[AdrHi]
else begin
V:= (dat[cc]-V);
j:=(Litr[cc+1]-Litr[cc]);
V:= V * j;
j:=(dat[cc]-dat[cc+1]);
V:= V / j;
V:= V + litr[cc];
end;
end;
end;
L10:= v div 10;
L1 := V mod 10;
if (porta.0 = 0) then
begin
C1:=1;
C2:=1;
portc:=$3B;
porta.4:=1;
calibrN:=0;
mode:=stCalibr;
delay10;
repeat until porta.0 = 1;
delay10;
end;
end;
end;
if mode = stCalibr then
begin
L10:=litr[calibrN] div 10;
l1:=litr[calibrN] mod 10;
if i>127 then
begin
C1:=0;
C2:=0;
end;
if porta.0 = 0 then
begin
delay10;
repeat until porta.0 = 1;
delay10;
V:=adc_read(1);
V:=V shr 2;
EEPROM_Write(calibrN,VLo);
inc(calibrN);
if calibrN>AdrHi then
begin
mode:= stNormal;
CalibrN:=0;
delay10;
delay10;
delay10;
delay10;
ReadData;
end;
end;
end;
delay_ms(1);
if i.0 then begin
C2 := 0;
Led(L10);
C1 := 1;
end else
begin
C1 := 0;
Led(L1);
C2 := 1;
end;
end;
end.



