LCD formatting...

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
rubenpena
Registered User
Registered User
Posts: 32
Joined: Sun Mar 25, 2007 2:07 am
Location: Monterrey,Mexico

LCD formatting...

Post by rubenpena » Mon Nov 24, 2008 9:51 pm

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.

User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

Post by Steven » Mon Nov 24, 2008 10:52 pm

I think

LCD.WriteAt (1, 1, BinToStr(Switches))

should work fine, as you suggest - nothing else should be needed and no need to dim an extra string to hold it.

rubenpena
Registered User
Registered User
Posts: 32
Joined: Sun Mar 25, 2007 2:07 am
Location: Monterrey,Mexico

LCD formatting...

Post by rubenpena » Mon Nov 24, 2008 11:53 pm

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.

rubenpena
Registered User
Registered User
Posts: 32
Joined: Sun Mar 25, 2007 2:07 am
Location: Monterrey,Mexico

LCD formatting...

Post by rubenpena » Tue Nov 25, 2008 12:08 am

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.

User avatar
Jason
Posts: 50
Joined: Mon Mar 10, 2008 1:10 pm
Location: Australia

Post by Jason » Wed Nov 26, 2008 6:42 pm

If 5 were the value of a variable called cal for example, I think you can use this..

LCD.WriteAt(1,1,BintoStr(cal,8))

8 being the decimal places displayed

rubenpena
Registered User
Registered User
Posts: 32
Joined: Sun Mar 25, 2007 2:07 am
Location: Monterrey,Mexico

LCD formatting...

Post by rubenpena » Thu Nov 27, 2008 12:33 am

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.

rmteo
Posts: 237
Joined: Fri Feb 29, 2008 7:02 pm
Location: Colorado, USA

Post by rmteo » Thu Nov 27, 2008 12:52 am

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:

User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

Post by Steven » Thu Nov 27, 2008 7:40 am

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

rubenpena
Registered User
Registered User
Posts: 32
Joined: Sun Mar 25, 2007 2:07 am
Location: Monterrey,Mexico

LCD FORMATTING

Post by rubenpena » Thu Nov 27, 2008 8:39 am

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.

rubenpena
Registered User
Registered User
Posts: 32
Joined: Sun Mar 25, 2007 2:07 am
Location: Monterrey,Mexico

LCD formatting...

Post by rubenpena » Sat Nov 29, 2008 7:25 pm

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.

Post Reply