Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:01 29 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Micromite beta 7

     Page 6 of 7    
Author Message
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2817
Posted: 12:09am 27 Feb 2014
Copy link to clipboard 
Print this post

Potential Bug

All,

While writing a simple demo for a flashing cursor I think I have uncovered a firmware bug. Please can you try the following to help Geoff pinpoint any issue.

As of yet I am not sure if the bug is related to variable naming, or with the LCD command, or something else.

The 'test' program to use simply scrolls an 'X' from left to right from top to bottom of an lcd.
I am using a 4x20 lcd.

First try this:

LCD INIT 2,3,4,5,24,25 ' note I am using pins 24 & 25
LCD CLEAR
LCD 1,1,"Hello" ' just to confirm LCD connected ok

For y=1 to 4 ' four lines - ADJUST to suit your lcd
For x = 1 to 20 ' 20 chars per line - ADJUST for your lcd
LCD y,x,"X" ' display 'X' at current x,y position
Pause 200 ' bit of a delay
LCD CLEAR ' clear screen, - NOT efficient but this is only for test purpose!

Next x ' left to right first
Next Y ' then next line down


The above should work ok.
Now replace 'y' variable with 'CuLine'. Run and should be ok
Next replace 'x' variable with CuPos. Run and doesn't scroll across (but no error)
Next replace 'CuPos' variable to 'C'. Run and get an Invalid Syntax

Going further, I can use 'C' as the variable name for the Line Pointer without an Invalid Syntax but not for Character position. So LCD C,x,"X" works ok but LCD y,C,"X" does not work???

Summary at the moment is I can't use the LCD command with a variable beginning with the letter C for the Character position. If I just use C or c I get a Syntax error. If I have a variable beginning with c or C then it has a value of zero in the LCD command without giving an error.

Hope we can get to the bottom of this


For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2817
Posted: 12:44am 27 Feb 2014
Copy link to clipboard 
Print this post

Update to previous post.

Only the letter C (upper or lower case) gives the issue for the character position. I have tried all other letters.

For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 01:35am 27 Feb 2014
Copy link to clipboard 
Print this post

Phil,
The 'C' issue is probably because of the optional 'clear' commands in the 'pos' position as per Geoff's manual.

LCD line, pos, text$

'pos' can also be C8, C16 or C20 in which case the line will be cleared and
the text centred on a 8 or 16 or 20 line display (eg, LCD 1, C16, "Hello").
LCD CLEAR will erase all data displayed on the LCD and LCD CLOSE
will terminate the LCD function and return all I/O pins to the not configured
state.


Jim,
using your line;
LCD 1, 2, "Distance"+chr$(15)

I get a solid Chinese-looking character displayed - it's probably a different font set for this controller. The ASCII character shown in my table for chr$(15), (i.e. TZ's 0x0F) is the S1 control character. Is that what's usually used to flash a cursor?

David,
I think it's a font set issue. I get the normal "_" for chr$(95), but 'Chinese' looking characters for 15 and 127 - the latter is the full 'block' character in my table.

I'll have a go at running through them all and see what happens

Greg

 
vasi

Guru

Joined: 23/03/2007
Location: Romania
Posts: 1697
Posted: 01:53am 27 Feb 2014
Copy link to clipboard 
Print this post

An LCD model can have many variations (differentiated by a letter in the name) because of the different character set inside (always look in the datasheet before deciding which one to buy).
Hobbit name: Togo Toadfoot of Frogmorton
Elvish name: Mablung Miriel
Beyound Arduino Lang
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 01:54am 27 Feb 2014
Copy link to clipboard 
Print this post

@Greg

LCD 1, 2, "Distance"+chr$(15)


I'm not sure why you are trying to write a control byte after the string (or at any time).

The only way you can flash the cursor is to send an appropriate cursor command and uM Basic can not do that - only by writing code to manipulate all the pins as required. The uM set up for LCD is very basic but usually enough for most data displays. If you want fancy, then you have to use a hard wired LCD or one that uses i2c, spi etc.

