Translate

Monitoring Tegangan Menggunakan Mikrokontroller Bascom AVR Dengan Interface Delphi 7

Monitoring Tegangan Menggunakan Mikrokontroller Bascom AVR Dengan Interface Delphi 7


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat interface menggunakan Delphi 7 dengan alat pengirimnya adalah mikrokontroller dan bahasa Bascom AVR, prinsip kerjanya sangat sederhana yaitu mikrokontroller mengirimkan dua data ke komputer kemudian pada interface ditampilkan grafik menggunakan software Delphi 7. jadi mikrokontroller mengirimkan data berupa data adc, yang berjumlah 2 buah yaitu adc A dan adc B. kemudian didalam delphi ada dua buah program yaitu menampilkan kedua data tersebut kedalam satu grafik dan yang kedua yaitu menampilkan kedua data tersebut ke grafik yang terpisah atau sendiri-sendiri. yang harus diperhatikan yaitu pertama install dulu comport untuk delphinya, disini saya menggunakan cport 3.10. untuk lebih jelasnya berikut program dan skemanya.



a. Minimum System




b. Rangkaian RS232




c. Program Bascom AVR

$regfile = "m16def.dat"
$crystal = 11059200

Config Adc = Single , Prescaler = Auto , Reference = Avcc

Dim Dataadc1 As Word
Dim Dataadc2 As Word

Cls
Cursor Off

Start Adc

Do

Dataadc1 = Getadc(0)
Dataadc2 = Getadc(1)

Print Dataadc1 ; "a"
Print Dataadc2 ; "b"

Waitms 50

Loop
'------------------------ end



d. Program Interface Grafik Delphi 7 ( Satu Grafik isi 2 Data )


unit TA;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls,strutils, TeeProcs, TeEngine, Chart, CPort, mmsystem,
  Series, Buttons;

