I'm using VC++ 2005 Express on Windows XP. I'm reading and writing parallel ports' pins. I'm using 10 outputs (D0-D6, C0,C2,C3) - a combination of data pins and control pins , and 6 inputs (D7, S3-S7). To accomplish that, I'm using dlportio.h to send/receive data and I have no problems with that. My problem is as follows:
When I'm reading the port, dlportio.h allows to read the entire address (e.g. data address 0x378), and not the individual pins. Since I'm using the Data pins as outputs and inputs, I need to isolate D7 from the rest of the bits and that was done easily:
-
unsigned Data = 0x378;
-
short inpD7;
-
char buffer1[32];
-
inpD7 = DlPortReadPortUchar(Data);
-
inpD7 = inpD7 & 0x80; // isolate the first bit D7
-
itoa (inpD7,buffer1,2); // Convert int to string in binary format (base=2)
Moreover, I have utilized S3-S7 since S2,S1&S0 are unused according to the parallel port documentations I found on line. I did this with the following code:
-
unsigned Status = 0x379;
-
short inpStatus;
-
char buffer2[32];
-
inpStatus = DlPortReadPortUchar(Status);
-
inpStatus = inpStatus | 0xF8; // recall S7 is inverted
-
itoa (inpStatus,buffer2,2);
-
I wanted to concinnate the inputs so I used strcat_s to do it and it worked nicely. The outputs results in 9 bits: D7 S7-S0, but I'm only interested in getting the first six bits so I need to truncate the last bits. How can I do that? Also, after that I need to convert it to Hex to complete the remainder of my code. I have tried using atoi to convert the string back to int with base 16, but it gave wrong results. Any help would appreciated. Sorry if this was a simple question but I'm stuck and searched the forum and I couldn't find what I'm looking for. Thanks in advance.