27
Laporan Praktikum 1 2012 PERCOBAAN 1 PARALEL PORT INTERFACING I) TUJUAN : Praktikan dapat memahami prinsip dasar dan konfigurasi dari paralel port. Praktikan dapat mengetahui fungsi dan kegunaan dari paralel port. Praktikan dapat menganalisa dan menyimpulkan hasil percobaan tentang fungsi dan kegunaan dari parallel port. II) PERALATAN : Hardware : 1. Modul Komunikasi Paralel. 2. Module LED. 3. Konektor DB 25 Male. Software : 1. Microsoft Visual Studio 2008. 2. Library File = Inpout32.dll (put onto C:\WINDOWS\ system32\). Yudha Handara - 7309040034 Page 1

7309040034_Yudha_Handara praktikum 1

Embed Size (px)

Citation preview

Page 1: 7309040034_Yudha_Handara praktikum 1

Laporan Praktikum 1 2012

PERCOBAAN 1

PARALEL PORT INTERFACING

I) TUJUAN :

Praktikan dapat memahami prinsip dasar dan konfigurasi dari paralel port.

Praktikan dapat mengetahui fungsi dan kegunaan dari paralel port.

Praktikan dapat menganalisa dan menyimpulkan hasil percobaan tentang fungsi dan

kegunaan dari parallel port.

II) PERALATAN :

Hardware :

1. Modul Komunikasi Paralel.

2. Module LED.

3. Konektor DB 25 Male.

Software :

1. Microsoft Visual Studio 2008.

2. Library File = Inpout32.dll (put onto C:\WINDOWS\system32\).

Yudha Handara - 7309040034 Page 1

Page 2: 7309040034_Yudha_Handara praktikum 1

Laporan Praktikum 1 2012

III) PARALEL CONFIGURATION :

IV) LISTING PROGRAM :

1. Percobaan 1 (Program untuk ON/OFF Pada Modul LED )

Program Pada Form :

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;

namespace Led{ public partial class Form1 : Form { public Form1() { InitializeComponent(); }

Yudha Handara - 7309040034 Page 2

Page 3: 7309040034_Yudha_Handara praktikum 1

Laporan Praktikum 1 2012

private void button1_Click(object sender, EventArgs e) { PortAccess.Output(888, 255); }

private void button2_Click(object sender, EventArgs e) { PortAccess.Output(888, 0); }

[STAThread] static void Main() { Application.Run(new Form1()); } }}

Program Pada Port Interop :

using System;using System.Runtime.InteropServices;

public class PortAccess{

[DllImport("inpout32.dll", EntryPoint="Out32")]public static extern void Output(int adress, int value);

}

Tampilan Pada Visual Studio 2008 :

Analisa Percobaan :

Yudha Handara - 7309040034 Page 3

Page 4: 7309040034_Yudha_Handara praktikum 1

Laporan Praktikum 1 2012

Praktikum yang pertama ini yaitu menghubungkan port paralel dengan

modul LED untuk mengontrol ON/OFF yang terdiri dari 8 bit. LED akan

dikontrol dengan tombol ON/OFF yang ada pada C#. Cara kerjanya yaitu

apabila tombol ON ditekan maka lampu LED akan menyala. Untuk

mematikan lampu LED tersebut maka tekan tombol OFF.

2. Percobaan 2 (Binary Led)

Program Pada Form :

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;

namespace Led{ public partial class Form1 : Form { int D=0,d0 = 0, d1 = 0, d2 = 0, d3 = 0, d4 = 0, d5 = 0, d6 = 0, d7 = 0; public Form1() { InitializeComponent(); }

private void button1_Click(object sender, EventArgs e) { PortAccess.Output(888, Convert.ToInt32(txb_data.Text)); }

private void button2_Click(object sender, EventArgs e) {

Yudha Handara - 7309040034 Page 4

Page 5: 7309040034_Yudha_Handara praktikum 1

Laporan Praktikum 1 2012

this.Close(); }

[STAThread] static void Main() { Application.Run(new Form1()); }

private void cb_led1_CheckedChanged(object sender, EventArgs e) { if (cb_led1.Checked) d0 = 1; else d0 = 0; kirim(); }

private void kirim() { D = d0 + d1 + d2 + d3 + d4 + d5 + d6 + d7; PortAccess.Output(888, D); txb_data.Text = D.ToString(); }

private void cb_led2_CheckedChanged(object sender, EventArgs e) { if (cb_led2.Checked) d1 = 2; else d1 = 0; kirim(); }

private void cb_led3_CheckedChanged(object sender, EventArgs e) { if (cb_led3.Checked) d2 = 4; else d2 = 0; kirim(); }

private void cb_led4_CheckedChanged(object sender, EventArgs e) { if (cb_led4.Checked) d3 = 8; else d3 = 0; kirim(); }

private void cb_led5_CheckedChanged(object sender, EventArgs e) {

Yudha Handara - 7309040034 Page 5

Page 6: 7309040034_Yudha_Handara praktikum 1

Laporan Praktikum 1 2012

if (cb_led5.Checked) d4 = 16; else d4 = 0; kirim(); }

private void cb_led6_CheckedChanged(object sender, EventArgs e) { if (cb_led6.Checked) d5 = 32; else d5 = 0; kirim(); }

private void cb_led7_CheckedChanged(object sender, EventArgs e) { if (cb_led7.Checked) d6 = 64; else d6 = 0; kirim(); }

private void cb_led8_CheckedChanged(object sender, EventArgs e) { if (cb_led8.Checked) d7 = 128; else d7 = 0; kirim(); }

private void txb_data_TextChanged(object sender, EventArgs e) {

} }}

