Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Formatting issue with number

Status
Not open for further replies.

jnilo

New Member
I have two numbers that can vary between 1 and 22. Whenever any of the two is comprised between 1 and 9 I would like to pad them with a zero e.g.
01/22 or 01/09 so that my result is always displayed at the same place. I cannot find a num to char conversion function. Any trick to suggest ? (I could have four different lcdout statements according to the different values of my two numbers but it seems a bit cumbersome...)
Thanks
Jacques
 
Oshonsoft doesn't cover any formatting of that nature... You need your own integer to ASCII routine ..

Its dead simple..

Assume the number is always 4 digits long ( if not you will have to adjust )
What you are looking for is right align!!

Here is mine
Code:
Sub PrintNumb( value as word)
    dim temp as word
    temp = value / 1000
    Lcdout #temp
    temp = ( value /  100 ) MOD 10 
    Lcdout #temp
    temp = (value / 10 ) MOD 10 
    Lcdout #temp
    temp =  value  MOD 10 
    Lcdout #temp
End Sub
I haven't tested this... Its just so you get the idea!!
 
Nice trick ! The correct code for oshonsoft using sub is:
Code:
printnumb:
  Dim temp As word
  temp = value / 1000
  Lcdout #temp
  temp = (value / 100) Mod 10
  Lcdout #temp
  temp = (ii / 10) Mod 10
  Lcdout #temp
  temp = ii Mod 10
  Lcdout #temp
Return
Thanks !
Jacques
 
Look under Oshonsoft snippets
https://www.electro-tech-online.com/threads/code-snippets-for-the-oshonsoft-basic-compiler.112540/


Code:
Dim ascbfr3 As Byte  'used in convert routing
Dim ascbfr2 As Byte  'used in convert routing
Dim ascbfr1 As Byte  'used in convert routine
Dim ascbfr0 As Byte  'used in convert routine

binval = volts
Gosub bin2asc

bin2asc:
ascbfr3 = binval / 1000
temp3 = binval Mod 1000
ascbfr2 = temp3 / 100
temp3 = temp3 Mod 100
ascbfr1 = temp3 / 10
ascbfr0 = temp3 Mod 10
'results are BCD so
'convert to ASCII for LCD
ascbfr3 = ascbfr3 Or 0x30
ascbfr2 = ascbfr2 Or 0x30
ascbfr1 = ascbfr1 Or 0x30
ascbfr0 = ascbfr0 Or 0

' and to show on a lcd after it is set up

Lcdout "Volts:", ascbfr3, ascbfr2, ".", ascbfr1, ascbfr0

'this will put a decimal point in and the example shows a voltage reading to 2 decimal places
 
Ian, Eric: thanks to both of you. In my case the following code works perfectly, j1 and j2 being the two bytes variables comprised between 1 and 22. It seems that I do not need the or x 30 mask. All variables are declared as bytes.
j11 = j1 / 10
j10 = j1 Mod 10
j21 = j2 / 10
j20 = j2 Mod 10
Lcdout #j11, #j10, "/", #j21, #j20
Jacques
 
Status
Not open for further replies.

Latest threads

Back
Top