type
  TForm1 = class(TForm)
    ComPort1: TComPort;
    GroupBox1: TGroupBox;
    Edit1: TEdit;
    Edit2: TEdit;
    Chart1: TChart;
    Shape1: TShape;
    Shape2: TShape;
    GroupBox2: TGroupBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Memo1: TMemo;
    Label1: TLabel;
    Label2: TLabel;
    Timer1: TTimer;
    Label7: TLabel;
    Label8: TLabel;
    GroupBox4: TGroupBox;
    Edit3: TEdit;
    Edit4: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    BitBtn1: TBitBtn;
    Series1: TFastLineSeries;
    Series2: TFastLineSeries;
    procedure ComPort1RxChar(Sender: TObject; Count: Integer);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Memo1Change(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ComPort1RxChar(Sender: TObject; Count: Integer);
var buff:string;
begin
comport1.ReadStr(buff,count);
memo1.Text:=memo1.Text+buff;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
comport1.ShowSetupDialog;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if button2.Caption='Connect' then
   begin
   button2.Caption:='Disconnect';
   comport1.Open;
   end
else if button2.Caption='Disconnect' then
   begin
   button2.Caption:='Connect';
   comport1.Close;
   end;

end;

procedure TForm1.Button3Click(Sender: TObject);
begin
Edit1.Color:=clwhite;
Edit2.Color:=clwhite;
edit1.text:='';
edit2.text:='';
memo1.Text:='';
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
close;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
ThousandSeparator:=',';
DecimalSeparator:='.';
end;

procedure TForm1.Memo1Change(Sender: TObject);
var ruang,kulit:double;
    rin,kin:string;
    jumlahdata:integer;

begin
  shape1.Brush.Color:=clgreen;
  shape2.Brush.Color:=clgreen;
  jumlahdata:=chart1.GetMaxValuesCount;
  form1.Caption:=inttostr(jumlahdata);
  if jumlahdata =10000 then
     begin
     chart1.Series[0].Clear;
     chart1.Series[1].Clear;
     end;

  rin:=memo1.Lines[memo1.Lines.count-2];
  kin:=memo1.Lines[memo1.Lines.count-1];

  if rightstr(rin,1)= 'a' then
     begin
     edit1.Text:=leftstr(rin,length(rin)-1);
     ruang:=strtofloat(edit1.text);
     chart1.Series[0].Add(ruang,'',clred) ;
     shape1.Brush.Color:=clred;
     end;
  if rightstr(kin,1)='b' then
     begin
     edit2.Text:=leftstr(kin,length(kin)-1);
     kulit:=strtofloat(edit2.text);
     chart1.Series[1].Add(kulit,'',clgreen) ;
     shape2.Brush.Color:=clred;
     end;


end;


procedure TForm1.Edit1Change(Sender: TObject);
var ruang:double;
begin
ruang:=strtofloat(edit1.text);
if ruang<30 then
   begin
   edit1.Color:=clblue;
   edit3.text:= 'Lembab';
   end;
if ruang>31 then
   begin
   edit1.Color:=clred;
   edit3.text:= 'Kering';
   end;
if (ruang>=31) and (ruang<=30) then
   begin
   edit1.Color:=clwhite;
   edit3.text:= 'Normal';
   end;
end;


procedure TForm1.Edit2Change(Sender: TObject);
var kulit:double;
begin
kulit:=strtofloat(edit2.text);
if kulit<60 then
   begin
   edit2.Color:=clblue;
   edit4.text:= 'Kering';
   end;
if kulit>61 then
   begin
   edit2.Color:=clred;
   edit4.text:= 'Lembab';
   end;
if (kulit>=61) and (kulit<=60) then
   begin
   edit2.Color:=clwhite;
   edit4.text:= 'Normal';
   end;
end;



procedure TForm1.Timer1Timer(Sender: TObject);
begin
label7.Caption:='Date  '+ FormatdateTime('d/mm/yyyy',Date);
label8.Caption:='Time  '+ FormatDateTime('hh:nn:ss',Time);
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
close;
end;

end.




e. Program Interface Grafik Delphi 7 ( Dua Grafik isi 2 Data )


 unit TA;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls,strutils, TeeProcs, TeEngine, Chart, CPort, mmsystem,
  Series, Buttons;

type
  TForm1 = class(TForm)
    ComPort1: TComPort;
    GroupBox1: TGroupBox;
    Edit1: TEdit;
    Edit2: TEdit;
    Chart1: TChart;
    Shape1: TShape;
    Shape2: TShape;
    GroupBox2: TGroupBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Memo1: TMemo;
    Label1: TLabel;
    Label2: TLabel;
    Timer1: TTimer;
    Label7: TLabel;
    Label8: TLabel;
    GroupBox4: TGroupBox;
    Edit3: TEdit;
    Edit4: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    BitBtn1: TBitBtn;
    Chart2: TChart;
    Series1: TFastLineSeries;
    Series2: TFastLineSeries;
    procedure ComPort1RxChar(Sender: TObject; Count: Integer);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Memo1Change(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ComPort1RxChar(Sender: TObject; Count: Integer);
var buff:string;
begin
comport1.ReadStr(buff,count);
memo1.Text:=memo1.Text+buff;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
comport1.ShowSetupDialog;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if button2.Caption='Connect' then
   begin
   button2.Caption:='Disconnect';
   comport1.Open;
   end
else if button2.Caption='Disconnect' then
   begin
   button2.Caption:='Connect';
   comport1.Close;
   end;

end;

procedure TForm1.Button3Click(Sender: TObject);
begin
Edit1.Color:=clwhite;
Edit2.Color:=clwhite;
edit1.text:='';
edit2.text:='';
memo1.Text:='';
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
close;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
ThousandSeparator:=',';
DecimalSeparator:='.';
end;

procedure TForm1.Memo1Change(Sender: TObject);
var ruang,kulit:double;
    rin,kin:string;
    jumlahdata:integer;

begin
  shape1.Brush.Color:=clgreen;
  shape2.Brush.Color:=clgreen;
  jumlahdata:=chart1.GetMaxValuesCount;
  form1.Caption:=inttostr(jumlahdata);
  if jumlahdata =10000 then
     begin
     Series1.Clear;
     Series2.Clear;
     end;

  rin:=memo1.Lines[memo1.Lines.count-2];
  kin:=memo1.Lines[memo1.Lines.count-1];

  if rightstr(rin,1)= 'a' then
     begin
     edit1.Text:=leftstr(rin,length(rin)-1);
     ruang:=strtofloat(edit1.text);
     Series1.Add(ruang,'',clred) ;
     shape1.Brush.Color:=clred;
     end;
  if rightstr(kin,1)='b' then
     begin
     edit2.Text:=leftstr(kin,length(kin)-1);
     kulit:=strtofloat(edit2.text);
     Series2.Add(kulit,'',clgreen) ;
     shape2.Brush.Color:=clred;
     end;


end;


procedure TForm1.Edit1Change(Sender: TObject);
var ruang:double;
begin
ruang:=strtofloat(edit1.text);
if ruang<30 then
   begin
   edit1.Color:=clblue;
   edit3.text:= 'Lembab';
   end;
if ruang>31 then
   begin
   edit1.Color:=clred;
   edit3.text:= 'Kering';
   end;
if (ruang>=31) and (ruang<=30) then
   begin
   edit1.Color:=clwhite;
   edit3.text:= 'Normal';
   end;
end;


procedure TForm1.Edit2Change(Sender: TObject);
var kulit:double;
begin
kulit:=strtofloat(edit2.text);
if kulit<60 then
   begin
   edit2.Color:=clblue;
   edit4.text:= 'Kering';
   end;
if kulit>61 then
   begin
   edit2.Color:=clred;
   edit4.text:= 'Lembab';
   end;
if (kulit>=61) and (kulit<=60) then
   begin
   edit2.Color:=clwhite;
   edit4.text:= 'Normal';
   end;
end;



procedure TForm1.Timer1Timer(Sender: TObject);
begin
label7.Caption:='Date  '+ FormatdateTime('d/mm/yyyy',Date);
label8.Caption:='Time  '+ FormatDateTime('hh:nn:ss',Time);
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
close;
end;

end.




f. VIDEO HASILNYA













No comments:

Post a Comment