[bascom] Multi digit Binary to BCD conversion
Hi Anders and all others
This is my first contribution to this list.
My name is Per Svensson and I run a firm in
Gothenburg (Sweden)
The company is Monolitsystem AB. We have been
developers of electronic equipment since 1987. Mostly
Instrument and high speed communication units.
Well, I saw your note regarding Bin2bcd16, and as I am
responsible for its existanse I thought I could release
Mark from some of his burdons. Can you understand, is
he ever sleeping?....:-))
Anyway I it is just a few simple lines to test the Library
routine bin2bcd16 in BcdCalc.lib. It is listed below:
I think this routine will be very useful to all you who like
me were trying to put out the value of an integer or word
on a scanning multidigit LED-display.
Lets say that you have the five digit decimal value
12345. Moving that to the display would present 3039
instead of 12345. There is no way for you to efficiently
do this conversion in Basic. That's why I wrote it.
It runs a conversion in 761 to 768 clock cycles on an
AVR 90Sxxxx (The algorithm originates from one of
Atmels appnotes)
Regards
Per Svensson
Monolitsystem AB
'***************************************************************
*****************
'define external user library
$lib "BCDcalc.lib"
'also define the used routines in BCDcalc.lib
$external Bin2bcd16
'this is needed so the parameters will be placed correct
on the stack
Declare Function Bin2bcd16(binval As Word) As Long
Dim A As Long 'Result could be up to five
nibbles long
Dim Temp As Word 'Sign is not supported
Temp = 12345 'Not more than five digits will fit
into a word.
A = Bin2bcd16(temp) 'The result is 0001 2345
(longword)
End
'***************************************************************
**************
----- Ursprungligt meddelande -----
Från: ANDERS LØVSTAD <anders.lovstad@c2i.net>
Till: <bascom@grote.net>
Skickat: den 14 november 2000 22:33
Ämne: SV: [bascom] New BASCOM-AVR version
> Hi Mark,
> Thanks for the new version!
> I'd like the TIME$ ,DATE$ functions very mutch , but I
could'nt find the samplefile megaclock.bas.
> Also the bin2bcd16.bas sample was missing.
> The two files are mentioned in History.txt ,but are
missing in the Sample.zip.
>
> Could you please upload a new sample.zip?
>
> Kind regards
> Anders Løvstad
> Norway.