Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:22 25 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 : New Version of MMBasic. Version 3.1

     Page 2 of 2    
Author Message
marcwolf

Senior Member

Joined: 08/06/2009
Location: Australia
Posts: 119
Posted: 04:22am 28 Jan 2012
Copy link to clipboard 
Print this post

Hi Geoff

A minor comment. With most Basic's and other languages - variables that are defined within the SUB stay in the SUB. You could use a term like GLOBAL to indicate that a variable is shared with the rest of the system..

ie

Counter(15)
print result
end

sub Counter(cnt1)
dim looper ' internal local variable
global result ' info to be returned
for looper = 0 to icnt1
If testing <> 0 then
exit for
end if
next
result = icnt
end sub


Or use the Global to indicate variables in the main program that can be shared, and any other variable are not shared.


Global result ' set up global variable
Counter(15)
print result
end

sub Counter(cnt1)
dim looper ' internal local variable
for looper = 0 to icnt1
If testing <> 0 then
exit for
end if
next
result = icnt ' update global variable
end sub



Take Care
Dave
Coding Coding Coding..
Keep those keyboards coding..
RAW CODE!!!!!
 
Bill.b

Senior Member

Joined: 25/06/2011
Location: Australia
Posts: 226
Posted: 05:09am 28 Jan 2012
Copy link to clipboard 
Print this post

Hi Geoff
defined subroutines are great. Is it possible to define as set of arguments to be returned from the defined subroutine.

If this is to be a library you would want it to be completely separated from then main program. using global variables within the subroutine would not be desirable. I am from a PLC background where when a subroutine is defined (Called) a list of variable to be passed and returned form the subroutine are defined.
i.e. if the subroutine contains an algorithm called from different stages of the program, the results may be passed to different variables in the main program.

In the interests of the environment, this post has been constructed entirely from recycled electrons.
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 09:46am 28 Jan 2012
Copy link to clipboard 
Print this post

  Bill.b said   Hi Geoff
defined subroutines are great. Is it possible to define as set of arguments to be returned from the defined subroutine.

Yes, this is called passing arguments by reference and it is described in the pdf tutorial that came with 3.1

Geoff
Geoff Graham - http://geoffg.net
 
Vikingboy
Regular Member

Joined: 23/09/2011
Location: Australia
Posts: 82
Posted: 01:22pm 28 Jan 2012
Copy link to clipboard 
Print this post

Hi,

Not sure if this should go in here or start another thread, I have a feeling there may be a simple answer, so I'll ask here.

In the new LCD.bas example using the subs, It seems it is using different pins than the previous example, which btw was compatible with the pins used on the LCD shield from Don and I believe the Arduino type LCD shields.

Problem is I changed the pins in the example to match those in the older lcd example which works, but it still is not working, Has any one else tried this and got it working, It seems there are quite a few other differences between this and the older version which is making it hard for me to trace through, I have only tried for a little while, but if anyone else has a solution I would be very interested to hear it.

thanks,

Andrew
 
djuqa

Guru

Joined: 23/11/2011
Location: Australia
Posts: 447
Posted: 01:47pm 28 Jan 2012
Copy link to clipboard 
Print this post

change the PIN numbers used by adding 2

IE pin12 becomes pin14 & So on

plus the
pause Wait_msec
statement at end needs to be changed to
Pause Wait_msec: Pause 2
I have just wired up two LCD Units using these changes
I will be submitting a full revision for inclusion in Library
VK4MU MicroController Units

 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 01:54pm 28 Jan 2012
Copy link to clipboard 
Print this post

I wrote the LCD demo and I was careful to keep the old pin numbers as per the pdf description. However, in the early days (many months ago) there was an error in the pdf which involved pin numbers which I later corrected. Are you looking at the old pdf?

BTW, I tested the new demo and it worked file. It even includes the extra 2 mS pause after initialisation.

GeoffEdited by Geoffg 2012-01-29
Geoff Graham - http://geoffg.net
 
