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 chr$()

Status
Not open for further replies.

g8lii

New Member
Can I/How do I program the the old basic printchr$() with Oshon Basic.

Very gratefrul for any help.

Jack G8LII
 
Can I/How do I program the the old basic printchr$() with Oshon Basic.

Very gratefrul for any help.

Jack G8LII

hi,
Are you trying to display to an LCD, if yes, its Lcdout "nnnnn" or Lcdout #1000 for a number
 
Formatting values on the LCD

Is it possible to format number for display on the LCD. So if I have say a 3 digit number "999" generated from an analog input and then want to over-write it with a 2 digit number "99", how do I pad it with a space to clear the trailing "9".

I am using the #analog_value to get it on the screen.

Currently I am doing it very long windedly with if statements...if analog_value > 100 then send some padding.

So...sort of like a FORMAT command?

Any suggestions?

Cheers

Roo
 
I use my own function to format as there isn't one available... I just create a format function.
( I use a screen buffer )
Code:
Proc format(value As Long, pos As Byte, deci As Byte)
	index2 = pos + 2
	l_index = 10000
	For index1 = pos To index2
		data = (value / l_index) Mod 10
		scrbuff(index1) = data + 48
		value = value - (l_index * data)
		l_index = l_index / 10
	Next index1
	If deci > 0 Then
		scrbuff(index1) = 0x2e
		index1 = index1 + 1
	Endif
	scrbuff(index1) = (value / l_index) Mod 10 + 48
	index1 = index1 + 1
	scrbuff(index1) = 0x20
	If deci = 2 Then scrbuff(index1) = value Mod 10 + 48
	index2 = index2 - 1
	For index1 = pos To index2
		If scrbuff(index1) > 48 Then Goto spaces_done
		scrbuff(index1) = 0x20
	Next index1
spaces_done: 			
End Proc

Oh yeah.. this is right justified.. you'll need to change it for left justified.
 
Last edited:
=rupert_powell;1021893]Is it possible to format number for display on the LCD. So if I have say a 3 digit number "999" generated from an analog input and then want to over-write it with a 2 digit number "99", how do I pad it with a space to clear the trailing "9".
If you just want to to clear a 'trailing' digit, this is a simple method I use.
Lcdout "adc0: ", #adcv0, " "

If you want a fixed length string, with leading zero's not suppressed, this worksOK
Code:
Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 4
Define LCD_RSREG = PORTA
Define LCD_RSBIT = 4
Define LCD_EREG = PORTA
Define LCD_EBIT = 5

Define SIMULATION_WAITMS_VALUE = 1
'------------------------------------
'setup temp variables
Dim ascbfr4 As Byte
Dim ascbfr3 As Byte
Dim ascbfr2 As Byte
Dim ascbfr1 As Byte
Dim ascbfr0 As Byte

Dim temp3 As Word
Dim binval As Word

Dim val0 As Word

'Define ADC_CLOCK = 3
'Define ADC_SAMPLEUS = 50

ADCON0 = %01000001  'adcchan0
ADCON1 = %10001011  'Dis clk div,,,an0 > an3 analaog rest dig

TRISA = %00000001
TRISB = %11111111  'all inputs on portb
TRISC = %11111111
'-----------------------------------------------------

Lcdinit

main0:
Lcdcmdout LcdClear

main:
Gosub readadc
Goto main

End                                               


readadc:
'read adc word
Adcin 0, val0

binval = 199  'val0  'rename for the bin2asc subr
Gosub bin2asc

Lcdcmdout LcdLine1Home
Lcdout "val0: ", ascbfr4, ascbfr3, ascbfr2, ".", ascbfr1, ascbfr0


Return                                            


'you can convert any binary value from 0000h to fffFh to 0000 to 65535 decimal
'just name the binary word as binval and call this subr and the ASCII
'result will be in ascbfr4,3,2,1,0, ready for your LCD or UART
'just pop the DP in the output to the LCD [as shown above]

bin2asc:
ascbfr4 = binval / 10000
temp3 = binval Mod 10000

ascbfr3 = temp3 / 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 or UART
ascbfr4 = ascbfr4 Or 0x30
ascbfr3 = ascbfr3 Or 0x30
ascbfr2 = ascbfr2 Or 0x30
ascbfr1 = ascbfr1 Or 0x30
ascbfr0 = ascbfr0 Or 0x30
Return
 
Last edited:
Thanks guys.

I was on the right track but these two functions will come in very handy.

It certainly looks like Vlad needs to add some string handling stuff. I suppose once you have some functions developed you can just re-use them...or stick em in an Include file for re-use in every project (when you need them).

INCLUDE "String_functions.bas"

Thanks again.

Roo
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top