Pascal to C++ - Microsoft Windows

This is a discussion on Pascal to C++ - Microsoft Windows ; Hey, Im doing a project which invoves using a serial A/D converter, I have been given some code in Pascal but i need this translated into C++ code in order to use it in the compiler that i have been ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Pascal to C++

  1. Pascal to C++

    Hey,


    Im doing a project which invoves using a serial A/D converter, I have
    been given some code in Pascal but i need this translated into C++
    code in order to use it in the compiler that i have been told to use, I

    am only new to both types of code and any help you could give me would
    be greatly appreciated,


    Thanks in advance,


    Rod


    The code is as shown here


    Program serial_adc;


    {Serial port AD converter circuit control program by Tomi Engdahl}


    Uses Crt;


    Const
    combase=$2f8;
    MCR=combase+4;
    LCR=combase+3;
    MSR=combase+6;


    Procedure Initialize_converter;
    Begin
    Port[MCR]:=3;
    Port[LCR]:=0;
    End;


    Function Read_value:byte;
    Var
    value:byte;
    count:byte;
    Begin
    value:=0;
    Port[MCR]:=1;
    For count:=0 to 7 Do Begin
    value:=value SHL 1;
    Port[LCR]:=64;
    If (port[MSR] and $10)=$10 Then Inc(value);
    Port[LCR]:=0;
    End;
    Port[MCR]:=3;
    Read_value:=value;
    End;


    Begin
    Initialize_converter;
    Repeat
    Writeln(Read_value);
    Until KeyPressed;
    End.


  2. Re: Pascal to C++

    6 May 2005 07:00:52 -0700, cwynnes@gmail.com:

    > Hey,
    >
    > Im doing a project which invoves using a serial A/D converter, I have
    > been given some code in Pascal but i need this translated into C++
    > code in order to use it in the compiler that i have been told to use, I
    >
    > am only new to both types of code and any help you could give me would
    > be greatly appreciated,
    >
    > Thanks in advance,
    > Rod


    Though this NG has nothing to do with programming:

    > Program serial_adc;
    >
    > {Serial port AD converter circuit control program by Tomi Engdahl}
    >
    > Uses Crt;
    >
    > Const
    > combase=$2f8;
    > MCR=combase+4;
    > LCR=combase+3;
    > MSR=combase+6;
    >
    > Procedure Initialize_converter;
    > Begin
    > Port[MCR]:=3;
    > Port[LCR]:=0;
    > End;
    >
    > Function Read_value:byte;
    > Var
    > value:byte;
    > count:byte;
    > Begin
    > value:=0;
    > Port[MCR]:=1;
    > For count:=0 to 7 Do Begin
    > value:=value SHL 1;
    > Port[LCR]:=64;
    > If (port[MSR] and $10)=$10 Then Inc(value);
    > Port[LCR]:=0;
    > End;
    > Port[MCR]:=3;
    > Read_value:=value;
    > End;
    >
    > Begin
    > Initialize_converter;
    > Repeat
    > Writeln(Read_value);
    > Until KeyPressed;
    > End.


    Try:

    #define combase 0x02f8
    #define MCR combase+4
    #define LCR combase+3
    #define MSR combase+6

    void Initialize_converter
    {
    Port[MCR]=3;
    Port[LCR]=0;
    }

    BYTE Read_value()
    {
    BYTE value=0;
    BYTE count;
    Port[MCR]=1;
    for (count=0;count<8;count++) {
    value<<=1;
    Port[LCR]=64;
    If (port[MSR] & 0x10) value++;
    Port[LCR]=0;
    }
    Port[MCR]=3;
    Read_value=value;
    }


    void main()
    {
    Initialize_converter();
    do {
    cout << Read_value <<;
    } while (!keypressed); // keypressed is wrong, but I don't know its
    C(++) equivalent
    }
    --
    Gruß | Greetings | Qapla'
    "All I ask is a tall ship and a star to steer her by."
    http://www.stud.tu-ilmenau.de/~frst-ii/

  3. Re: Pascal to C++

    Fri, 6 May 2005 15:20:39 +0100, Frank Steinmetzger:

    > Try:
    >
    > [...]
    >
    > do {
    > cout << Read_value <<;


    remove the latter <<, they are wrong.

    --
    Gruß | Greetings | Qapla'
    "All I ask is a tall ship and a star to steer her by."
    http://www.stud.tu-ilmenau.de/~frst-ii/

+ Reply to Thread