Vikingboy
Regular Member

Joined: 23/09/2011
Location: Australia
Posts: 82
Posted: 02:12pm 28 Jan 2012
Copy link to clipboard 
Print this post

Hi,

I tried changing the pin numbers and still didnt have success, I did adjust a few other things I think also the timing delay and also in my working LCD.bas I am using 8 digital out, not 9 open collector, but I tried both ways, I will start again from scratch and see if I can work it out,

Geoff, I am looking at the lcd.bas itself, the one that works with my LCD shield use 19 and 20 as rs and en and data on 15 - 18. In the new LCD it uses 11 and 12 as rs and en and data on 13 - 16.
It also seems to handle the data transfer in a different way it only sends the 2nd 4 bit nibble, but I dont completely follow this part so I will have to examine it and try and follow it through better.

rgds,

Andrew
 
Vikingboy
Regular Member

Joined: 23/09/2011
Location: Australia
Posts: 82
Posted: 07:24pm 28 Jan 2012
Copy link to clipboard 
Print this post


OK,

It has taken me a while but I have finally got it working on my standard LCD shield now.
That was actually only about 75% of the battle, then I changed it all to use labels etc and cleaned it up, as I was working between the old version that worked and the new one thanks Geoff :)

Anyway this should now work fine for those with the Arduino shield type LCD boards, An interesting thing is that if it is set to use open collector mode it stops working and no matter how hard I tried I couldn't get the new version working by changing the pin numbers etc, Although maybe now after that learning experience I may be able to LOL.

If I have made any huge blunders etc please feel free to educate me and correct them, as you can see this uses the whole byte to send to the LCD, not sure if this was part of why the new one didn't work but I left it as is and didn't fiddle with that any more, If that would be better then please feel free.

Sorry for clipping the header information, I wasn't sure about what to put and it also saved space here, Please can someone add an appropriate header crediting Geoff and also Mick Gulovsen as he adapted it for the Arduino shield originally, if this is distributed anywhere.

hope this is useful:



InitLCD
LCDPrint 1," MAXIMITE "
LCDPrint 2," LCD DRIVER "

End


Sub InitLCD

RS=19 : EN=20 : D4=15 : D5=16 : D6=17 : D7=18 'Allocate pins

SetPin D4,8: SetPin D5,8: SetPin D6,8: SetPin D7,8 'Set to Digital out
SetPin EN,8: SetPin RS,8

LCDbyte &B0011, 0, 1 ' reset
LCDbyte &B0011, 0, 1 ' reset
LCDbyte &B0011, 0, 1 ' reset
LCDbyte &B0010, 0, 1 ' 4 bit mode

LCDbyte &B00101100, 0, 1 ' 4 bit, 2 lines
LCDbyte &B00001100, 0, 1 ' display on, no cursor
LCDbyte &B00000110, 0, 1 ' increment on write
LCDbyte &B00000001, 0, 1 ' clear display

End Sub

Sub LCDPrint ( Linenumber, Line$ )

Local X

LCDbyte &B10000000 + (Linenumber - 1) * 64, 0, 1 ' Select line 1 or 2

For X= 1 To 16

LCDbyte Asc(Mid$(Line$, X, 1)),1,5 ' send one character

Next X

End Sub

Sub LCDbyte ( Data, Flag, DELAY )

Pin(RS) = Flag 'Flag for Data or Comand

Pin(D4) = Data And &B00010000 ' output the 1st 4 bits
Pin(D5) = Data And &B00100000
Pin(D6) = Data And &B01000000
Pin(D7) = Data And &B10000000
Pin(EN) = 1 : Pause 1:Pin(EN) = 0 : Pause DELAY 'Tell LCD to accept data

' Entry point to send just 4 bits to the LCD

Pin(D4) = Data And &B00000001 ' output the 2nd 4 bits
Pin(D5) = Data And &B00000010
Pin(D6) = Data And &B00000100
Pin(D7) = Data And &B00001000
Pin(EN) = 1 : Pause 1: Pin(EN) = 0 : Pause DELAY: 'Tell lcd to accept data

