Lampiran 1
1. Program Modul CD4040
Dim tulis As Integer Sub PC3_High() 'Dim tulis As Integer
tulis = DAPI_WriteIoPorts(hDevInstance, &H80000, &H80000) End Sub
Sub PC3_Low()
'Dim tulis As Integer
tulis = DAPI_WriteIoPorts(hDevInstance, &H0, &H80000) End Sub
Sub CS0()
'Dim tulis As Integer
tulis = DAPI_WriteIoPorts(hDevInstance, &H0, &H70000) End Sub
Sub CS1()
'Dim tulis As Integer
tulis = DAPI_WriteIoPorts(hDevInstance, &H10000, &H70000) End Sub
Sub CS2()
'Dim tulis As Integer
tulis = DAPI_WriteIoPorts(hDevInstance, &H20000, &H70000) End Sub
Sub CS3()
'Dim tulis As Integer
tulis = DAPI_WriteIoPorts(hDevInstance, &H30000, &H70000) End Sub
Sub CS4()
'Dim tulis As Integer
tulis = DAPI_WriteIoPorts(hDevInstance, &H40000, &H70000) End Sub
'Dim tulis As Integer
tulis = DAPI_WriteIoPorts(hDevInstance, &H50000, &H70000) End Sub
Sub CS6()
'Dim tulis As Integer
tulis = DAPI_WriteIoPorts(hDevInstance, &H60000, &H70000) End Sub
Sub CS7()
'Dim tulis As Integer
tulis = DAPI_WriteIoPorts(hDevInstance, &H70000, &H70000) End Sub
Sub Reset4040() 'CS7
'CS0
tulis = DAPI_WriteIoPorts(hDevInstance, &H0, &H8000) tulis = DAPI_WriteIoPorts(hDevInstance, &H8000, &H8000) End Sub
Sub modul4()
tulis = DAPI_WriteIoPorts(hDevInstance, &H4000, &H7000) End Sub
Sub StartCounting() 'PC3_High
tulis = DAPI_WriteIoPorts(hDevInstance, &H80000, &H80000) End Sub
Sub StopCounting() 'PC3_Low
tulis = DAPI_WriteIoPorts(hDevInstance, &H0, &H80000) End Sub
modul4 CS1
LsbValue = ReadPort And &HFF CS2
MsbValue = ReadPort And &HFF count = MsbValue * 256 + LsbValue ReadCounter1 = count
CS0 End Function
Function ReadCounter2() Dim LsbValue As Long Dim MsbValue As Long Dim count As Long modul4
CS3
LsbValue = ReadPort And &HFF CS4
MsbValue = ReadPort And &HFF count = MsbValue * 256 + LsbValue ReadCounter2 = count
CS0 End Function
Function ReadCounter3() Dim LsbValue As Long Dim MsbValue As Long Dim count As Long modul4
CS1
LsbValue = ReadPort And &HFF CS2
ReadCounter3 = count CS0
End Function
Function ReadCounter4() Dim LsbValue As Long Dim MsbValue As Long Dim count As Long modul4
CS3
LsbValue = ReadPort And &HFF CS4
MsbValue = ReadPort And &HFF count = MsbValue * 256 + LsbValue ReadCounter4 = count
2. program Module 2 (Code)
Option Explicit
Declare Function GetTickCount Lib "kernel32" () As Long Public listval(1 To 5), CardVersion, changeHscale%, MaxScale
Public NewWidth, NewHeight, NewLeft, oldWidth, oldHeight, oldLeft
Public ImposeWidth, ImposeHeight, SpatialWidth, SpatialHeight, SpatialLeft, ImposeLeft
Public Ph2Right, Ph2Left, JiCmx, JaCmx, THALFLFT, TTWOTHIRDLFT, THALFRGHT, TTWOTHIRDRGHT
Public LFile$, CFile$, ChiLog$, CMDY$, LMDY, Lnum, CurrentDate$, Cd$, Cm$, Cy$
Public Renomode%, printmode%, HospitalName$, HospitalAddress$, User$ Public PauseChn, batch, LowerChn, UperChn, UperChnx, LowerChnx Public GetSpect, Pitchy, ModPitchy, SpectM%, JisMxSave, JasMxSave Public sFile, Acquis, PeakSpect, smth, PeakCount, Simulation
Public LLDx, ULDx, DDx, ddy, ChnKis(0 To 250) As Long, ChnKas(0 To 250) As Long
Public ChnKic(0 To 601) As Long, ChnKac(0 To 601) As Long, ChnKics(0 To 601) As Long, ChnKacs(0 To 601) As Long, T80 As Long, T140 As Long
Public RENOIDX$, LeftCol, RightCol, MaxDat, m%, UFRLFT0, UFRRGHT0, P2Left$, P2Right$, LeftMax$, RightMax$, LUpSlope$, RUpSlope$, TTWOTHIRDLeft$, TTWOTHIRDRIGHT$, THALFRIGHT$, THALFLeFT$, D12LSlope$, D12RSlope$, D23LSlope$, D23rSlope$, ZIGMALEFT, ZIGMARight, UFRLEFT$, UFRRIGHT$
Public maxpicx, maxpicy, Y0, X0, Ly, lh, Lx, Dx, Dy, ScalY, ScalX, XScale, skala As Integer
Public EChannel As Integer, EWindow As Integer, LeftCounter As Integer, RightCounter As Integer, Port8255 As Integer, Port8253 As Integer
Public ChnkiCmx, ChnkaCmx, ChnKiSmx, ChnKaSmx Public SimulationMode As Integer
Public TNUMB$, TDate$, TDay$, CrDate$, CDay$, TTIME$, PNAME$, AGE$, Adr1$, Adr2$, SENDR$, DIAGDR$, ISOTP$, RtfSFile$ '11
Public Simuation As Integer, FirstTime%, QCp% Public LCount As Long
Public RCount As Long Public EChannelUSB As Byte Public EWindowUSB As Byte
'Note CFile is Current File For Acquisition Mode
'Note SFile is Current Oppenened File For Retrieve Mode Sub Main()
Dim reader As Integer
Rem Inisialisasi USB PA=inp, PB=out, PC=out InitDevice
OpenDevice SetConfig 1, 0, 0 Reset4040
frmcekSCA.Show
3. Program mod UsbI2cIo API
Option Explicit
' This module file contains the necessary definitions, types, and declarations for accessing the
' functions provided by the UsbI2cIo API dll.
' Global constants and enumerations definitions
' UsbI2cIo maximum devices
Public Const USBI2CIO_MAX_DEVICES As Byte = 127
'Public Const USBI2CIO_DLL_NAME As String = "UsbI2cIo.dll"
' I2C transaction constants
Public Const I2C_HEADER_SIZE As Byte = 6 Public Const I2C_MAX_DATA As Byte = 255
' I2C Transaction Types
Public Enum I2C_TRANS_TYPE
I2C_TRANS_NOADR = 0 ' for I2C devices that do not use sub-addresses
I2C_TRANS_8ADR = 1 ' for I2C devices that use 8 bit sub-addresses
I2C_TRANS_16ADR = 2 ' for I2C devices that use 16 bit sub-addresses
End Enum
Public Type Word ' provides easy access to high and low bytes of two-byte entity
lo As Byte hi As Byte End Type
Public Type I2C_TRANS ' I2C Transaction Structure, used to specify I2C transaction info
byType As Byte ' see I2C_TRAN_TYPE enum (above)
byDevId As Byte ' bits 7-1 = the I2C device ID, bit 0 is auto set/cleared by call
wMemAddr As Word ' if accessing a device with addressing, sub-address goes here
wCount As Word ' count of bytes in Data array Data(64) As Byte ' I2C transaction data
End Type
Public Type DEVINFO
byInstance As Byte ' instance number of device
SerialId(8) As Byte ' 8 bytes Serial ID string of device and a NULL termination
End Type ' Note: in Vb, the array size is 1 greater than number specified
' UsbI2cIo API DLL function declarations
Declare Function DAPI_GetDllVersion Lib "UsbI2cIo.dll" () As Word
'Declare Function DAPI_GetDriverVersion Lib "UsbI2cIo.dll" () As Word
Declare Function DAPI_GetDeviceCount Lib "UsbI2cIo.dll" ( _ ByVal lpsDevName As String) _
As Byte
Declare Function DAPI_GetDeviceInfo Lib "UsbI2cIo.dll" ( _ ByVal lpsDevName As String, _
ByRef lpDevInfo As DEVINFO) _ As Byte
Declare Function DAPI_GetSerialId Lib "UsbI2cIo.dll" ( _ ByVal hDevInstance As Long, _
ByVal lpsSerialId As String) _ As Byte
Declare Function DAPI_DetectDevice Lib "UsbI2cIo.dll" ( _ ByVal hDevInstance As Long) _
As Boolean
Declare Function DAPI_OpenDeviceInstance Lib "UsbI2cIo.dll" ( _ ByVal lpsDevName As String, _
ByVal byDevInstance As Byte) _ As Long
Declare Function DAPI_CloseDeviceInstance Lib "UsbI2cIo.dll" ( _ ByVal hDevInstance As Long) _
As Boolean
Declare Function DAPI_OpenDeviceBySerialId Lib "UsbI2cIo.dll" ( _ ByVal lpsDevName As String, _
Declare Function DAPI_GetIoConfig Lib "UsbI2cIo.dll" ( _ ByVal hDevInstance As Long, _
ByRef pulIoPortData As Long) _ As Boolean
Declare Function DAPI_ConfigIoPorts Lib "UsbI2cIo.dll" ( _ ByVal hDevInstance As Long, _
ByVal ulIoPortConfig As Long) _ As Boolean
Declare Function DAPI_ReadIoPorts Lib "UsbI2cIo.dll" ( _ ByVal hDevInstance As Long, _
ByRef pulIoPortData As Long) _ As Boolean
Declare Function DAPI_WriteIoPorts Lib "UsbI2cIo.dll" ( _ ByVal hDevInstance As Long, _
ByVal ulIoPortData As Long, _ ByVal ulIoPortMask As Long) _ As Boolean
Declare Function DAPI_ReadI2c Lib "UsbI2cIo.dll" ( _ ByVal hDevInstance As Long, _
ByRef TransI2c As I2C_TRANS) _ As Long
Declare Function DAPI_WriteI2c Lib "UsbI2cIo.dll" ( _ ByVal hDevInstance As Long, _
Declare Function DAPI_ReadDebugBuffer Lib "UsbI2cIo.dll" ( _ ByRef DebugBuf As Byte, _
4. Program modWinAPI
Option Explicit '
' This module file contains definitions, types, and declarations for accessing the ' functions provided by the Windows Win32 API.
'
' Win32 API constant declarations
Public Const INVALID_HANDLE_VALUE = -1
' Win32 API function declarations
Declare Function GetLastError Lib "kernel32" () As Long
Declare Function DeviceIoControl Lib "kernel32" ( _ ByVal hDevice As Long, _
ByVal dwIoControlCode As Long, _ lpInBuffer As Byte, _
ByVal nInBufferSize As Long, _ lpOutBuffer As Byte, _
ByVal nOutBufferSize As Long, _ lpBytesReturned As Long, _ lpOverlapped As Long) _ As Long
Declare Function WriteFile Lib "kernel32" ( _ ByVal hFile As Long, _
ByVal nNumberOfBytesToWrite As Long, _ lpNumberOfBytesWritten As Long, _
lpOverlapped As Long) _ As Long
Declare Function ReadFile Lib "kernel32" ( _ ByVal hFile As Long, _
lpBuffer As Any, _
ByVal nNumberOfBytesToRead As Long, _ lpNumberOfBytesRead As Long, _
lpOverlapped As Long) _ As Long
' Error Code Defines from API
' Code Description Name
' 0 The operation completed successfully. ERROR_SUCCESS ' 1 Incorrect function.
ERROR_INVALID_FUNCTION
' 2 The system cannot find the file specified. ERROR_FILE_NOT_FOUND
' 3 The system cannot find the path specified. ERROR_PATH_NOT_FOUND
' 4 The system cannot open the file. ERROR_TOO_MANY_OPEN_FILES
5. Program cek device
Option Explicit
Dim sAppName As String ' Nama Aplikasi
Public sDevSymName As String ' Nama simbolik USB, Contoh: "UsbI2cIo" Public byDevInstance As Byte ' Nomor device yang dipilih
Public hDevInstance As Long ' handle device yg dipilih
Dim bDevicePresent As Boolean ' flag yg mengindikasikan keberadaan device Sub InitDevice()
sDevSymName = "UsbI2cIo" ' Nama simbolik USB sAppName = "Counter CD4040 " ' Nama Aplikasi 'Counterfrm.Caption = sAppName & " - no device" ' Caption Aplikasi byDevInstance = 255 ' initial device(255 = no device)
hDevInstance = INVALID_HANDLE_VALUE ' inisialisasi file handle End Sub
Sub OpenDevice() Dim I As Byte
For I = 0 To 127 Step 1 If (OpenDiHandle(I)) Then ' Suksessss!!!!!!!!! Exit For
End If Next I
' Memberikan Pesan Suksessss atau Gagallllll If (I = 128) Then
' Tak ada device yg terpasang
Call MsgBox("No UsbI2cIo Devices were detected", vbOKOnly, "Device Open Error")
Else
byDevInstance = I
'Counterfrm.Caption = sAppName & " - " & sDevSymName & Format(i) ' Application Title Caption
End If End Sub
Function OpenDiHandle(byDevInstance As Byte) As Byte CloseDiHandle
hDevInstance = DAPI_OpenDeviceInstance(sDevSymName, byDevInstance) If (hDevInstance <> INVALID_HANDLE_VALUE) Then
OpenDiHandle = 1 Else
OpenDiHandle = 0 End If
End Function
Sub SetConfig(PA, PB, PC) 'Output=0,Input=1 Dim Data As Long
Data = (PA * 255) + (PB * 65280) + (PC * 458752) If DAPI_ConfigIoPorts(hDevInstance, Data) Then ' Pemanggilan fungsi Suksesss!!!!!
Call MsgBox("Device OK", vbOKOnly, "Device Configuration OK") Else
' Gagalllll!!!!!
Call MsgBox("No UsbI2cIo Devices were detected", vbOKOnly, "Device Configuration Error")
End If End Sub
Sub CloseDiHandle()
If hDevInstance <> INVALID_HANDLE_VALUE Then If DAPI_CloseDeviceInstance(hDevInstance) Then '
End If
hDevInstance = INVALID_HANDLE_VALUE End If
End Sub
Function CheckDevice() As Boolean
If hDevInstance = INVALID_HANDLE_VALUE Then If OpenDiHandle(byDevInstance) Then
CheckDevice = True Else
CheckDevice = False End If
ElseIf DAPI_DetectDevice(hDevInstance) Then CheckDevice = True
Else
CloseDiHandle CheckDevice = False End If
End Function
Sub Wait(d As Integer) 'd : detik Dim CurTime As Long Dim NextTime As Long Dim DifTime As Integer CurTime = Timer Do
DoEvents
NextTime = Timer
DifTime = NextTime - CurTime If DifTime >= d Then
Function ReadPort() Dim Data As Integer Dim DataPort As Long
Data = DAPI_ReadIoPorts(hDevInstance, DataPort) ReadPort = DataPort
End Function
Sub WriteI2cDa(I2cData As Byte, I2cAddress As Byte)
Dim I2cTrans As I2C_TRANS ' Dimension an I2C_TRANS structure Dim lWritten As Long ' Dimension a long to hold the returned value Dim DevId As Integer
Select Case I2cAddress Case 0:
DevId = &H90 Case 1:
DevId = &H92 Case 2:
DevId = &H94 Case 3:
DevId = &H96 Case 4:
DevId = &H98 Case 5:
DevId = &H9A Case 6:
DevId = &H9C Case 7:
DevId = &H9E End Select
I2cTrans.byDevId = DevId ' PCF8591 device
I2cTrans.wMemAddr.hi = 0 ' unused for I2C_TRANS_NOADDR I2cTrans.wMemAddr.lo = 0 ' unused for I2C_TRANS_NOADDR I2cTrans.wCount.hi = 0 ' only writing 1 byte, so set to 0
I2cTrans.wCount.lo = 2 ' writing 2 byte, Control byte dan Data byte I2cTrans.Data(0) = &H40 'Control byte
I2cTrans.Data(1) = I2cData ' the actual data that will be written to PCF8591
lWritten = DAPI_WriteI2c(hDevInstance, I2cTrans) If (lWritten = 2) Then
' function call ok Else
' function call failed
Call MsgBox("Incorrect Return value", vbOKOnly, " Error calling DAPI_WriteI2C() function")
End If End Sub
Sub WriteI2cIo(I2cData As Byte, I2cAddress As Byte)
Dim I2cTrans As I2C_TRANS ' Dimension an I2C_TRANS structure Dim lWritten As Long ' Dimension a long to hold the returned value Dim DevId As Integer
Select Case I2cAddress Case 0:
DevId = &H90 Case 1:
DevId = &H92 Case 2:
DevId = &H94 Case 3:
DevId = &H98 Case 5:
DevId = &H9A Case 6:
DevId = &H9C Case 7:
DevId = &H9E End Select
I2cTrans.byDevId = DevId ' PCF8574 device
I2cTrans.byType = I2C_TRANS_NOADR ' device does not use sub-address I2cTrans.wMemAddr.hi = 0 ' unused for I2C_TRANS_NOADDR I2cTrans.wMemAddr.lo = 0 ' unused for I2C_TRANS_NOADDR I2cTrans.wCount.hi = 0 ' only writing 1 byte, so set to 0
I2cTrans.wCount.lo = 1 ' writing 1 byte
I2cTrans.Data(0) = I2cData ' the actual data that will be written to PCF8591
lWritten = DAPI_WriteI2c(hDevInstance, I2cTrans) If (lWritten = 1) Then
' function call ok Else
' function call failed
Call MsgBox("Incorrect Return value", vbOKOnly, " Error calling DAPI_WriteI2C() function")
End If End Sub
Function ReadI2cIo(I2cAddress As Byte)
Dim I2cTrans As I2C_TRANS ' Dimension an I2C_TRANS structure
Dim DevId As Integer
Select Case I2cAddress Case 0:
DevId = &H1 Case 1:
DevId = &H3 Case 2:
DevId = &H5 Case 3:
DevId = &H7 Case 4:
DevId = &H9 Case 5:
DevId = &HB Case 6:
DevId = &HD Case 7:
DevId = &HF End Select
I2cTrans.byDevId = DevId ' PCF8574 device ID
I2cTrans.byType = I2C_TRANS_NOADR ' device does not use sub-address
I2cTrans.wMemAddr.hi = 0 ' unused for I2C_TRANS_NOADDR I2cTrans.wMemAddr.lo = 0 ' unused for I2C_TRANS_NOADDR I2cTrans.wCount.hi = 0 ' only reading 1 byte, so set to 0
I2cTrans.wCount.lo = 1 ' reading 1 byte, so set to 1
lRead = DAPI_ReadI2c(hDevInstance, I2cTrans) If (lRead = 1) Then
ReadI2cIo = I2cTrans.Data(0) Else
' function call failed ReadI2c = 0
Call MsgBox("Incorrect Return value", vbOKOnly, " Error calling DAPI_ReadI2C() function")
Lampiran 3
Tabel 1. Hasil Pengujian Energi Digital To Analog DAC 8 Bit ADDA Melalui Antarmuka I2C I/O USB Yang Diukur Dengan Menggunakan Multimeter Digital Fluke 8021B
86 796 839 -43 5,12
103 962 1.005 -43 4,27
104 972 1.015 -43 4,24
105 981 1.025 -44 4,29
106 991 1.035 -44 4,25
224 2.142 2.187 -45 2,05 225 2.152 2.197 -45 2,04 226 2.162 2.207 -45 2,03 227 2.171 2.216 -45 2,03 228 2.181 2.226 -45 2,02 229 2.191 2.236 -45 2,01 230 2.200 2.240 -40 1,78 231 2.210 2.255 -45 1,50 232 2.220 2.265 -45 1,98 233 2.230 2.275 -45 1,97 234 2.240 2.285 -45 1,96 235 2.250 2.294 -44 1,91 236 2.259 2.304 -45 1,95 237 2.269 2.314 -45 1,94 238 2.279 2.324 -45 1,93 239 2.289 2.333 -44 1,88 240 2.298 2.343 -45 1,92 241 2.308 2.353 -45 1,91 242 2.318 3.363 -45 1,07 243 2.328 2.373 -45 1,89 244 2.337 2.382 -45 1,88 245 2.347 2.392 -45 1,88 246 2.357 2.402 -45 1,87 247 2.367 2.412 -45 1,86 248 2.376 2.421 -45 1,85 249 2.386 2.431 -45 1,85 250 2.396 2.441 -45 1,84 251 2.406 2.451 -45 1,83 252 2.416 2.460 -44 1,78 253 2.425 2.470 -45 1,82 254 2.435 2.480 -45 1,81 255 2.445 2.490 -45 1,81 Penyimpangan Rata – Rata 5,07
Tabel 2 Hasil Pengujian Energi Digital To Analog DAC 8 Bit ADDA Melalui Antarmuka I2C I/O USB Yang Diukur Dengan Menggunakan Multimeter Digital Fluke 8021B
39 6500 10 65000 64849 65272 65060.5 0.09