Rancang Bangun Sistem Pendeteksi Banjir Pada Daerah Aliran Sungai dengan Menggunakan SCADA (Supervisory Control And Acquisition) Berbasis Mikrokontroler AT89S51

Teks penuh

(1)
(2)

Listing Program 1. Menu Utama

Private Sub mn_adata_Click() frm_display_data.Show Me.Hide

End Sub

Private Sub mn_koneksiport_Click() frm_koneksi.Show

Me.Hide End Sub

Private Sub mn_tentang_Click() frm_tentang.Show

Me.Hide End Sub

Private Sub mn_keluar_Click() End

End Sub

2. Aquisisi Sub Aktifdg_data() With dg_data .Cols = 4

(3)

.Col = 0 .Row = 0

.Text = "Tanggal" .CellFontBold = True .ColWidth(0) = 1200

.AllowUserResizing = flexResizeColumns .CellAlignment = flexAlignCenterCenter .Col = 1

.Row = 0

.Text = "Waktu" .CellFontBold = True .ColWidth(1) = 1200

.AllowUserResizing = flexResizeColumns .CellAlignment = flexAlignCenterCenter .Col = 2

.Row = 0

.Text = "Ketinggian" .CellFontBold = True .ColWidth(2) = 2000

.AllowUserResizing = flexResizeColumns .CellAlignment = flexAlignCenterCenter .Col = 3

(4)

.AllowUserResizing = flexResizeColumns .CellAlignment = flexAlignCenterCenter End With

End Sub

Sub tampil_data() Dim Baris As Integer dg_data.Clear

Call Aktifdg_data dg_data.Rows = 2 Baris = 0

Set Rs_data = New ADODB.Recordset

Rs_data.Open "SELECT * FROM tbl_status ORDER BY id DESC", KonekDb, adOpenDynamic, adLockOptimistic

If Rs_data.PageCount > 0 Then With Rs_data

.MoveFirst

Do While Not .EOF On Error Resume Next Baris = Baris + 1

dg_data.Rows = Baris + 1 dg_data.ColAlignment(0) = 4 dg_data.ColAlignment(1) = 4 dg_data.ColAlignment(2) = 4 dg_data.ColAlignment(3) = 4

(5)

dg_data.TextMatrix(Baris, 1) = !waktu dg_data.TextMatrix(Baris, 2) = !ketinggian dg_data.TextMatrix(Baris, 3) = !Status .MoveNext

Loop End With End If End Sub

Private Sub Form_Load() Label4.Caption = "0" If Koneksi = "" Then

MsgBox "Port Belum Terhubung" Label9.Caption = "-"

Label9.Alignment = vbCenter Label4.Caption = "-"

Label4.Alignment = vbCenter

End If

Call BukaDatabase Call tampil_data

MSComm2.CommPort = Port

MSComm2.Settings = Bound_Rate + "N,8,1" MSComm2.PortOpen = True

(6)

Private Sub Form_Unload(Cancel As Integer) MSComm2.PortOpen = False

frm_utama.Show Me.Hide

End Sub

Private Sub Timer1_Timer()

Label2.Caption = Format(Date, "dd-mm-yyyy") Label3.Caption = Format(Time, "hh:mm:ss") End Sub

Private Sub Timer2_Timer() Dim tinggi As String Dim strwaktu As String Dim strtanggal As String strtanggal = Label2.Caption strwaktu = Label3.Caption SQLsimpan = ""

SQLsimpan = "INSERT INTO tbl_status (tanggal, waktu, ketinggian, status)" _ & " VALUES('" & strtanggal & "','" & strwaktu & "','" _

& Label4.Caption & "', '" & Label9.Caption & "')" KonekDb.Execute SQLsimpan, , adCmdText

Call tampil_data End Sub

(7)

If Koneksi = "Terhubung" Then

If MSComm2.CommEvent = comEvReceive Then tinggi = ""

tinggi = MSComm2.Input tinggi = 200 - Int(tinggi) If Int(tinggi) <= 0 Then Label4.Caption = "-"

Label4.Alignment = vbCenter Else

Label4.Caption = tinggi End If

If Int(tinggi) > 195 And Int(tinggi) <= 200 Then Label9.Caption = "Banjir"

ElseIf Int(tinggi) > 188 And Int(tinggi) <= 195 Then Label9.Caption = "Awas"

ElseIf Int(tinggi) > 181 And Int(tinggi) <= 188 Then Label9.Caption = "Aman"

