The fellow programmer that program to connect with computer’s port on Window by using Borland C++ Builder that use the method that I suggested in programming connect to port that is run on DOS. Also, present how to program by MS VC++ 6 for running on Window that is using function of dos.h file, but cannot be used, despite declare #include at the top of program.
First of all, I want to disclaim that I don’t use Borland C++ Builder in programming because I practice just MS VC++ 6 , but trying to search information in the internet , then I find the answer that we have to use in writing function to connect to I/O Port by helping of assembly. I reminded that I used the method of writing in
Assembly connect I/O port
Send data out
OUT Address data port, Value
Address data port is the port’s position such as printer=0378
Value is the value that will send to printer data port, amount that control 8 bit is 00-FF.
mov dx,al
IN Value, Address Status Port
Address Status Port is the port’s position that will get value from the input such as printer=0379
Value is the value that read from the position of Printer Status Port, and then keeps in the register.
in al,dx
Take them to write the function in Borland C++ Builder
Output Port
I will use the function Outp for sending variable value as byte and will use the function Outp for sending variable value as word for setting the value that send out of port.
Outp function
|
void Outp(unsigned short pAddress , unsigned short pValue) { asm { mov dx,pAddress mov al,pValue out dx,al } } |
Outpw function
|
void Outp(unsigned short pAddress , unsigned char pValue) { asm { mov dx,pAddress mov al,pValue out dx,al } } |
The form of function that is used to work
Outp(Address Port,Value to Port)
Input Port
I will use the Inputb function for getting variable value as byte and will use the Inputw function, getting variable value as word for setting the value that send out of port.
Inputb function
|
unsigned char Inputb( pAddress) { unsigned char pStatus; asm { mov dx,pAddress in al,dx mov pStatus,al } return pStatus; } |
Inputw fucntion
|
unsigned short Inputw( pAddress) { unsigned char pStatus; asm { mov dx,pAddress in al,dx mov pStatus,al } return pStatus; } |
The form of function that is used to work
value=Inp(pAddress)