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.

Print leading zeros on LCD

Status
Not open for further replies.

NevM

New Member
I output large numbers, eg, 3000000 to my LCD. I want to format with zeros ie 3,000,000. I've figured out how to split the number in to groups of three digits and display.
lcdout #part1,",",#part2,",",#part3
This outputs 3,0,0.
Any suggestions to pad out numbers <100 with leading zeros?
Thanks.
 
Write a function.... Its called right justified

This is mine... Remember I print to a buffer... Also I put spaces as I don't like leading zero's.

Code:
'fill in display values
'------------------------
Proc fillbuffer(value As Long, posn As Byte)
		longindex = 1000000
		For index = posn To posn+6
			data = value / longindex
			scrbuff(index) = data + 48
			value = value - (longindex * data)
			longindex = longindex / 10
		Next index
			scrbuff( index) = (value Mod 10) + 48
		For index = posn To posn + 6
			If scrbuff(index) > 0x30 Then Goto spacesdone
			scrbuff(index) = 0x20
		Next index

spacesdone:
				
End Proc

***NOTE*** this may need modifiying to you requirements.
 
Last edited:
NevM said:
Any suggestions to pad out numbers <100 with leading zeros?

Yep, if the number is <100 add 1000, make it a string, and take the right 3 characters. e.g. 12 becomes 1012 and the right 3 characters are 012.
 
Sneaky idea, but is it possible with Oshonsoft? I'm not aware of any string manipulation functions.
 
Sneaky idea, but is it possible with Oshonsoft? I'm not aware of any string manipulation functions.

hi,
This is for Oshonsoft basic, by using an ASCII bfr you can display or RS232 data

Code:
Dim b2avall As Byte
Dim b2avalm As Byte
Dim b2avalh As Byte

'buffers for the converted bin to ASCII
Dim ascbfr7 As Byte
Dim ascbfr6 As Byte
Dim ascbfr5 As Byte
Dim ascbfr4 As Byte
Dim ascbfr3 As Byte
Dim ascbfr2 As Byte
Dim ascbfr1 As Byte
Dim ascbfr0 As Byte

Dim temp1 As Byte
Dim temp2 As Byte
Dim cntr1 As Byte
Dim cntr2 As Byte

TestLoop: ' load dummy test value
b2avall = TMR1L  'load your low Byte
b2avalm = TMR1H ' load your middle Byte
b2avalh = tmr1_cnt ;load your high Byte

Gosub bin2asc   ' call 24 Bin to 8 ASCII subr

Lcdcmdout LcdLine1Home ' display contents of ASCII brs
Lcdout ascbfr7, ascbfr6, ascbfr5, ascbfr4, ascbfr3, ascbfr2, ascbfr1, ascbfr0,
WaitMs 500
Goto  TestLoop


'convert 24bit bin To 8 asci in ascbfr0
bin2asc:
ASM:        clrf ascbfr7
ASM:        clrf ascbfr6
ASM:        clrf ascbfr5
ASM:        clrf ascbfr4
ASM:        clrf ascbfr3
ASM:        clrf ascbfr2
ASM:        clrf ascbfr1
ASM:        clrf ascbfr0
ASM:        movlw .24
ASM:        movwf temp1
bitlp2:
ASM:        rlf b2avall,F
ASM:        rlf b2avalm,F
ASM:        rlf b2avalh,F
ASM:        movlw ascbfr0
ASM:        movwf FSR
ASM:        movlw 0x8
ASM:        movwf temp2
adjlp2:
ASM:        rlf INDF,F
ASM:        movlw 0x0a
ASM:        subwf INDF,W
ASM:        btfsc STATUS,C
ASM:        movwf INDF
ASM:        decf FSR,F
ASM:        decfsz temp2,F
Goto adjlp2
ASM:        decfsz temp1,F
Goto bitlp2

ASM:        movlw 0x30
ASM:        iorwf ascbfr7,F
ASM:        iorwf ascbfr6,F
ASM:        iorwf ascbfr5,F
ASM:        iorwf ascbfr4,F
ASM:        iorwf ascbfr3,F
ASM:        iorwf ascbfr2,F
ASM:        iorwf ascbfr1,F
ASM:        iorwf ascbfr0,F

'' this section I use for leading Zero supression
'in your project load whatever symbols you need
If ascbfr7 = 0x30 Then
ascbfr7 = 0x20
Else
Goto skipz
Endif
If ascbfr6 = 0x30 Then
ascbfr6 = 0x20
Else
Goto skipz
Endif
If ascbfr5 = 0x30 Then
ascbfr5 = 0x20
Else
Goto skipz
Endif
If ascbfr4 = 0x30 Then
ascbfr4 = 0x20
Else
Goto skipz
Endif
If ascbfr3 = 0x30 Then
ascbfr3 = 0x20
Else
Goto skipz
Endif
If ascbfr2 = 0x30 Then
ascbfr2 = 0x20
Else
Goto skipz
Endif
If ascbfr1 = 0x30 Then
ascbfr1 = 0x20
Endif
	

skipz:
Return
 
Many thanks Eric. Your code is going to take a little thought on my part as I'm new to this PIC programming. Up until now I've managed to avoid ASM, so thanks! :) FYI my first project is controlling an AD9835. It all works fine and all that's left is to tidy up the LCD.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top