Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need professional help

Status
Not open for further replies.

Bertv100

Programmer
Apr 27, 2000
204
BE
Hi, I've got some source code in C I would like to translate to Delphi 4 (Object Pascal). I would be glad if someone could help me out.<br>I've got the same source for Turbo Pascal, Visual Basic 3.0 & 4.0, C and QBasic.<br>You'll think: he's got it in Turbo Pascal, why not use it in Delphi directly. Well I tried but it makes use or TPs PORT array, which doesn't exist in Delphi.<br><br>Here's one of the most important procedures. If you really want to help me, I could send you one of the units.<br>Mind that I've never programmed in this language before, so there could be some missing things.<br><br>This stands in the beginning:<br><FONT FACE=monospace><br>#include &lt;stdio.h&gt;<br>#include &lt;dos.h&gt;<br>#include &lt;string.h&gt;<br>#include &lt;stdlib.h&gt;<br></font><br>And this is the procedure I would like to have decrypted :)<br><FONT FACE=monospace><br>void ReadIOchip(int Chip_no)<br>{<br> int Start_Channel, Channel, Data, cport, i, j;<br><br> /*Generate start condition*/<br> outport(ControlPort, 0x06);<br> for (i = 0; i &lt;= I2CbusDelay; i++) {};&nbsp;&nbsp;&nbsp;&nbsp;/*I2c-bus timing*/<br> outport(ControlPort, 0x0E);<br> for (i = 0; i &lt;= I2CbusDelay; i++) {};&nbsp;&nbsp;&nbsp;&nbsp;/*I2c-bus timing*/<br><br> /*Serial output of Chipcode for readmode*/<br> Data = ((IOchipCode[Chip_no] ¦ 0x01) &lt;&lt; 8);&nbsp;&nbsp;/*Shift data 8 bits left*/<br> for (j = 1; j &lt;= 8; j++) {<br> cport = (Data &lt; 0) ? 0x0C: 0x0E;<br> outport(ControlPort, cport);<br> for (i = 0; i &lt;= I2CbusDelay; i++) {};&nbsp;&nbsp;/*I2c-bus timing*/<br> cport = cport & 0x07;<br> outport(ControlPort, cport);<br> Data &lt;&lt;= 1;<br> for (i = 0; i &lt;= I2CbusDelay; i++) {};&nbsp;&nbsp;/*I2c-bus timing*/<br> cport = cport ¦ 0x08;<br> outport(ControlPort, cport);<br> for (i = 0; i &lt;= I2CbusDelay; i++) {};&nbsp;&nbsp;/*I2c-bus timing*/<br> };<br><br> /*Clock pulse for acknowledgement*/<br> outport(ControlPort, 0x0C);<br> for (i = 0; i &lt;= I2CbusDelay; i++) {};&nbsp;&nbsp;&nbsp;&nbsp;/*I2c-bus timing*/<br> outport(ControlPort, 0x04);<br> for (i = 0; i &lt;= I2CbusDelay; i++) {};&nbsp;&nbsp;&nbsp;&nbsp;/*I2c-bus timing*/<br> outport(ControlPort, 0x0C);<br> for (i = 0; i &lt;= I2CbusDelay; i++) {};&nbsp;&nbsp;&nbsp;&nbsp;/*I2c-bus timing*/<br><br> /*Serial input of ChipData*/<br> Data = 0; /*Clear Data*/<br> for (j = 1; j &lt;= 8; j++) {<br> Data &lt;&lt;= 1;<br> outport(ControlPort, 0x04);<br> for (i = 0; i &lt;= I2CbusDelay; i++) {};&nbsp;&nbsp;&nbsp;&nbsp;/*I2c-bus timing*/<br> if (inport(StatusPort) & 0x10) Data = Data ¦ 0x0001;<br> outport(ControlPort, 0x0C);<br> for (i = 0; i &lt;= I2CbusDelay; i++) {};&nbsp;&nbsp;&nbsp;&nbsp;/*I2c-bus timing*/<br> };<br> IOdata[Chip_no] = ~Data;<br><br> /*Clock pulse for acknowledgement*/<br> outport(ControlPort, 0x0C);<br> for (i = 0; i &lt;= I2CbusDelay; i++) {};&nbsp;&nbsp;&nbsp;&nbsp;/*I2c-bus timing*/<br> outport(ControlPort, 0x04);<br> for (i = 0; i &lt;= I2CbusDelay; i++) {};&nbsp;&nbsp;&nbsp;&nbsp;/*I2c-bus timing*/<br> outport(ControlPort, 0x0C);<br> for (i = 0; i &lt;= I2CbusDelay; i++) {};&nbsp;&nbsp;&nbsp;&nbsp;/*I2c-bus timing*/<br><br> /*Generate stop condition*/<br> outport(ControlPort, 0x0E);<br> for (i = 0; i &lt;= I2CbusDelay; i++) {};&nbsp;&nbsp;&nbsp;&nbsp;/*I2c-bus timing*/<br> outport(ControlPort, 0x06);<br> for (i = 0; i &lt;= I2CbusDelay; i++) {};&nbsp;&nbsp;&nbsp;&nbsp;/*I2c-bus timing*/<br> outport(ControlPort, 0x04);<br> for (i = 0; i &lt;= I2CbusDelay; i++) {};&nbsp;&nbsp;&nbsp;&nbsp;/*I2c-bus timing*/<br><br> /*Update 'IO' array*/<br> Start_Channel = Chip_no * 8 + 1; /*Calculate start channel*/<br> for (Channel = 0; Channel &lt;= 7; Channel++) /*Test status 8 ch. of the IOchip*/<br> IO[Start_Channel+Channel] = ((IOdata[Chip_no] & (0x01 &lt;&lt; Channel)) != 0);<br>};<br></font><br><br><br>Thanks in advance,<br> <p>Bert Vingerhoets<br><a href=mailto:vingerhoetsbert@hotmail.com>vingerhoetsbert@hotmail.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top