Sei sulla pagina 1di 4

PUERTO PARALELO

Para el uso de este puerto siga los pasos siguientes pasos necesarios para la interface de datos, con el
microcontrolador:
1) Abra y cre un nuevo proyecto en Visual Basic 6.0, en un destino que usted considere.

2) Haga click derecho en Form1 y elija la opcin quitar form1.

3) Haga click derecho en Proyecto (Agregar-Formulario)y cambie el nombre a frmParalelo

4) Haga click derecho en Proyecto (Agregar-Modulo) y copie todo este contenido en el mismo:

5) Una vez que se abra la nueva ventana de este modulo copie el siguiente contenido sin omi r nada.
'********************************************************************
'Declarations for direct port I/O in 32-bit Visual Basic 6 programs.
'
Funciona en W9x, ME, NT, 2000 y XP
'********************************************************************
Public Declare Sub PortOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As Byte)
Public Declare Sub PortWordOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As
Integer)
Public Declare Sub PortDWordOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As
Long)
Public Declare Function PortIn Lib "IO.DLL" (ByVal Port As Integer) As Byte
Public Declare Function PortDWordIn Lib "IO.DLL" (ByVal Port As Integer) As Long
Public Declare Sub SetPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)
Public Declare Sub ClrPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)
Public Declare Sub NotPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)
Public Declare Function GetPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As
Byte) As Boolean
Public Declare Function RightPortShift Lib "IO.DLL" (ByVal Port As Integer, ByVal Val
As Boolean) As Boolean
Public Declare Function LeftPortShift Lib "IO.DLL" (ByVal Port As Integer, ByVal Val As
Boolean) As Boolean
Public Declare Function IsDriverInstalled Lib "IO.DLL" () As Boolean

'********************************************************
'*********
Function Descriptions
*******************
'********************************************************
'PortOut - Outputs a byte to the specified port.
'PortWordOut - Outputs a word (16-bits) to the specified port.
'PortDWordOut - Outputs a double word (32-bits) to the specified port.
'PortIn - Reads a byte from the specified port.
'PortWordIn - Reads a word (16-bits) from the specified port.
'PortDWordIn - Reads a double word (32-bits) from the specified port.
'SetPortBit - Sets the bit of the specified port.
'ClrPortBit - Clears the bit of the specified port.
'NotPortBit - Nots (inverts) the bit of the specified port.
'GetPortBit - Returns the state of the specified bit.
'RightPortShift - Shifts the specified port to the right. The LSB is
'
returned, and the value passed becomes the MSB.
'LeftPortShift - Shifts the specified port to the left. The MSB is
'
returned, and the value passed becomes the LSB.
'IsDriverInstalled - Returns non-zero if io.dll is installed and
'
functioning. The primary purpose of this function
'
is to ensure that the kernel mode driver for
'
NT/2000/XP has been installed and is accessible.

6) Si nos fijamos en el contenido estas sern las funciones que nos permitirn efectuar la comunicacin
paralela en forma fsica:

7) Luego abra el Formulario e introduzca los siguientes componentes, se describe las propiedades mas
importantes a modicar, de cada uno de estos:

HScrollBar (max=200,min=0)

Timer1(Enabled=False,Interval=100)

8)
(UNIDAD C: ----WINDOWS-----system32-----) y luego actualizar

9) Para poder simular en PROTEUS la transferencia de datos de la PC al MICROCONTROLADOR siga los pasos de
en PROTEUS y
luego tendr un puerto paralelo virtual, esto para ver solo simulaciones.

El programa consiste en un bucle innito que realiza los siguientes pasos:


a) El programa en Visual Basic espera a que el usuario cambie el valor en el ScrollBar
b) El computador PC enva el dato al PIC18F4550 a travs del puerto paralelo por el registro
de datos RD.
c) El microcontrolador recibe el dato por el puerto RB, suma 5 al dato y lo despliega en 8 leds
conectados al puerto RD.

10) El codigo para MIKROBASIC es:


program Puerto_Paralelo
dim dato as byte
main:
ADCON1=15
'Modo digital
CMCON=7
'Se deshabilita los comparadores A/D
INTCON=0
'Se deshabilita todas las interrupciones
TRISB=255
'Puerto B como entrada
LATD=0
' Puerto en estado bajo
TRISD=0
'Puerto D como salida
Bucle:
dato=PORTB
PORTD=dato+5
goto Bucle
end.
11) El codigo para VISUAL BASIC 6.0 es:
Dim datoTx As Byte
Dim datoRx As Byte
Private Sub Command1_Click()
End
End Sub
Private Sub Command2_Click()
datoRx = PortIn(&H379)
Text2.Text = Str(datoRx)
End Sub
Private Sub Form_Load()
PortOut &H378, 0
Timer1.Enabled = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
PortOut &H378, 0
End Sub
Private Sub HScroll1_Change()
Text1.Text = HScroll1.Value
Text4.Text = HScroll1.Value + 5
datoTx = HScroll1.Value
PortOut &H378, datoTx
End Sub

Potrebbero piacerti anche