codigo fuente en visual basic 'variable que contiene la direccion base del puerto Private DIR_PUERTO As Integer 'Declaracion de funciones Private Declare Function GetPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte) As Boolean Private Declare Function IsDriverInstalled Lib "IO.DLL" () As Boolean 'Funciones que habilitan/deshabilitan bits del puerto. Private Declare Function SetPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte) As Boolean Private Declare Function NotPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte) As Boolean Private Declare Function ClrPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte) As Boolean Private Sub Form_Load() 'Veo si cargo el driver If IsDriverInstalled() = True Then DIR_PUERTO = &H378 Else MsgBox "Driver no instalado.", vbInformation + vbOKOnly + vbSystemModal, "Problemas!" End End If End Sub Private Sub LeerP_Click() 'Limpio el estado del puerto For X = 0 To 7 Step 1 aux = SetPortBit(DIR_PUERTO, X) aux = ClrPortBit(DIR_PUERTO, X) Next 'Configuro el puerto paralelo como entrada 'poniendo el BIT 5 del port de control en 1 aux = SetPortBit(DIR_PUERTO + 2, 5) '--- Ordeno la conversion A/D---- 'selecciono el chip 'poniendo CS (Pin 1 del chip) a masa:C0=0 (Pin 1 del LPT) aux = SetPortBit(DIR_PUERTO + 2, 0) 'Pongo WR (pin 3 del chip) bajo: C2=0 (pin 16 del LPT) aux = SetPortBit(DIR_PUERTO + 2, 2) 'Espero al menos 100 ns For X = 0 To 100000 Next 'Pongo WR (pin 3 del chip) en alto: C2=1 (pin 16 LPT) aux = ClrPortBit(DIR_PUERTO + 2, 2) 'Leo y muestro Bits de control For X = 0 To 7 Step 1 If GetPortBit(DIR_PUERTO + 2, X) = True Then Text3(X).Text = CStr(1) Else Text3(X).Text = CStr(0) End If Next For X = 0 To 100000 Next 'Le doy tiempo a que INTR (pin 5 del chip) se ponga en alto For X = 0 To 100000 Next 'Pongo RD (pin 2 del chip) en bajo: C3=1 (pin 1 LPT) aux = ClrPortBit(DIR_PUERTO + 2, 3) 'Espera al menos 200 ns For X = 0 To 100000 Next 'Leo los 8 bits del puerto ValorD = 0 For X = 0 To 7 Step 1 'Bits de datos If GetPortBit(DIR_PUERTO, X) = True Then Text1(X).Text = CStr(1) ValorD = ValorD + 2 ^ (7 - X) Else Text1(X).Text = CStr(0) End If 'Bits de control If GetPortBit(DIR_PUERTO + 2, X) = True Then Text3(X).Text = CStr(1) Else Text3(X).Text = CStr(0) End If Next X 'Calculo el valor porcentual, etc ValorP = ValorD / 256 * 100 ValorV = ValorD / 256 * 5 'La siguiente linea calcula la temperatura a mostrar. 'Para calibrar lo que mide el sensor, podemos variar el 'valor que se resta al final (2.73). ValorT = ValorV / 0.01 - 273 End Sub Private Sub LimpiarP_Click() 'Limpio el estado del puerto aux = ClrPortBit(DIR_PUERTO + 2, 5) For X = 0 To 7 Step 1 aux = SetPortBit(DIR_PUERTO, X) aux = ClrPortBit(DIR_PUERTO, X) aux = ClrPortBit(DIR_PUERTO + 2, X) Next 'Leo los 8 bits del puerto ValorD = 0 For X = 0 To 7 Step 1 'Bits de datos If GetPortBit(DIR_PUERTO, X) = True Then Text1(X).Text = CStr(1) ValorD = ValorD + 2 ^ X Else Text1(X).Text = CStr(0) End If 'Bits de control If GetPortBit(DIR_PUERTO + 2, X) = True Then Text3(X).Text = CStr(1) Else Text3(X).Text = CStr(0) End If Next End Sub Private Sub Timer1_Timer() Dim X As Integer Dim aux As Integer 'acquiring different bits and there values in different registers in the parallel port 'For X = 0 To 7 Step 1 'If GetPortBit(DIR_PUERTO, X) = True Then 'Text1(X).Text = CStr(1) 'Else 'Text1(X).Text = CStr(0) 'End If 'If GetPortBit(DIR_PUERTO + 1, X) = True Then 'Text2(X).Text = CStr(1) 'Else 'Text2(X).Text = CStr(0) 'End If 'aux = SetPortBit(DIR_PUERTO + 2, 32) 'If GetPortBit(DIR_PUERTO + 2, X) = True Then 'Text3(X).Text = CStr(1) 'Else 'Text3(X).Text = CStr(0) 'End If 'Next X End Sub codigo fuente en vb.net Option Strict Off Option Explicit On Friend Class Frm_Register_Analyzer Inherits System.Windows.Forms.Form 'variable que contiene la direccion base del puerto Private DIR_PUERTO As Short 'Declaracion de funciones Private Declare Function GetPortBit Lib "IO.DLL" (ByVal Port As Short, ByVal Bit As Byte) As Boolean Private Declare Function IsDriverInstalled Lib "IO.DLL" () As Boolean 'Funciones que habilitan/deshabilitan bits del puerto. Private Declare Function SetPortBit Lib "IO.DLL" (ByVal Port As Short, ByVal Bit As Byte) As Boolean Private Declare Function NotPortBit Lib "IO.DLL" (ByVal Port As Short, ByVal Bit As Byte) As Boolean Private Declare Function ClrPortBit Lib "IO.DLL" (ByVal Port As Short, ByVal Bit As Byte) As Boolean Private Sub Frm_Register_Analyzer_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load 'Veo si cargo el driver If IsDriverInstalled() = True Then DIR_PUERTO = &H378S Else MsgBox("Driver no instalado.", MsgBoxStyle.Information + MsgBoxStyle.OkOnly + MsgBoxStyle.SystemModal, "Problemas!") End End If End Sub Private Sub LeerP_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles LeerP.Click Dim aux As Object Dim X As Object 'Limpio el estado del puerto For X = 0 To 7 Step 1 aux = SetPortBit(DIR_PUERTO, X) aux = ClrPortBit(DIR_PUERTO, X) Next 'Configuro el puerto paralelo como entrada 'poniendo el BIT 5 del port de control en 1 aux = SetPortBit(DIR_PUERTO + 2, 5) '--- Ordeno la conversion A/D---- 'selecciono el chip 'poniendo CS (Pin 1 del chip) a masa:C0=0 (Pin 1 del LPT) aux = SetPortBit(DIR_PUERTO + 2, 0) 'Pongo WR (pin 3 del chip) bajo: C2=0 (pin 16 del LPT) aux = SetPortBit(DIR_PUERTO + 2, 2) 'Espero al menos 100 ns For X = 0 To 100000 Next 'Pongo WR (pin 3 del chip) en alto: C2=1 (pin 16 LPT) aux = ClrPortBit(DIR_PUERTO + 2, 2) 'Leo y muestro Bits de control For X = 0 To 7 Step 1 If GetPortBit(DIR_PUERTO + 2, X) = True Then Text3(X).Text = CStr(1) Else Text3(X).Text = CStr(0) End If Next For X = 0 To 100000 Next 'Le doy tiempo a que INTR (pin 5 del chip) se ponga en alto For X = 0 To 100000 Next 'Pongo RD (pin 2 del chip) en bajo: C3=1 (pin 1 LPT) aux = ClrPortBit(DIR_PUERTO + 2, 3) 'Espera al menos 200 ns For X = 0 To 100000 Next 'Leo los 8 bits del puerto ValorD.Text = CStr(0) For X = 0 To 7 Step 1 'Bits de datos If GetPortBit(DIR_PUERTO, X) = True Then Text1(X).Text = CStr(1) ValorD.Text = CStr(CDbl(ValorD.Text) + 2 ^ (7 - X)) Else Text1(X).Text = CStr(0) End If 'Bits de control If GetPortBit(DIR_PUERTO + 2, X) = True Then Text3(X).Text = CStr(1) Else Text3(X).Text = CStr(0) End If Next X 'Calculo el valor porcentual, etc ValorP.Text = CStr(CDbl(ValorD.Text) / 256 * 100) ValorV.Text = CStr(CDbl(ValorD.Text) / 256 * 5) 'La siguiente linea calcula la temperatura a mostrar. 'Para calibrar lo que mide el sensor, podemos variar el 'valor que se resta al final (2.73). ValorT.Text = CStr(CDbl(ValorV.Text) / 0.01 - 273) End Sub Private Sub LimpiarP_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles LimpiarP.Click Dim X As Object Dim aux As Object 'Limpio el estado del puerto aux = ClrPortBit(DIR_PUERTO + 2, 5) For X = 0 To 7 Step 1 aux = SetPortBit(DIR_PUERTO, X) aux = ClrPortBit(DIR_PUERTO, X) aux = ClrPortBit(DIR_PUERTO + 2, X) Next 'Leo los 8 bits del puerto ValorD.Text = CStr(0) For X = 0 To 7 Step 1 'Bits de datos If GetPortBit(DIR_PUERTO, X) = True Then Text1(X).Text = CStr(1) ValorD.Text = CStr(CDbl(ValorD.Text) + 2 ^ X) Else Text1(X).Text = CStr(0) End If 'Bits de control If GetPortBit(DIR_PUERTO + 2, X) = True Then Text3(X).Text = CStr(1) Else Text3(X).Text = CStr(0) End If Next End Sub Private Sub Timer1_Timer() Dim X As Short Dim aux As Short 'acquiring different bits and there values in different registers in the parallel port For X = 0 To 7 Step 1 If GetPortBit(DIR_PUERTO, X) = True Then Text1(X).Text = CStr(1) Else Text1(X).Text = CStr(0) End If If GetPortBit(DIR_PUERTO + 1, X) = True Then Text2(X).Text = CStr(1) Else Text2(X).Text = CStr(0) End If aux = SetPortBit(DIR_PUERTO + 2, 32) If GetPortBit(DIR_PUERTO + 2, X) = True Then Text3(X).Text = CStr(1) Else Text3(X).Text = CStr(0) End If Next X End Sub End Class