The chr$(95) is an underscore, 127 is a hollow square but 15 is a control character and is not supported in ascii characters (at least not according to my old micro educational (from the early 80's)) data reference catalogue).
David M.
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3196
Posted: 02:24am 27 Feb 2014
Copy link to clipboard 
Print this post

The 'C' issue for pos in the LCD command is caused by me trying to be smart and not executing it correctly

As pacman pointed out C16, C20, etc will centre the text - but what I did is just checked if the first letter of pos was C and if it was, treat the rest as a number. In the next beta I will make it much more specific and look just for C18, etc and treat anything else as a variable.

Thanks Phil for pointing out the bug.

Geoff
Geoff Graham - http://geoffg.net
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2817
Posted: 02:40am 27 Feb 2014
Copy link to clipboard 
Print this post

I know there are many ways to achieve a flashing cursor, but a simple 'non bit-banging' way is as follows.
This is a highly configurable cursor program which can be stripped down to requirements:

'set cursor parameters . . . .
yCu = 1 'cursor position - here on first line
XCu = 3 'cursor position - here at third character position
CuOn$ = Chr$(95) 'underscore character for my particular lcd. This will vary between lcds. Choose whatever character you like
CuOff$ = " " 'doesn't have to be a blank character
CuTiOn = 600 'Time in mS that cursor is on for (showing CuOn$ character defined above)
CuTiOff = 300 'Time in mS that cursor shows the CuOff$ character)
CuState = 1 'whether cursor is current showing CuOn$ (if 1) or CuOff$ (if 0)

'initialise lcd
LCD INIT 2,3,4,5,23,24
LCD CLEAR

'use these two lines whenever you need to display a cursor (part of Main Program)
SETTICK CuTiOn,CuFlash,4 'use SetTick No 4
LCD yCu,xCu,CuOn$ 'initially show CuOn$

Do
' Main Program here
Loop

'interrupt called to toggle/flash cursor
CuFlash:
If CuState = 1 then
LCD yCu,xCu,CuOff$ 'now need to show CuOff$
SETTICK CuTiOff 'adjust interrupt time to delay CuTiOff
CuState=0 'need this to toggle state next time interrupt occurs
else
LCD yCu,xCu,CuOn$ 'now need to show CuOn$
SETTICK CuTiOn 'adjust interrupt time to delay CuTiOn
CuState=1 'need this to toggle state next time interrupt occurs
endif
ireturn


The above looks more complicated than it really is. Simply configure the required cursor parameters, then interrupt automatically calls the single Toggle sub 'CuFlash'.

NOTE: when displaying data on the lcd, you need to disable interrupt with SETTICK 0,0,4. Then after displaying your data then update cursor position (xCu & yCu) then re-enable interrupt.

Hope this helps some of you . . . .

For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2817
Posted: 02:44am 27 Feb 2014
Copy link to clipboard 
Print this post

the last two SETTICK command in my last post should read:

SETTICK CuTiOff,CuFlash,4
.
.
.
SETTICK CuTiOn,CuFlash,4

(end got chopped off somehow!

For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 03:22am 27 Feb 2014
Copy link to clipboard 
Print this post

Geoff,
I noticed when I was using 'C20' that the command gave an error if the text$ parameter wasn't entered, i.e. at least a null character "", because you just wanted to clear the line - is that how you wanted it?

Also, the 'text$' centering when using the C20 option is handy, but being able to indicate that it should be left justified would be even handier e.g. maybe 'C20L" or some-such. The reason is that if you don't want it centered, either two commands are needed, the C20 clear + the normal LCD write, or else just one normal 'pos' LCD command needs to be issued but with all trailing spaces being counted and appended to text$ out to the full line length - so that possible previous characters past the new text, aren't left displayed.

Greg
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 03:45am 27 Feb 2014
Copy link to clipboard 
Print this post

Phil,
Thanks for that, I'll check it out after some sleep. It looks a bit like my basic effort earlier but more generic and using only one SETTICK instead of two.

Mobi,
TZ's comment about just writing a 0x0F (i.e. chr$(15)) to get a flashing cursor would be a dead simple way to do it - if it worked with Geoff's very handy new 'simple' LCD command. I suspect it doesn't without 'controlling-the-pins' code but that's what he implied and he hasn't gotten back to us yet (hope he's not being shot at over there!)

Greg
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3196
Posted: 04:24am 27 Feb 2014
Copy link to clipboard 
Print this post

If you wanted some special feature of your LCD (such as flashing cursor) and you wanted to use my "simple" function you could always send the codes to the display after the LCD INIT command.

You would need to drive the data lines yourself but it would work because the LCD display command does not override the configuration of the LCD which is done by LCD INIT.

Geoff
Geoff Graham - http://geoffg.net
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3196
Posted: 04:34am 27 Feb 2014
Copy link to clipboard 
Print this post

  paceman said  I noticed when I was using 'C20' that the command gave an error if the text$ parameter wasn't entered, i.e. at least a null character "", because you just wanted to clear the line - is that how you wanted it?

That is correct, the LCD command needs all three parameters, even if the last is an empty string.

Not sure about adding a right justify option. How often would it be needed? And it could be done with:
LCD 1, 21 - LEN(txt$), txt$
To right justify on a 20 line display.

Geoff
Geoff Graham - http://geoffg.net
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2817
Posted: 04:51am 27 Feb 2014
Copy link to clipboard 
Print this post

Hi Greg,

Regarding justified text on LCD, I do like your suggestion, however, I would tend to code this with simple logic rather than having numerous justified commands to learn.

I think the ability to centre text on a blank line is useful (i.e. the C20 type command), but that anything else starts to get messy. The reason I say this is that not all text would want the line cleared first i.e. you may want to display the time right justified but leave whatever was on the line beforehand in place (rather than then having to redraw any required data again.) So do you then have justified commands with additional parameter dictating whether the line is cleared first or not?

Anyway - I use the following code (for a 4x20 character lcd):

Message$="Required string to be displayed!" 'can be blank without any error

'left justified on blank line:
m$=Left$(Message$,20)
LCD 1,1,m$+String$(20-Len(m$)," ")


'left justified without clearing line
m$=Left$(Message$,20)
LCD 2,1,m$


'right justified on blank line
m$=Right$(Message$,20)
LCD 3,1,String$(20-len(m$)," ")+m$


'right justified without clearing line
m$=Right$(Message$,20)
lcd 4,21-Len(M$),m$


The above is pretty bullet-proof i.e. can handle empty string, or over length string. And you can always call these as subs depending on amount of justified data you need to display.


Phil



For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 06:12am 27 Feb 2014
Copy link to clipboard 
Print this post

hi Greg,

It is pretty quiet around here, only the protesters are busy (brave souls to fight a corrupt government)

The 0x0f code i used often with lcd's and most of them showed a blinking solid block cursor after that.
Using the LCD command will not work because it is then send as data and can be anything depending on the font that is used.
I will have to setup a uMite with an LCD and try it. might get it done over the weekend, as i am pretty busy at the moment.
Microblocks. Build with logic.
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2350
Posted: 06:55am 27 Feb 2014
Copy link to clipboard 
Print this post

  Geoffg said  As pacman pointed out C16, C20, etc will centre the text - but what I did is just checked if the first letter of pos was C and if it was, treat the rest as a number. In the next beta I will make it much more specific and look just for C18, etc and treat anything else as a variable.


geoff - instead of detecting specific sequences of characters ("C16", etc) have you ever thought of defining these as numeric constants with a value that is either outside the valid input range of the function, or even a value that is 'not a number'. as an simple example, define C8=1008, C16=1016, C20=1020.

the logic behind detecting and acting upon these special-case commands within the interpreter may well be easier to implement, and possibly end up use less code space. if applied to the rest of MMbasic, this may be a way to squeeze out a few hundred more bytes of flash space.


for those wondering, the 'not a number' i refer to above is the (usually small) range of bit sequences that can be stored into a variable, but that do not translate into a valid number. examples may include numbers where the stored mantissa is zero, but the exponent is non-zero. variables holding such a bit sequence (strictly speaking it can not be called a 'value') may cause an interpreter to throw up an error, or produce unexpected behaviour. if suitably trapped, they can also be used to good purpose to implement special behaviour.


rob :-)Edited by robert.rozee 2014-02-28
 
vasi

Guru

Joined: 23/03/2007
Location: Romania
Posts: 1697
Posted: 07:29am 27 Feb 2014
Copy link to clipboard 
Print this post

The parsing problem will remain
Hobbit name: Togo Toadfoot of Frogmorton
Elvish name: Mablung Miriel
Beyound Arduino Lang
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 12:06pm 27 Feb 2014
Copy link to clipboard 
Print this post

I agree with Geoff. If you want to access LCD function commands, then write a few routines to send commands and/or data to the LCD using the wiring configuration that you selected for the uM LCD. I think Viscomjim did this a few posts ago?

Mind you, I think this is a bit of a storm in a teacup as Geoff's LCD commands are more then adequate for nearly all purposes. Only if you want say, a scrolling display would you need anything more.

If anyone wants to convert their blank LCD to I2c, I can send the source or hex file provided you have pickit programmer or similar and can programme a 16F88 (or 16F1503 or 16F819). Once hooked up to the i2c bus, the world is your oyster. Wiring on a bit of vero board is dead simple.


David M.
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 02:53pm 27 Feb 2014
Copy link to clipboard 
Print this post

  Geoffg said   If you wanted some special feature of your LCD (such as flashing cursor) and you wanted to use my "simple" function you could always send the codes to the display after the LCD INIT command.
You would need to drive the data lines yourself but it would work because the LCD display command does not override the configuration of the LCD which is done by LCD INIT. Geoff

Oh right! - I just assumed that that wouldn't be an option after using the new config and display commands. That leaves two good options, either the turn-on/off one using SETTICK or this one you've suggested. Either way it can be set up as a subroutine.

  Geoffg said   Not sure about adding a right justify option. How often would it be needed? And it could be done with:
LCD 1, 21 - LEN(txt$), txt$
To right justify on a 20 line display.
Geoff

I think left justify would be used more than centering and a lot more than right justify. Your suggestion here is pretty easy though too - I should have thought of that. No point using tight firmware space when the Basic answer is simple as you've often pointed out. Phil's got a good 'justify' set in his post.

GregEdited by paceman 2014-03-01
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 03:00pm 27 Feb 2014
Copy link to clipboard 
Print this post

  TZAdvantage said   Using the LCD command will not work because it is then send as data and can be anything depending on the font that is used.
I will have to setup a uMite with an LCD and try it. might get it done over the weekend, as i am pretty busy at the moment.

That's what I thought. Don't put more time into it, we've got two good options now.
Edited by paceman 2014-03-01
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 03:11pm 27 Feb 2014
Copy link to clipboard 
Print this post

  WhiteWizzard said   Regarding justified text on LCD, I do like your suggestion, however, I would tend to code this with simple logic rather than having numerous justified commands to learn.
I think the ability to centre text on a blank line is useful (i.e. the C20 type command), but that anything else starts to get messy. The reason I say this is that not all text would want the line cleared first

Yes I've had exactly those issues but your group of 'justify' suggestions is great - thanks for that. They'd be a good set to go into the MMBasic library along with Geoff's one-liner!

GregEdited by paceman 2014-03-01
 
     Page 6 of 7    
Print this page
© JAQ Software 2024