LCD formatting...
Moderators: David Barker, Jerry Messina
LCD formatting...
Hi Friends:
In this advanced world of complex Glcd displays, I am almost ashamed
to ask for a simple task.
As always, is very simple when you know how. But I don't.
In a example I did see the following:
USART.Write("Hello World", 13, 10) // string
USART.Write("Binary : ", BinToStr(242), 13, 10) // binary number
USART.Write("Hex : ", HexToStr(242), 13, 10) // hex number
USART.Write("Decimal : ", DecToStr(242), 13, 10) // decimal number.
How can I do the same for a two lines LCD display.?
LCD.WriteAt (1,1 BinToStr (Switches) ' (Switches is a word)
Do I need to Dim a string for this,or it is included in the Convert.bas.?
Thanks in advance...
Ruben de la Pena V.
In this advanced world of complex Glcd displays, I am almost ashamed
to ask for a simple task.
As always, is very simple when you know how. But I don't.
In a example I did see the following:
USART.Write("Hello World", 13, 10) // string
USART.Write("Binary : ", BinToStr(242), 13, 10) // binary number
USART.Write("Hex : ", HexToStr(242), 13, 10) // hex number
USART.Write("Decimal : ", DecToStr(242), 13, 10) // decimal number.
How can I do the same for a two lines LCD display.?
LCD.WriteAt (1,1 BinToStr (Switches) ' (Switches is a word)
Do I need to Dim a string for this,or it is included in the Convert.bas.?
Thanks in advance...
Ruben de la Pena V.
LCD formatting...
Thanks Steve:
I was aware of the last missing parentesis.(Was a Typo).
My subroutine:
{
********************************************************************************
* Name : ReadSw *
* Purpouse : Read 4021's switches 2 chips for 16 bits *
********************************************************************************
}
Sub ReadSw()
Shift.SetInput(DataPin) //initialise shiftin pin
Shift.SetClock(ClockPin) //initia lise shiftin clock pin
switches = 0 'Dim as word on start
Loadpin = 1 'pulse Load
DelayUS (50)
Loadpin = 0
DelayUS (50)
switches = Shift.In(LSB_POST,16) 'I did'nt found samples of use...
End Sub
Maybe I have something wrong in my Sub.
I have the data pin as input.I make a call in my program:
readSw
LCD.WriteAt(2, 1, HexToStr(switches))
Always get a "0"... Just one digit...
Any hint...?
Thanks again...
Ruben de la Pena V.
I was aware of the last missing parentesis.(Was a Typo).
My subroutine:
{
********************************************************************************
* Name : ReadSw *
* Purpouse : Read 4021's switches 2 chips for 16 bits *
********************************************************************************
}
Sub ReadSw()
Shift.SetInput(DataPin) //initialise shiftin pin
Shift.SetClock(ClockPin) //initia lise shiftin clock pin
switches = 0 'Dim as word on start
Loadpin = 1 'pulse Load
DelayUS (50)
Loadpin = 0
DelayUS (50)
switches = Shift.In(LSB_POST,16) 'I did'nt found samples of use...
End Sub
Maybe I have something wrong in my Sub.
I have the data pin as input.I make a call in my program:
readSw
LCD.WriteAt(2, 1, HexToStr(switches))
Always get a "0"... Just one digit...
Any hint...?
Thanks again...
Ruben de la Pena V.
LCD formatting...
Hi Steven:
The display command is working OK. Then I am not reading the ShiftIn.
I set a value of $D555 to the variable "Switches" and changed to BinToStr
and I got at the display 1101010101010101.
At least I am understanding the use of the LCD options.
Another question: if the value is = 5 then I get 101 at the display. is there
any way to force to print the leading zeros.?
Thanks again...
Ruben de la Pena V.
The display command is working OK. Then I am not reading the ShiftIn.
I set a value of $D555 to the variable "Switches" and changed to BinToStr
and I got at the display 1101010101010101.
At least I am understanding the use of the LCD options.
Another question: if the value is = 5 then I get 101 at the display. is there
any way to force to print the leading zeros.?
Thanks again...
Ruben de la Pena V.
LCD formatting...
Thanks Jason:
I will try it...
My problem was more the reading of the shift registers (two 4021) to get
16 switches.
It is working now, but I needed to convert the 16 bits of my word variable
to an specific switch. (In PBP I did use the NCD (priority encoder).
Now in Swordfish,I use this solution but is not elegant or compact:
'******************************************
If switches = $0 Then
NUMBER = 0
EndIf
If switches = 1 Then
NUMBER = 1
GOTO TOCA
EndIf
If switches = 2 Then
NUMBER = 2
GOTO TOCA
EndIf
If switches = 4 Then
NUMBER = 3
GOTO TOCA
EndIf
If switches = 8 Then
NUMBER = 4
GOTO TOCA
EndIf
If switches = $10 Then
NUMBER = 5
GOTO TOCA
EndIf
If switches = $20 Then
NUMBER = 6
GOTO TOCA
EndIf
If switches = $40 Then
NUMBER = 7
GOTO TOCA
EndIf
If switches = $80 Then
NUMBER = 8
GOTO TOCA
EndIf
If switches = $100 Then
NUMBER = 9
GOTO TOCA
EndIf
If switches = $200 Then
NUMBER = 10
GOTO TOCA
EndIf
If switches = $400 Then
NUMBER = 11
GOTO TOCA
EndIf
If switches = $800 Then
NUMBER = 12
GOTO TOCA
EndIf
If switches = $1000 Then
NUMBER = 13
GOTO TOCA
EndIf
If switches = $2000 Then
NUMBER = 14
GOTO TOCA
EndIf
If switches = $4000 Then
NUMBER = 15
GOTO TOCA
EndIf
If switches = $8000 Then
NUMBER = 16
GOTO TOCA
EndIf
'*********************************************************
Any ideas for a better routine..?
Thanks again...
Ruben de la Pena V.
I will try it...
My problem was more the reading of the shift registers (two 4021) to get
16 switches.
It is working now, but I needed to convert the 16 bits of my word variable
to an specific switch. (In PBP I did use the NCD (priority encoder).
Now in Swordfish,I use this solution but is not elegant or compact:
'******************************************
If switches = $0 Then
NUMBER = 0
EndIf
If switches = 1 Then
NUMBER = 1
GOTO TOCA
EndIf
If switches = 2 Then
NUMBER = 2
GOTO TOCA
EndIf
If switches = 4 Then
NUMBER = 3
GOTO TOCA
EndIf
If switches = 8 Then
NUMBER = 4
GOTO TOCA
EndIf
If switches = $10 Then
NUMBER = 5
GOTO TOCA
EndIf
If switches = $20 Then
NUMBER = 6
GOTO TOCA
EndIf
If switches = $40 Then
NUMBER = 7
GOTO TOCA
EndIf
If switches = $80 Then
NUMBER = 8
GOTO TOCA
EndIf
If switches = $100 Then
NUMBER = 9
GOTO TOCA
EndIf
If switches = $200 Then
NUMBER = 10
GOTO TOCA
EndIf
If switches = $400 Then
NUMBER = 11
GOTO TOCA
EndIf
If switches = $800 Then
NUMBER = 12
GOTO TOCA
EndIf
If switches = $1000 Then
NUMBER = 13
GOTO TOCA
EndIf
If switches = $2000 Then
NUMBER = 14
GOTO TOCA
EndIf
If switches = $4000 Then
NUMBER = 15
GOTO TOCA
EndIf
If switches = $8000 Then
NUMBER = 16
GOTO TOCA
EndIf
'*********************************************************
Any ideas for a better routine..?
Thanks again...
Ruben de la Pena V.
Although there is nothing technically wrong with using large if…then blocks, it can sometimes be difficult to read them. The select…case statement is an alternative to using a large or multiple if…then…elseif statement. For example:
Code: Select all
select switches
case = 0 number = 0
case = 1 number = 1
'
'
'
case = $8000 number = 16
end select
TOCA:
Something like this might also help:
Code: Select all
Function GetNumber(pSwitches as Word) as Byte
Dim i as Byte
GetNumber = 0
i = 0
Repeat
Inc(i)
If pSwitches.0 = 1 Then
GetNumber = i
EndIf
pSwitches = pSwitches >> 1
Until i = 16 or GetNumber > 0
End Function
LCD FORMATTING
Thanks to RMTEO and Steven:
I will try your sugestions... I was trying something like this:
'*****************************
For index = 1 to 16
if switches.index = 1 then
button = index
goto toca
endif
next index
'*****************************
But I got several errors in the compiler and opted for the
"If then" secuences...
Greetings...
Ruben de la Pena V.
I will try your sugestions... I was trying something like this:
'*****************************
For index = 1 to 16
if switches.index = 1 then
button = index
goto toca
endif
next index
'*****************************
But I got several errors in the compiler and opted for the
"If then" secuences...
Greetings...
Ruben de la Pena V.
LCD formatting...
Hi...
Steven... your function works OK... Thanks...By the way,to address a
bit in a register we can use the expresion register.bit#,like portb.3 ,etc..
Can be the bit number a expresion like (Var.bit) or Var.var ?
Thanks again...
Ruben de la Pena V.
Steven... your function works OK... Thanks...By the way,to address a
bit in a register we can use the expresion register.bit#,like portb.3 ,etc..
Can be the bit number a expresion like (Var.bit) or Var.var ?
Thanks again...
Ruben de la Pena V.