Program Pada Port Interop :

using System;using System.Runtime.InteropServices;public class PortAccess{

[DllImport("inpout32.dll", EntryPoint="Out32")]public static extern void Output(int adress, int value);}

Yudha Handara - 7309040034 Page 6

Page 7: 7309040034_Yudha_Handara praktikum 1

Laporan Praktikum 1 2012

Tampilan Pada visual Studio 2008 :

Analisa Percobaan :

Percobaan yang kedua ini masih sama dengan percobaan pertama.

Perbedaannya terdapat pada pengaturan nyala LEDnya yang diatur oleh

tampilan pada microsoft vidual studio 2008 dengan cara mencentang kotak

urutan LED. Tombol SEND untuk mengirim nilai variabel D.

3. Percobaan 3 ()

Program Pada Form :

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;

namespace Led{ public partial class Form1 : Form {

Yudha Handara - 7309040034 Page 7

Page 8: 7309040034_Yudha_Handara praktikum 1

Laporan Praktikum 1 2012

int D=0,d0 = 0, d1 = 0, d2 = 0, d3 = 0, d4 = 0, d5 = 0, d6 = 0, d7 = 0; double data = 0, HB = 0, SB = 0; string Binari; int pjg;

public Form1() { InitializeComponent(); }

private void button1_Click(object sender, EventArgs e) { PortAccess.Output(888, Convert.ToInt32(txb_data.Text)); }

private void button2_Click(object sender, EventArgs e) { this.Close(); }

[STAThread] static void Main() { Application.Run(new Form1()); }

private void cb_led1_CheckedChanged(object sender, EventArgs e) { if (cb_led1.Checked) d0 = 1; else d0 = 0; kirim(); }

private void kirim() { D = d0 + d1 + d2 + d3 + d4 + d5 + d6 + d7; PortAccess.Output(888, D); txb_data.Text = D.ToString(); }

private void cb_led2_CheckedChanged(object sender, EventArgs e) { if (cb_led2.Checked) d1 = 2; else d1 = 0;

Yudha Handara - 7309040034 Page 8

Page 9: 7309040034_Yudha_Handara praktikum 1

Laporan Praktikum 1 2012

kirim(); }

private void cb_led3_CheckedChanged(object sender, EventArgs e) { if (cb_led3.Checked) d2 = 4; else d2 = 0; kirim(); }

private void cb_led4_CheckedChanged(object sender, EventArgs e) { if (cb_led4.Checked) d3 = 8; else d3 = 0; kirim(); }

private void cb_led5_CheckedChanged(object sender, EventArgs e) { if (cb_led5.Checked) d4 = 16; else d4 = 0; kirim(); }

private void cb_led6_CheckedChanged(object sender, EventArgs e) { if (cb_led6.Checked) d5 = 32; else d5 = 0; kirim(); }

private void cb_led7_CheckedChanged(object sender, EventArgs e) { if (cb_led7.Checked) d6 = 64; else d6 = 0; kirim(); }

private void cb_led8_CheckedChanged(object sender, EventArgs e) { if (cb_led8.Checked) d7 = 128; else d7 = 0; kirim(); }

private void Form1_Load(object sender, EventArgs e) { baca();

Yudha Handara - 7309040034 Page 9

Page 10: 7309040034_Yudha_Handara praktikum 1

Laporan Praktikum 1 2012

}

private void btn_baca_Click(object sender, EventArgs e) { }

private void baca() { txb_baca.Text = PortAccess.Input(889).ToString(); data = Convert.ToInt32(txb_baca.Text); Binari = ""; while (data > 0) { HB = Math.Floor(data / 2); SB = data % 2; Binari = SB.ToString() + Binari; data = HB; } label1.Text = Binari; pjg = Binari.Length; if (pjg < 8) Binari = "00000000" + Binari; label2.Text = Binari; }

private void timer1_Tick(object sender, EventArgs e) { baca(); }

private void txb_data_TextChanged(object sender, EventArgs e) {

}

private void txb_baca_TextChanged(object sender, EventArgs e) {

}

}}