ElseIf Int(tinggi) > 177 And Int(tinggi) <= 181 Then Label9.Caption = "Normal"

Else

Label9.Caption = "-"

Label9.Alignment = vbCenter End If

(8)

3. Koneksi port

Private Sub cmdConnect_Click() On Error GoTo errcode

Select Case cbo_port.ListIndex Case -1

(9)

If MSComm1.PortOpen = False Then MSComm1.CommPort = Port MSComm1.RThreshold = 1

MSComm1.Settings = cbo_boundrate.List(cbo_boundrate.ListIndex) & ",N,8,1" MSComm1.PortOpen = True

Bound_Rate = cbo_boundrate.Text Koneksi = "Terhubung"

Text1.Text = "Status : " & vbNewLine & vbNewLine & "Terhubung" cmdConnect.Enabled = False

cmdDisconnect.Enabled = True End If

Exit Sub

errcode:

Text1.Text = "Status : " & vbNewLine & vbNewLine & "Port Salah" cbo_port.SetFocus

End Sub

Private Sub cmdDisconnect_Click() If MSComm1.PortOpen = True Then MSComm1.PortOpen = False cmdConnect.Enabled = True cmdDisconnect.Enabled = False Koneksi = ""

Text1.Text = "Status : " & vbNewLine & vbNewLine & "Port Terputus" End If

(10)

Private Sub Command1_Click() Unload Me

End Sub

Private Sub Form_Load() cbo_port.AddItem "COMM1" cbo_port.AddItem "COMM2" cbo_port.AddItem "COMM3" cbo_port.AddItem "COMM4" cbo_port.AddItem "COMM5" cbo_port.AddItem "COMM6" cbo_port.AddItem "COMM7" cbo_port.AddItem "COMM8" cbo_port.AddItem "COMM9" cbo_port.ListIndex = 0

With cbo_boundrate .AddItem "2400" .AddItem "4800" .AddItem "9600" .AddItem "19200" .AddItem "38400" .AddItem "58600" End With

If Koneksi = "Terhubung" Then Select Case Port

(11)

cbo_port.ListIndex = 0 Case 2

cbo_port.ListIndex = 1 Case 3

cbo_port.ListIndex = 2 Case 4

cbo_port.ListIndex = 3 Case 5

cbo_port.ListIndex = 4 Case 6

cbo_port.ListIndex = 5 Case 7

cbo_port.ListIndex = 6 Case 8

cbo_port.ListIndex = 7 Case 9

cbo_port.ListIndex = 8 End Select

cbo_boundrate.Text = Bound_Rate MSComm1.CommPort = Port

MSComm1.Settings = Bound_Rate + "N,8,1" MSComm1.PortOpen = True

(12)

Else

Timer1.Enabled = True cmdConnect.Enabled = True cmdDisconnect.Enabled = False End If

End Sub 4. tentang Unload Me End Sub

Private Sub Form_Unload(Cancel As Integer) frm_utama.Show

Me.Hide End Sub

5. keluar

Private Sub mn_keluar_Click() End

End Sub

6. Module Option Explicit

(13)

Public Port As Integer

Public SQLubah, SQLsimpan, SQLhapus As String Sub BukaDatabase()

Dim strSS, strPort, strDB, strUID, strPWD As String strSS = "localhost"

strPort = "3306" strDB = "db_data" strUID = "root" strPWD = ""

Set KonekDb = New ADODB.Connection KonekDb.CursorLocation = adUseClient KonekDb.ConnectionString = "" _

& "DRIVER={MYSQL ODBC 3.51 Driver};" _ & "SERVER=" & strSS & ";" _

& "DATABASE=" & strDB & ";" _ & "UID=" & strUID & ";" _

& "PWD=" & strPWD & ";" _ & "OPTION="

On Error Resume Next

(14)

Set KonekDb = New ADODB.Connection KonekDb.Open

Else

KonekDb.Open End If

If Err.Number <> 0 Then

MsgBox "GAGAL KONEKSI SERVER", vbOKOnly, "Kesalahan" End If

(15)

Program Assembly

1. Listing Program Mikrokontroller

(16)
(17)
(18)

tnd: mov r6,#255

4. listing program Mikrokontroler – II (Assembly)

(19)
(20)
(21)
(22)
(23)
(24)

acall tunda ret

tunda:

mov r7,#255 tnd:

mov r6,#255 djnz r6,$ djnz r7,tnd ret

hitung:

(25)

Figur

Memperbarui...

Referensi

Memperbarui...