Board index » delphi » Real number to integer to byte help!!!

Real number to integer to byte help!!!

I hope someone can help me!

I have designed an ISA card for a PC and I am trying to program it in TP7.
(You may remember a post I made a while ago). I've tested the card, and
manufactured a final version with a few improvements. I am now writing the
final software for it.

The problem I have is with using real numbers. I need to put a count into a
register on the card (a byte). I need to get a frequency from the user in
kHz. Then divide this number by 8000000 (The 8MHz reference clock on the
card) to get the count to put into the register. So the code is something
like this:

count:=(8000000/frequency);
port [$01B0]:=count;

of course this will not work, becuase count has to be a real number to be
output to a port. The rest of the code I've written makes sure that
frequency will divide my 8MHz to generate an integer which will work with
the register.

Can anyone help me with the code to convert the count variable in real to
another variable which is a byte variable??

If someone can help I would be very grateful,
Thank you for your time,
Richard Webb
ICQ:  10634107

 

Re:Real number to integer to byte help!!!


It's alright everyone!! Stop looking! I've found the answer. I took a trip
to the library and got some books out on Pascal and found the answer. I had
to use the Trunc and Round commands to convert real numbers to signed
integers, which I could then use Hi and Lo to breakdown into bytes!
Quote
Richard Webb wrote in message <8a38e8$i0...@supernews.com>...
>I hope someone can help me!

>I have designed an ISA card for a PC and I am trying to program it in TP7.
>(You may remember a post I made a while ago). I've tested the card, and
>manufactured a final version with a few improvements. I am now writing the
>final software for it.

>The problem I have is with using real numbers. I need to put a count into a
>register on the card (a byte). I need to get a frequency from the user in
>kHz. Then divide this number by 8000000 (The 8MHz reference clock on the
>card) to get the count to put into the register. So the code is something
>like this:

>count:=(8000000/frequency);
>port [$01B0]:=count;

>of course this will not work, becuase count has to be a real number to be
>output to a port. The rest of the code I've written makes sure that
>frequency will divide my 8MHz to generate an integer which will work with
>the register.

>Can anyone help me with the code to convert the count variable in real to
>another variable which is a byte variable??

>If someone can help I would be very grateful,
>Thank you for your time,
>Richard Webb
>ICQ:  10634107

Re:Real number to integer to byte help!!!


JRS:  In article <8a38e8$i0...@supernews.com> of Tue, 7 Mar 2000
15:46:34 in news:comp.lang.pascal.misc, Richard Webb

Quote
<rdw...@nildram.co.uk> wrote:
>I hope someone can help me!

>I have designed an ISA card for a PC and I am trying to program it in TP7.
>(You may remember a post I made a while ago). I've tested the card, and
>manufactured a final version with a few improvements. I am now writing the
>final software for it.

>The problem I have is with using real numbers. I need to put a count into a
>register on the card (a byte). I need to get a frequency from the user in
>kHz. Then divide this number by 8000000 (The 8MHz reference clock on the
>card) to get the count to put into the register. So the code is something
>like this:

>count:=(8000000/frequency);
>port [$01B0]:=count;

>of course this will not work, becuase count has to be a real number to be
>output to a port. The rest of the code I've written makes sure that
>frequency will divide my 8MHz to generate an integer which will work with
>the register.

In this newsgroup, you need to specify the version of Pascal you are
using.  That fragment looks like Turbo/Borland, for which the right
group is c.l.p.borland.

You have the choice of Round and Trunc - see the manuals, or the on-line
help.  You should validate the user's request for range, since otherwise
if the input frequency is too small bad things will happen.

You should not, of course, be using the standard TP/BP real type
nowadays, except under special circumstances (which you may have) - see
my pas-real.htm.

--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
 <URL: http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
 <URL: ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ;
 <URL: http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b. mFAQ.

Re:Real number to integer to byte help!!!


Sorry for the confusion, I'm not much of a programmer! I've sorted the
problem (see other post). I am using TurboPascal7 for the code. The reason
I'm using the real type is because this software is going to be used as the
brains of an autonomous robot. The main robot brain is the motherboard out
of an ancient PC, hence the use of the real type.

Sorry for the lack of info, I didnt realise I needed to include it!
Thanks
Richard Webb
ICQ:  10634107

Quote
Dr John Stockton wrote in message <6UhyJ+UrFYx4E...@merlyn.demon.co.uk>...
>JRS:  In article <8a38e8$i0...@supernews.com> of Tue, 7 Mar 2000
>15:46:34 in news:comp.lang.pascal.misc, Richard Webb
><rdw...@nildram.co.uk> wrote:
>>I hope someone can help me!

>>I have designed an ISA card for a PC and I am trying to program it in TP7.
>>(You may remember a post I made a while ago). I've tested the card, and
>>manufactured a final version with a few improvements. I am now writing the
>>final software for it.

>>The problem I have is with using real numbers. I need to put a count into
a
>>register on the card (a byte). I need to get a frequency from the user in
>>kHz. Then divide this number by 8000000 (The 8MHz reference clock on the
>>card) to get the count to put into the register. So the code is something
>>like this:

>>count:=(8000000/frequency);
>>port [$01B0]:=count;

>>of course this will not work, becuase count has to be a real number to be
>>output to a port. The rest of the code I've written makes sure that
>>frequency will divide my 8MHz to generate an integer which will work with
>>the register.

>In this newsgroup, you need to specify the version of Pascal you are
>using.  That fragment looks like Turbo/Borland, for which the right
>group is c.l.p.borland.

>You have the choice of Round and Trunc - see the manuals, or the on-line
>help.  You should validate the user's request for range, since otherwise
>if the input frequency is too small bad things will happen.

>You should not, of course, be using the standard TP/BP real type
>nowadays, except under special circumstances (which you may have) - see
>my pas-real.htm.

>--
>? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00
MIME. ?
> <URL: http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics &
links;
> <URL: ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal
FAQ;
> <URL: http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b.

mFAQ.

Other Threads