Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Can I/How do I program the the old basic printchr$() with Oshon Basic.
Very gratefrul for any help.
Jack G8LII
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
If you just want to to clear a 'trailing' digit, this is a simple method I use.=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".
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