PENGIRIMAN DATA SECARA SERIAL DARI PC KE MIKROKONTROLLER DENGAN OUTPUT LED (DELPHI)

Pengiriman data secara serial dari PC ke mikrokontroller dengan output LED ( pemrograman delphi )

Pada percobaan ini, data dikirimkan melalui port communication serial PC secara serial dan ditangkap oleh mikrokontroller untuk dioutputkan ke LED

Lakukan beberapa langkah percobaan sebagai berikut:
1. Hubungkan jumper konektor ke LED_EN
2. Hubungkan modul Microcontroller Trainer dengan power supply +5V
3. Hubungkan modul Microcontroller Trainer dengan rangkaian programmer
4. Buka Program M-IDE Studio for MCS-51, sebagai editor dan compiler program
5. Ketik program asembly berikut ini: (download file prog101a.asm)

org 0h nop call initserial gets: call inchar mov P0,a sjmp gets ; 
initserial: mov scon,#52h ; 
Konfigurasi komunikasi serial mode 1 mov tmod,#20h ; 
Baud rate 2400 BPS mov th1,#-13 setb tr1 ret ; 
inchar: detect: jnb ri,detect ; 
Deteksi bit RI apakah data sudah diterima atau belum clr ri mov a,sbuf ret ; 
End

6. Buka Program Delphi
7. Ketik Program Delphi berikut ini, untuk menjalankan komunikasi melalui port serila dengan base address 3F8h. (download file Ledserial.asm)

var Form1: TForm1; data,status:byte; const base = $3f8;
{base address port serial} lcr = 3;
 {line control register} dll = 0; 
{divisor lacht low byte} dlh = 1; 
{divisor lacht high byte} lsr = 5;
 {line status register}
implementation {$R *.DFM}
Procedure Initserial; 
begin asm mov dx,base+lcr; 
{address line control register} mov al,$80 ;
 {10000000b = access bit divisor lacht} out dx,al ;
 mov dx,base+dll; {address divisor lacht low byte} mov al,$30 ; 
{DLLB = 30h} out dx,al ; 
mov dx,base+dlh; {address divisor lacht high byte} mov al,$00 ; 
{DLLH = 00h} out dx,al ; 
{Pada saat ini Port serial} ;
 {memp.baud rate = 2400 bps} mov dx,base+lcr; 
{address line control register} mov al,$03 ; 
{00000011b =} out dx,al ; 
{bit 7=0, access to Rx buffer & Tx ;
 {bit 6=0, set break disable ; 
{bit 5-4-3=000, no parity ; 
{bit 2=0, one stop bit ; 
{bit 1-0=11,data lenght 8 bit} end; 
end;
Procedure Send_Data_Serial; 
begin asm mov dx,base mov al,data out dx,al end end;
 procedure TForm1.FormCreate(Sender: TObject);
 begin Initserial; 
end;
procedure TForm1.Button1Click(Sender: TObject);
begin repeat asm mov dx,base+lsr ; 
{address line status register } in al,dx and al,$20 ; 
{00100000b =not masking bit 5} mov status,al ;
{bit5=Empty Transmitting holding reg} end; 
until status = $20; 
{ If ETHR = 1 then data ready tobe send } data:=1; 
Send_Data_Serial; 
end;
procedure TForm1.Button2Click(Sender: TObject); 
begin repeat asm mov dx,base+lsr ; 
{address line status register } in al,dx and al,$20 ; 
{00100000b =not masking bit 5} mov status,al ;
 {bit5=Empty Transmitting holding reg} end; 
until status = $20; { If ETHR = 1 then data ready tobe send } data:=2; 
Send_Data_Serial; 
end;
procedure TForm1.Button3Click(Sender: TObject); begin repeat asm mov dx,base+lsr ;
{address line status register } in al,dx and al,$20 ; 
{00100000b =not masking bit 5} mov status,al ;
{bit5=Empty Transmitting holding reg} end; 
until status = $20; 
{ If ETHR = 1 then data ready tobe send } data:=4; 
Send_Data_Serial; 
end;
procedure TForm1.Button4Click(Sender: TObject); 
begin repeat asm mov dx,base+lsr ; 
{address line status register } in al,dx and al,$20 ;
{00100000b =not masking bit 5} mov status,al ; 
{bit5=Empty Transmitting holding reg} end;
until status = $20; 
{ If ETHR = 1 then data ready tobe send } data:=8; 
Send_Data_Serial; 
end;
procedure TForm1.Button5Click(Sender: TObject); 
begin repeat asm mov dx,base+lsr ; 
{address line status register } in al,dx and al,$20 ;
{00100000b =not masking bit 5} mov status,al ; 
{bit5=Empty Transmitting holding reg} end; 
until status = $20; 
{ If ETHR = 1 then data ready tobe send } data:=16; 
Send_Data_Serial; 
end;
procedure TForm1.Button6Click(Sender: TObject); 
begin repeat asm mov dx,base+lsr ; 
{address line status register } in al,dx and al,$20 ; 
{00100000b =not masking bit 5} mov status,al ; 
{bit5=Empty Transmitting holding reg} end;
until status = $20; 
{ If ETHR = 1 then data ready tobe send } data:=32; Send_Data_Serial; 
end;
procedure TForm1.Button7Click(Sender: TObject); 
begin repeat asm mov dx,base+lsr ; 
{address line status register } in al,dx and al,$20 ;
{00100000b =not masking bit 5} mov status,al ;
{bit5=Empty Transmitting holding reg} end; 
until status = $20; 
{ If ETHR = 1 then data ready tobe send } data:=64; 
Send_Data_Serial;
end;
procedure TForm1.Button8Click(Sender: TObject); begin repeat asm mov dx,base+lsr ;
{address line status register } in al,dx and al,$20 ; 
{00100000b =not masking bit 5} mov status,al ; 
{bit5=Empty Transmitting holding reg} end; until status = $20; 
{ If ETHR = 1 then data ready tobe send } data:=128; Send_Data_Serial; 
end;
procedure TForm1.Button9Click(Sender: TObject); 
begin repeat asm mov dx,base+lsr ; 
{address line status register } in al,dx and al,$20 ; 
{00100000b =not masking bit 5} mov status,al ; 
{bit5=Empty Transmitting holding reg} end; 
until status = $20;
 { If ETHR = 1 then data ready tobe send } data:=0; Send_Data_Serial; 
end;
procedure TForm1.Button10Click(Sender: TObject); 
begin repeat asm mov dx,base+lsr ; 
{address line status register } in al,dx and al,$20 ; 
{00100000b =not masking bit 5} mov status,al ; 
{bit5=Empty Transmitting holding reg} end; 
until status = $20;
 { If ETHR = 1 then data ready tobe send } data:=255; Send_Data_Serial; 
end;
end.

8. Simpanlah program yang anda ketik dan beri nama : prog101a.asm
9. Pada program MIDE tersebut pilih Build /F9 atau untuk melakukan kompilasi program dari *.asm ke *.hex.
10. Lakukan pemrograman mikrokontroller dengan menggunakan Program ISP Software ( Lihat Petunjuk Penggunaan)
11. Jalankan program delphi dengan menekan tombol F9 atau RUN
12. Lakukan penekanan pada tiap-tiap button dan lakukan pengamatan.

Button
Keadaan LED ( Nyala/ Padam )
1
2
4
8
16
32
64
128
255

2 thoughts on “PENGIRIMAN DATA SECARA SERIAL DARI PC KE MIKROKONTROLLER DENGAN OUTPUT LED (DELPHI)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s