End Sub


rgds,

Andrew
 
Olimex
Senior Member

Joined: 02/10/2011
Location: Bulgaria
Posts: 226
Posted: 05:57pm 29 Jan 2012
Copy link to clipboard 
Print this post

the new subroutines are really cool, Geoff how much memory do we have for code in MM3.1?

with the no numbers and subroutines will be very easy to make "libraries" for the different UEXT modules

I'm thinking if it's possible to move this idea one step forward and make something like loadable BASIC language subroutines?

something like the USES CRT, DOS, etc it was available in Turbo Pascal in the old time.

at the beginning of your code you write:

USES LCD.LIB

for instance and this BASIC code is loading from the sd-card at the end of the BASIC program but is not LIST-able so not make all code huge and distract the readability

and to remove from memory with

REMOVE LCD.LIB

and load other code:

USES GSM.LIB

this way you can load dynamically libraries and work around the limited code memory we have for programming
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 11:28pm 29 Jan 2012
Copy link to clipboard 
Print this post

At this time it is 30K. The rest of memory is taken up with the video buffer, variables and space for arrays, etc (all necessary for the program to run).

It is simplistic to look at just program memory. Usually a program will run out general memory first which is why so much memory is allocated to that task rather than just holding the code. Anyway, I have been slowly moving towards dynamic memory management which would make the whole issue irrelevant.

Yes, one of the big benefits of getting rid of line numbers is that it is easier to load a hunk of code (and discard it). I like the USE/REMOVE idea and it would not be hard to implement.

... and work around the limited code memory we have for programming

Has anyone run out of program memory?

Please speak up if you have as it would give me an incentive to implement dynamic memory management. The only example that I heard of was someone who tried to code a lot of the user manual as PRINT statements and no amount of memory management could accommodate that.

Geoff

Geoff Graham - http://geoffg.net
 
Gizmo

Admin Group

Joined: 05/06/2004
Location: Australia
Posts: 5078
Posted: 12:15am 30 Jan 2012
Copy link to clipboard 
Print this post

I write a lot of stuff in ASP using VBscript, and use the INCLUDE command to include other scripts into the current script.

For example, most ASP pages, like this forum, retrieveve data from a database. So at the top of each page there may be a command like

include file="DatabaseConnection.asp"

The DatabaseConnection.asp file is just another chunk of script, that makes connection to the database, and has a bunch of other common functions that may be called as needed. When the web server interpretor sees a INCLUDE command, it loads up the external file into that location within the main script, and executes it in order.

Its like a MERGE file$, but happens on the fly.

GlennEdited by Gizmo 2012-01-31
The best time to plant a tree was twenty years ago, the second best time is right now.
JAQ
 
djuqa

Guru

Joined: 23/11/2011
Location: Australia
Posts: 447
Posted: 12:39am 30 Jan 2012
Copy link to clipboard 
Print this post

sounds great, can't wait! Mate
VK4MU MicroController Units

 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 01:47am 30 Jan 2012
Copy link to clipboard 
Print this post

I'm checking lcd.bas and getting an odd result.
Initialise takes 34418 msecs
Set cursor takes 8599 msecs
Line 1 takes 137549 msecs
Set cursor takes 8600 msecs
Line 2 takes 137548 msecs

There's a lot of consistency in the times taken to display each line and set the cursor.

Each nibble takes 4297 mSecs.

I replaced the Pause Wait_mSec statement in the LCD_Nibble Sub with Pause 2, and the program completes in normal time, each nibble taking 2 msecs.

I replaced Pause Wait_mSec with Pause 0 and each nibble still took 4297 mSecs.

This leads me to conclude that there is a problem on my system and my lcd setup and version 3.1 with the command Pause 0.

Has anyone else had a similar problem? If they have, I'll report it as a bug.

Thanks,

James
My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
djuqa

Guru