Yudha Handara - 7309040034 Page 10

Page 11: 7309040034_Yudha_Handara praktikum 1

Laporan Praktikum 1 2012

Program Pada Interop :

using System;using System.Runtime.InteropServices;

public class PortAccess{

[DllImport("inpout32.dll", EntryPoint="Out32")]public static extern void Output(int adress, int value);

[DllImport("inpout32.dll",EntryPoint="Inp32")] public static extern int Input(int adress);}

Tampilan Pada Visual Studio 2008 :

Analisa Percobaan :

Percobaan ketiga ini hampir sama dengan percobaan kedua yaitu kolom

LED yang terdapat pada tampilan visual studio 2008 akan dicentang dan

kolom tersebut akan menghidupkan LED sesuai dengan kolom yang telah

Yudha Handara - 7309040034 Page 11

Page 12: 7309040034_Yudha_Handara praktikum 1

Laporan Praktikum 1 2012

dicentang, hanya saja pada percobaan ketiga ini terdapat beberapa tambahan

yaitu kolom yang dicentang akan mengirimkan nilai berupa bilangan biner

yang nantinya akan ditampilkan dalam bilangan desimal.

Contoh :

Jika yang dicentang kolom LED 0, 2,dan 3 maka akan menghidupkan LED

sesuai urutan yang dicentang dan juga mengirimkan nilai biner berupa 1101

yang nantinya akan dikonversi ke nilai desimal yang bernilai 13.

4. Percobaan 4 ()

Program Pada Form :

using System.Collections.Generic;using System.Linq;using System.Windows.Forms;

namespace first{ static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } }}

Program Pada Port Interop :

Yudha Handara - 7309040034 Page 12

Page 13: 7309040034_Yudha_Handara praktikum 1

Laporan Praktikum 1 2012

using System;using System.Runtime.InteropServices;

public class PortAccess{

[DllImport("inpout32.dll", EntryPoint="Out32")]public static extern void Output(int adress, int value);

}

Tampilan Pada Visual Studio 2008 :

Analisa Percobaan :

Percobaan keempat yaitu port paralel DB 25 yang dikomunikasikan

dengan modul komunikasi paralel untuk mengontrol relay yang

dikombinasikan dengan timer. Secara otomatis relay akan trip secara

bergantian sesuai dengan setting waktu yang telah diprogram. Dalam

percobaan ini juga terdapat lampu indikator yang berguna untuk mengetahui

bahwa relay tersebut telah bekerja.

Yudha Handara - 7309040034 Page 13

Page 14: 7309040034_Yudha_Handara praktikum 1

Laporan Praktikum 1 2012

5. Percobaan 5 ()

Program Pada Form :

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;