Joined: 23/11/2011
Location: Australia
Posts: 447
Posted: 02:58am 30 Jan 2012
Copy link to clipboard 
Print this post

same here I found the Pause Statement had to be hardwired .
I have 2 LCD 8x2 Units running using Pin(13)for RS and Pin(15)-Pin(18) as Data (parallel connected)
Unit 1 uses Pin(14) for EN and Unit 2 uses Pin(5) for EN
All pins are set AS Digital Output not OPEN DRAIN (correct term used in MicroChip documentation, as the output stages use FETS)

Edited by djuqa 2012-01-31
VK4MU MicroController Units

 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 03:28am 30 Jan 2012
Copy link to clipboard 
Print this post

Damn, there is a bug in PAUSE 0

In the meantime you will have to change the line in LCD_Nibble to:
if Wait_mSec > 0 Then Pause Wait_mSec


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

Regular Member

Joined: 19/06/2011
Location: Australia
Posts: 64
Posted: 09:32am 30 Jan 2012
Copy link to clipboard 
Print this post

  Gizmo said   I think if the new MMBAsic can use libraries, then thats covered. The SHOWBMP.BAS program included with the sample files could be used as a defined subroutine.

I don't claim that SHOWBMP is in any way complete or perfect, especially since several efforts to allow images to be shown at different locations on the screen unearthed some (to me) very obscure bugs. At present I'm not well enough to work on tracking them down. However, for showing a full screen it works slowly but accurately.

For practical use the code should be converted into native PIC code, not left in its tediously slow MMBASIC form. But, as Gizmo says:
  Quote  Finding the balance between the byte count of implementing a feature into MMBasic, versus how often it would get used, is always going to be difficult. To some, a feature like displaying BMP's would be great, but to others it would never get used.

And of course for fixed images, the sort you'd use for backgrounds or logos, the pre-compressed RLE approach used by Crackerjack is ideal, not least because it works very quickly in MMBASIC. That would be an excellent candidate for a Defined Subroutine library.

Bruce
 
Ray B
Senior Member

Joined: 16/02/2007
Location: Australia
Posts: 219
Posted: 09:44am 30 Jan 2012
Copy link to clipboard 
Print this post

I confirm that the last line before "End Sub" in LCD.BAS should be changed to
if Wait_mSec > 0 Then Pause Wait_mSec

Now I tested this on a 4 x 40 LCD display and line 2 & Line 2 printed as expected for a 2 x 16 LCD.

PrintLCD 1, " Hello World"
PrintLCD 2, " Maximite LCD "
PrintLCD 3, "1234567890ABCDEFGHIJ"
PrintLCD 4, "qwertyuiopasdfghjklz"

Problem when I try the following code on the 4 x 20 lines lines 3 & 4 of code above don't display on the next line 3 & 4 as hoped even when I pad out the 2nd line with spaces.

Before I dive into the code has someone solved this?

Cheers
RayB from Perth WA
 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 08:40pm 30 Jan 2012
Copy link to clipboard 
Print this post

Ray, it's hard coded for 16 x 2.
I'll send you a copy that works for 20 x 4. If you agree it works ok, we'll post it for others to use.
James

My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 10:39pm 30 Jan 2012
Copy link to clipboard 
Print this post

  James_From_Canb said   Ray, it's hard coded for 16 x 2.
I'll send you a copy that works for 20 x 4. If you agree it works ok, we'll post it for others to use.
James

And send to to Hugh (mmlib@geoffg.net) for inclusion in the MMBasic Library.

Geoff
Geoff Graham - http://geoffg.net
 
Ray B
Senior Member

Joined: 16/02/2007
Location: Australia
Posts: 219
Posted: 02:11am 31 Jan 2012
Copy link to clipboard 
Print this post

James looking forward to your message / attachment.
At least my other post of last night with all the commented examples of driving LCDs like characters to certain LCD Row / Column positions may assist others I'm sure.
Cheers
RayB from Perth WA
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024