namespace Led{ public partial class Form1 : Form { int D=0,d0 = 0, d1 = 0, d2 = 0, d3 = 0, d4 = 0, d5 = 0, d6 = 0, d7 = 0;

double data = 0, HB = 0, SB = 0; string Binari; int pjg; bool kunci,aktif1=false;

public Form1() { InitializeComponent(); }

private void button1_Click(object sender, EventArgs e) { PortAccess.Output(888, Convert.ToInt32(txb_data.Text)); }

private void button2_Click(object sender, EventArgs e) { this.Close(); }

[STAThread]

Yudha Handara - 7309040034 Page 14

Page 15: 7309040034_Yudha_Handara praktikum 1

Laporan Praktikum 1 2012

static void Main() { Application.Run(new Form1()); }

private void cb_led1_CheckedChanged(object sender, EventArgs e) { if (cb_led1.Checked) d0 = 1; else d0 = 0; kirim(); }

private void kirim() { D = d0 + d1 + d2 + d3 + d4 + d5 + d6 + d7; PortAccess.Output(888, D); txb_data.Text = D.ToString(); }

private void cb_led2_CheckedChanged(object sender, EventArgs e) { if (cb_led2.Checked) d1 = 2; else d1 = 0; kirim(); }

private void cb_led3_CheckedChanged(object sender, EventArgs e) { if (cb_led3.Checked) d2 = 4; else d2 = 0; kirim(); }

private void cb_led4_CheckedChanged(object sender, EventArgs e) { if (cb_led4.Checked) d3 = 8; else d3 = 0; kirim(); }

private void cb_led5_CheckedChanged(object sender, EventArgs e) { if (cb_led5.Checked) d4 = 16; else d4 = 0; kirim(); }

Yudha Handara - 7309040034 Page 15

Page 16: 7309040034_Yudha_Handara praktikum 1

Laporan Praktikum 1 2012

private void cb_led6_CheckedChanged(object sender, EventArgs e) { if (cb_led6.Checked) d5 = 32; else d5 = 0; kirim(); }

private void cb_led7_CheckedChanged(object sender, EventArgs e) { if (cb_led7.Checked) d6 = 64; else d6 = 0; kirim(); }

private void cb_led8_CheckedChanged(object sender, EventArgs e) { if (cb_led8.Checked) d7 = 128; else d7 = 0; kirim(); }

private void btn_baca_Click(object sender, EventArgs e) { baca(); }

private void baca() { txb_baca.Text = PortAccess.Input(889).ToString();

data = Convert.ToInt32(txb_baca.Text); Binari = ""; while (data > 0) { HB = Math.Floor(data / 2); SB = data % 2; Binari = SB.ToString() + Binari; data = HB; } label1.Text = Binari; pjg = Binari.Length; if (pjg < 8) Binari = "00000000" + Binari; label2.Text = Binari;

Yudha Handara - 7309040034 Page 16

Page 17: 7309040034_Yudha_Handara praktikum 1

Laporan Praktikum 1 2012

if (Binari.Substring(Binari.Length - 1, 1) == "1") L1.BackColor = System.Drawing.Color.Lime; else L1.BackColor = System.Drawing.Color.White;

if (Binari.Substring(Binari.Length - 2, 1) == "1") L2.BackColor = System.Drawing.Color.Lime; else L2.BackColor = System.Drawing.Color.White;

if (Binari.Substring(Binari.Length - 3, 1) == "1") L3.BackColor = System.Drawing.Color.Lime; else L3.BackColor = System.Drawing.Color.White;

if (Binari.Substring(Binari.Length - 4, 1) == "1" && aktif1==false) { kunci = !kunci; aktif1 = true; } if (Binari.Substring(Binari.Length - 4, 1) == "0") aktif1 = false;

if (kunci) { L4.BackColor = System.Drawing.Color.Lime; PortAccess.Output(888, 1); } else { L4.BackColor = System.Drawing.Color.White; PortAccess.Output(888, 0); }

if (Binari.Substring(Binari.Length - 5, 1) == "1") L5.BackColor = System.Drawing.Color.Lime; else L5.BackColor = System.Drawing.Color.White;

if (Binari.Substring(Binari.Length - 6, 1) == "1") L6.BackColor = System.Drawing.Color.Lime;

Yudha Handara - 7309040034 Page 17

Page 18: 7309040034_Yudha_Handara praktikum 1

Laporan Praktikum 1 2012

else L6.BackColor = System.Drawing.Color.White;

if (Binari.Substring(Binari.Length - 7, 1) == "1") L7.BackColor = System.Drawing.Color.Lime; else L7.BackColor = System.Drawing.Color.White;

if (Binari.Substring(Binari.Length - 8, 1) == "1") L8.BackColor = System.Drawing.Color.Lime; else L8.BackColor = System.Drawing.Color.White;

}

private void timer1_Tick(object sender, EventArgs e) { baca(); }

private void txb_data_TextChanged(object sender, EventArgs e) {

} }}

Program Pada Port Interop :

using System;using System.Runtime.InteropServices;

public class PortAccess{

[DllImport("inpout32.dll", EntryPoint="Out32")]public static extern void Output(int adress, int value);

[DllImport("inpout32.dll",EntryPoint="Inp32")] public static extern int Input(int adress);}

Yudha Handara - 7309040034 Page 18

Page 19: 7309040034_Yudha_Handara praktikum 1

Laporan Praktikum 1 2012

Tampilan Pada visual Studio 2008 :

Analisa percobaan :

Praktikum yang terakhir ini yaitu memodifikasi program sebelumnya. Pada

program sebelumnya yaitu menampilkan hasil data baca textbox maka pada

percobaan ini output relay yang ditampilkan dengan lampu indikator dan

ditampilkan pada program C# dalam bentuk visual lampu kotak 0-7. Pada

fungsi modifikasi program ini terdapat fungsi toogle sehingga satu inputan

bisa berfungsi toogle yaitu bisa ON dan OFF.

Yudha Handara - 7309040034 Page 19