Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 10:03 24 Apr 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 : Lineless code

Author Message
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 04:08am 07 Aug 2011
Copy link to clipboard 
Print this post

Do we have to wait for a firmware update to get lineless code?

I've been thinking about Geoff's RENUMBER.BAS program. How difficult would it be to modify the program so it took code without linenumbers and added them?

It could start by looking like:

[code]
ADD2_P1 = 1
ADD2_P2 = 3
GOSUB ADD2 'add 2 numbers
PRINT "The sum is " ADD2_RET
...

.INCLUDE ADD2.BAS
[/code]

and end up like

[code]
10 ADD2_P1 = 1
20 ADD2_P2 = 3
30 GOSUB 100 ' SUB ADD2 'add 2 numbers
40 PRINT "The sum is " ADD2_RET

100 ' SUB ADD2 'add 2 numbers
110 ADD2_RET = ADD2_P1 + ADD2_P2
120 RETURN
[/code]
It would need some sort of naming convention so the program could recognise a named subroutine or GOTO label, and some agreed format for parameter names and return values so we could INCLUDE code snippets.

There's no point doing it if there's lineless code on the way, but might be useful if lineless code is somewhere over the horizon.

Any thoughts?

James (who is still smarting from a linenumber related incident)
My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
Gizmo

Admin Group

Joined: 05/06/2004
Location: Australia
Posts: 5012
Posted: 12:40pm 07 Aug 2011
Copy link to clipboard 
Print this post

That would work. You could even write a program for the Maximite to do it, its just basic string manipulation.

Glenn
The best time to plant a tree was twenty years ago, the second best time is right now.
JAQ
 
haiqu

Senior Member

Joined: 30/07/2011
Location: Australia
Posts: 152
Posted: 05:30am 08 Aug 2011
Copy link to clipboard 
Print this post

Without a full page editor, lineless code would be difficult to use on the Maximite natively. You could, however, have a software switch to disable displaying it...

Rob

unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep
 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 11:41am 08 Aug 2011
Copy link to clipboard 
Print this post

  haiqu said   Without a full page editor, lineless code would be difficult to use on the Maximite natively. You could, however, have a software switch to disable displaying it...

Rob

True, but you can use an editor like Crimson (or Emerald) or ConText on your PC for editing because you get to use a mouse, cut-and-paste, find and replace, keyword highlighting etc. It's good for those big programming tasks. You could copy the code to the Maximite then merge in code snippets and insert the line numbers. Voila. Instant compatibility with no firmware changes.

You're right about needing the full page editor for coding on the Maximite. You couldn't write code without one.

Just displaying the code without line numbers would be the worst of both worlds and would lose the flexibility of named labels.

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

Hedley Lamarr, Blazing Saddles (1974)
 
vasi

Guru

Joined: 23/03/2007
Location: Romania
Posts: 1697
Posted: 12:02pm 08 Aug 2011
Copy link to clipboard 
Print this post

Hi,

I agree with James. I had a ZX Spectrum 48K compatible, with a line editor at the end of screen. It was handy to edit every line from the code by introducing the number of that line. The number was the only way to indicate to the editor what line you wanted to edit. Then you had the LIST command to see the entire program...

Migrating to a numberless Basic, will include a PC in equation. Of course, such a Basic is very good for embedded devices where you definitely need a PC (let's say a netbook or tablet).

Vasi

----------
Oops! It was exactly what Bob(haiqu) said...Edited by vasi 2011-08-09
Hobbit name: Togo Toadfoot of Frogmorton
Elvish name: Mablung Miriel
Beyound Arduino Lang
 
haiqu

Senior Member

Joined: 30/07/2011
Location: Australia
Posts: 152
Posted: 03:13pm 08 Aug 2011
Copy link to clipboard 
Print this post

  James_From_Canb said  
Just displaying the code without line numbers would be the worst of both worlds and would lose the flexibility of named labels.

James


I was being ironic. Guess I should use more smileys...

Rob

unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep
 
crackerjack

Senior Member

Joined: 11/07/2011
Location: Australia
Posts: 164
Posted: 01:30am 09 Aug 2011
Copy link to clipboard 
Print this post

It would be possible to write code in a line-less pseudo-MMBasic on a laptop/PC and using a text-processing tool such as (G)AWK (yes, what a beautiful little language it still is) or a macro-expansion language such as M4 to pre-process/transform this into MMBasic with Lines. Constructs such as the following would be possible (using a slightly modified version of James' example above):


ADD2_P1 = 1
ADD2_P2 = 3
GOSUB ADD2(ADD2_P1, ADD2_P2, OUT ADD2_RET) ' <== This is not MMBasic Syntax
PRINT "The sum is " ADD2_RET
IF ADD2_RET > 10 THEN
GOTO :SKIP ' <== This is not MMBasic Syntax
ENDIF
PRINT "Not Skipped"
:SKIP
PRINT "Skipped"
...
.INCLUDE ADD2.BAS

..where ADD2.BAS is along the lines of:


.SUB ADD2(X, Y, OUT Z) ' Add X, Y, result in Z
Z = X + Y
RETURN

...which once transformed would be something like...


10 ADD2_P1 = 1
20 ADD2_P2 = 3
30 GOSUB 150 ' SUB ADD2(ADD2_P1, ADD2_P2, OUT ADD2_RET) ' Add ADD2_P1, ADD2_P2 result in ADD2_RET
40 PRINT "The sum is " ADD2_RET
50 IF ADD2_RET > 10 THEN
60 GOTO 90
70 ENDIF
80 PRINT "Not Skipped"
90 ' :SKIP
100 PRINT "Skipped"
...
150 '.INCLUDE ADD2.BAS
160 'SUB ADD2(X, Y, OUT Z) ' Add X, Y, result in Z
170 ADD2_RET = ADD2_P1 + ADD2_P2
180 RETURN


Of course, as already pointed out this would require the initial code being written in a MMBasic-esque way on a PC, a pre-processor of some sort resulting in the line numbered MMBasic code.

I'd be willing to have a crack at it if it is considered a worthwhile undertaking by the forum and if native lineless code is still a way off...
Edited by crackerjack 2011-08-10
 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 09:00pm 09 Aug 2011
Copy link to clipboard 
Print this post

Hi Crackerjack.

That sounds like a great idea. I assume (G)AWK and M4 are easily downloadable and preferable free.

Obviously this cannot run on the Maximite because those tools won't run on it. That limits this solution to those people who program outside the Maximite and copy the result in by USB or SD Card.

Judging by the number of replies, there doesn't seem to be a huge amount of interest out there in user-land. Maybe everyone is still getting their hardware worked out.

Anyway, I think it's a great idea and will be more and more useful as people start writing large programs, especially if they want to include libraries of subroutines. As you say, the effort may be wasted if lineless code is coming out soon though.

But assuming lineless code isn't coming out soon:

Could your solution handle recursive includes? (an include in a routine that is being included).
Could it avoid including a routine if it's already been included? (two snippets may call the same routine, such as writing to an LCD screen, and there's no point having it in there twice or more).
Could it take hints at where to start (or restart) code numbering? I like to have major chunks of code separated by large gaps so I have space to edit them without having to renumber following code, and others may feel the same way).

Apologies for all the questions, but it's a lot sorting this sort of thing out before the code is written.

James

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

Hedley Lamarr, Blazing Saddles (1974)
 
crackerjack

Senior Member

Joined: 11/07/2011
Location: Australia
Posts: 164
Posted: 02:43am 10 Aug 2011
Copy link to clipboard 
Print this post

Hi James,

Those are all good questions, some of which I have been thinking about - particularly the nested includes - it would obviously be an issue to have circular references (INCLUDE A includes INCLUDE B which includes INCLUDE A, etc.).

As for M4 and AWK - these are free GNU utilities (Linux and Windows versions exist) - they have been around for decades (somewhat forgotten, but VERY useful tools) and will probably, with minimal code and minimal alteration of writing MMBasic, get the job done. My goal would be to have very little change to writing normal MMBasic - essentially MMBasic with no line numbers, INCLUDE statements and labels for GOTO's and GOSUBs - with some luck/effort, parameters on GOSUBs.

I have spent an hour or so tinkering this morning and almost have a basic solution in place. I'll spend a bit more time (when I have it) looking at this with consideration of your questions and see what I can come up with.

Even if it only benefits a few, it may be worth working on - as you say, only useful to those who transfer code from PC to Maximite.

Cheers,

Lance.
 
vasi

Guru

Joined: 23/03/2007
Location: Romania
Posts: 1697
Posted: 12:44pm 10 Aug 2011
Copy link to clipboard 
Print this post

Hi,
  crackerjack said  Even if it only benefits a few, it may be worth working on - as you say, only useful to those who transfer code from PC to Maximite.


I think that the Maximite embedded world can be big enough and can increase also thanks to your efforts.

Vasi
Hobbit name: Togo Toadfoot of Frogmorton
Elvish name: Mablung Miriel
Beyound Arduino Lang
 
crackerjack

Senior Member

Joined: 11/07/2011
Location: Australia
Posts: 164
Posted: 01:40pm 10 Aug 2011
Copy link to clipboard 
Print this post

Hi,

I have an initial "prototype" working to convert a pseudo-MMBasic with labels and includes to actual MMBasic. The following somewhat contrived (yet, line-less) code snippets might explain it better:

Starting with a couple of library files in a folder called libs, there is a file called constants.bas with the following content:


' MATHS CONSTANTS
MATH_PI = 3.14159265
MATH_DEG_PER_RAD = 57.29577
MATH_E = 2.71828183


In the same folder, there is a file called math.bas

Note the first line (include... - the argument to include is a standard file system path - relative or absolute paths may be used).
Also note the label lines (defined as _LABEL_), in this example the labels are _MAX_ and _ARCTAN_. Any label value may be used as long as it is the label a single word is preceded by an underscore.

math.bas has the following content...


include(libs/constants.bas)

' RETURN MAX OF TWO GIVEN VALUES
_MAX_ (MAX_P1, MAX_P2, MAX_RETURN)
IF MAX_P1 > MAX_P2 THEN
MAX_RETURN = MAX_P1
ELSE
MAX_RETURN = MAX_P2
ENDIF
RETURN

_ARCTAN_ (ARCTAN_X, ARCTAN_Y, ARCTAN_RETURN)
IF ARCTAN_X=0 THEN
ARCTAN_RETURN = 90*SGN(ARCTAN_Y)
ELSEIF X!>0 THEN
ARCTAN_RETURN = MATH_DEG_PER_RAD*ATN(ARCTAN_Y/X)
ELSEIF ARCTAN_Y=0 THEN
ARCTAN_RETURN = 180
ELSE
ARCTAN_RETURN = 180*SGN(ARCTAN_Y) + MATH_DEG_PER_RAD*ATN(ARCTAN_Y/ARCTAN_X)
END IF
RETURN



To use (and re-use) the above library files, the following code may serve as an example. Again note the lack of line numbers, the GOSUBs to labels, the GOTO to a label, the labels themselves and the SETPIN to a labelled intterupt, as well as the include of the math.bas library (which itself has an include of the contants.bas file - i.e. nested includes):


' Main code
_MAIN_
PRINT "In Main Branch"
' Calculate a maximum
MAX_P1 = 10
MAX_P2 = 20
GOSUB _MAX_
PRINT "Max is", MAX_RETURN
' Some Trigonometry
ARCTAN_X = 5
ARCTAN_Y = 3
GOSUB _ARCTAN_
PRINT "ARCTAN is", ARCTAN_RETURN
SETPIN 2, 6, _INT_1_
GOTO _MAIN_
END

' Interrupt
_INT_1_
TEST = TEST + 1
IRETURN

include(libs/math.bas)


Running this through M4 and ~50 odd lines of AWK code results in the following line numbered MMBasic code - note that line number spacing (default of 10) is a parameter provided to the process which will also detect duplicate labels and line numbers exceeding MMBasic's maximum of 32000:


10 ' Main code
20 ' MAIN_
30 PRINT "In Main Branch"
40 ' Calculate a maximum
50 MAX_P1 = 10
60 MAX_P2 = 20
70 GOSUB 300
80 PRINT "Max is", MAX_RETURN
90 ' Some Trigonometry
100 ARCTAN_X = 5
110 ARCTAN_Y = 3
120 GOSUB 380
130 PRINT "ARCTAN is", ARCTAN_RETURN
140 SETPIN 2, 6, 190
150 GOTO 20
160 END
170 '
180 ' Interrupt
190 ' INT_1_
200 TEST = TEST + 1
210 IRETURN
220 '
230 '
240 ' MATHS CONSTANTS (NESTED INCLUDE IN MATH.BAS)
250 MATH_PI = 3.14159265
260 MATH_E = 2.71828183
270 '
280 '
290 ' RETURN MAX OF TWO GIVEN VALUES
300 ' MAX_ (MAX_P1, MAX_P2, MAX_RETURN)
310 IF MAX_P1 > MAX_P2 THEN
320 MAX_RETURN = MAX_P1
330 ELSE
340 MAX_RETURN = MAX_P2
350 ENDIF
360 RETURN
370 '
380 ' ARCTAN_ (ARCTAN_X, ARCTAN_Y, ARCTAN_RETURN)
390 IF ARCTAN_X=0 THEN
400 ARCTAN_RETURN = 90*SGN(ARCTAN_Y)
410 ELSEIF X!>0 THEN
420 ARCTAN_RETURN = MATH_DEG_PER_RAD*ATN(ARCTAN_Y/X)
430 ELSEIF ARCTAN_Y=0 THEN
440 ARCTAN_RETURN = 180
450 ELSE
460 ARCTAN_RETURN = 180*SGN(ARCTAN_Y) + MATH_DEG_PER_RAD*ATN(ARCTAN_Y/ARCTAN_X)
470 END IF
480 RETURN
490 '


This post is getting a bit long now, but I will post a code package and document what is required to get this working on a Windows or Linux PC in the next day or two. As I don't actually have a Maximite as yet, I cannot run any of the example code above to verify everything is OK, but I think the principals are sound.

Note that there is some standard format for variables used and altered in subroutines (e.g. MAX_P1, MAX_P2, etc.) but this is probabaly good practice in a BASIC such as MMBasic anyway.

Let me have your thoughts regarding any problems you may see, improvements etc.

Lance.
 
seco61
Senior Member

Joined: 15/06/2011
Location: Australia
Posts: 205
Posted: 08:43pm 10 Aug 2011
Copy link to clipboard 
Print this post

Hi Lance.

Great work!

The MMBasic max line number is (as of v2.5) 65000.

Regards

Gerard (vk3cg/vk3grs)

Regards

Gerard (vk3cg/vk3grs)
 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 12:51pm 11 Aug 2011
Copy link to clipboard 
Print this post

Hi Lance - it looks really good.

About the only suggestion I have is to keep the label name on the GOSUB line so, for instance, the line calling subroutine _MAX_ would expand

GOSUB _MAX_
to
70 GOSUB 300 '_MAX_

and being picky, the leading underscore for _MAX_ on line 300 has been dropped.

The only problem I can see is two different subroutines using the same variable name. That could be managed by a separate snippet manager though.

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

Hedley Lamarr, Blazing Saddles (1974)
 
crackerjack

Senior Member

Joined: 11/07/2011
Location: Australia
Posts: 164
Posted: 03:32pm 11 Aug 2011
Copy link to clipboard 
Print this post

Ok - here's a preliminary set of instructions for Windows users for this thing called NUMB (Numbering Utility for MMBasic):

1) Download & Install the GNU Utilities packages gawk and M4 . You only need the binaries. The pages have details of dependencies you may need, but I think these are minimal.

2) The packages can both be installed in the same folder - say C:\Program Files\GnuWin (or wherever you choose).

3) Once installed, ensure the bin folder of your installation path is included in your windows environment variable PATH. This is required so that when you run NUMB later, it can find gawk and m4.

4) Download the NUMB zip file and unzip it into a folder of your choice.

5) This file contains two main files - a file called numb.awk - the "work horse" and numb.bat which is used to invoke the process. There is also a folder called src and within that one called libs in the zip file. These are only examples to give an idea of what this thing does and are not required necessarily.

6) You can now start using NUMB to transform line-number free MMBasic with includes and labels.

numb.bat takes two parameters on the command line. The first is the path (relative or absolute) to the folder containing your line-number free BASIC code - *** NOTE *** NUMB expects code files to have an extension of .nmb - e.g. main.nmb. The second parameter is the increment of line numbers to use - the default is 10.

If you run the following from the command line while in the folder in which you unzipped NUMB to, you should see the outout and a new file called main.bas will be created in the src folder.


numb.bat src 20

...outputs...

Transforming src\main.nmb to src\main.bas - line increment is 20

Done


I'm a bit tired now, so I hope to give better, full details on how to use it - what it really does and what to look out for, etc. in soon.

Please bear in mind the usual caveats apply - I still(!) don't have a MaxiMite so cannot test the output on the real thing. Any feedback appreciated. The code is yours to do with as you wish, but I obviously cannoy be held accountable for anything that may occur from you using it. All in good faith, yadda, yadda...

If there are any bugs, defects, whatever, I'll try fix as I can...

Last points
- the include(...) lines need to be in lower case.
- labels must be alone on a line as _LABEL_ without leading or trailing spaces.
- circular include references will lead to exceeding the line number max and the process will abort.
- duplicate labels will abort the process.


Cheers,

Lance.

Edited by crackerjack 2011-08-13
 
crackerjack

Senior Member

Joined: 11/07/2011
Location: Australia
Posts: 164
Posted: 01:05pm 14 Aug 2011
Copy link to clipboard 
Print this post

Hi All,

For the sake of completeness, I have now documented the utility (NUMB) and made some minor updates. It obviously has it's limitations, but for what it's worth it can be downloaded here

The zip file contains a folder called docs with a html file documenting installation and usage, etc.

As a test, I fed Geoff's original LCD.bas file into it after stripping out the line numbers, replacing the GOSUB line numbers with labels and adding labels as required. Made some other minor tweaks to variable names and separated a few multi-statement lines. I didn't make any effort to split the file so as to display the include capability. Here is inputs and resultant output:

INPUT as an NMB (line-number free) file:

GOSUB _LCD_INIT_ ' Initialise the LCD
LCD_line1$ = " Hello World "
LCD_line2$ = " Maximite LCD "
GOSUB _LCD_SEND_ ' send to the LCD
END
'
'
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''
' LCD driver for standard 16 x 2 LCDs
' Geoff Graham, March 2011
'
' For example
futurlec.com LCD16X2
' altronics.com.au Z7001
' jaycar.com.au QP5512
'
' To use

' - execute GOSUB 11000 to initialise display
' - then load the text strings into the
' variablesLCD_line1$ and LCD_line2$
' - execute GOSUB 12000 to display the text
'
' See the file lcd.pdf for the schematic.
' Maximite pin 11 is RS, pin 12 is EN
' pins 13 to 16 are D4 to D7. R/W is grounded
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''
'
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''
_LCD_INIT_
' Initialise the LCD
'
FOR i = 11 TO 16
SETPIN i, 9
NEXT i
LCD_byte = &B0011
GOSUB _LCD_SEND_NIBBLE_
PAUSE 5 ' reset
LCD_byte = &B0011
GOSUB _LCD_SEND_NIBBLE_
PAUSE 5 ' reset
LCD_byte = &B0011
GOSUB _LCD_SEND_NIBBLE_
PAUSE 5 ' reset
LCD_byte = &B0010
GOSUB _LCD_SEND_NIBBLE_
PAUSE 2 ' 4 bit mode
LCD_byte = &B00101100
GOSUB _LCD_SEND_BYTE_ ' 4 bit, 2 lines
LCD_byte = &B00001100
GOSUB _LCD_SEND_BYTE_ ' display on, no cursor
LCD_byte = &B00000110
GOSUB _LCD_SEND_BYTE_ ' increment on write
LCD_byte = &B00000001
GOSUB _LCD_SEND_BYTE_ ' clear display
RETURN
'
'
' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''
_LCD_SEND_
' send the two lines to the LCD
' the text is in LCD_Line1$ and LCD_Line2$
'
LCD_byte = &H80
GOSUB _LCD_SEND_BYTE_ ' select the 1st line
FOR _LCD = 1 TO 16
LCD_byte = ASC(MID$(LCD_Line1$, _LCD, 1))
PIN(11) = 1
GOSUB _LCD_SEND_BYTE_ ' send the character
NEXT _LCD
LCD_byte = &B11000000
GOSUB _LCD_SEND_BYTE_ ' select the 2nd line
FOR _LCD = 1 TO 16
LCD_byte = ASC(MID$(LCD_Line2$, _LCD, 1))
PIN(11) = 1
GOSUB _LCD_SEND_BYTE_ ' send the character
NEXT _LCD
RETURN
'
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''
_LCD_SEND_BYTE_
' Send a byte to the LCD
' the data to be sent is in LCD_byte
'
PIN(13) = LCD_byte AND &B00010000 ' output the 1st 4 bits
PIN(14) = LCD_byte AND &B00100000
PIN(15) = LCD_byte AND &B01000000
PIN(16) = LCD_byte AND &B10000000
PIN(12) = 1
PIN(12) = 0 ' tell lcd to accept data
'
'
_LCD_SEND_NIBBLE_
' Entry point to send just 4 bits to the LCD
PIN(13) = LCD_byte AND &B00000001 ' output the 2nd 4 bits
PIN(14) = LCD_byte AND &B00000010
PIN(15) = LCD_byte AND &B00000100
PIN(16) = LCD_byte AND &B00001000
PIN(12) = 1
PIN(12) = 0
PIN(11) = 0 ' tell lcd to accept data
RETURN


OUTPUT from NUMB:

10 GOSUB 320 ' LCD_INIT_ ' Initialise the LCD
20 LCD_line1$ = " Hello World "
30 LCD_line2$ = " Maximite LCD "
40 GOSUB 620 ' LCD_SEND_ ' send to the LCD
50 END
60 '
70 '
80 '
90 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''
100 ' LCD driver for standard 16 x 2 LCDs
110 ' Geoff Graham, March 2011
120 '
130 ' For example
140 futurlec.com LCD16X2
150 ' altronics.com.au Z7001
160 ' jaycar.com.au QP5512
170 '
180 ' To use
190 '
200 ' - execute GOSUB 11000 to initialise display
210 ' - then load the text strings into the
220 ' variablesLCD_line1$ and LCD_line2$
230 ' - execute GOSUB 12000 to display the text
240 '
250 ' See the file lcd.pdf for the schematic.
260 ' Maximite pin 11 is RS, pin 12 is EN
270 ' pins 13 to 16 are D4 to D7. R/W is grounded
280 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''
290 '
300 '
310 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''
320 ' _LCD_INIT_
330 ' Initialise the LCD
340 '
350 FOR i = 11 TO 16
360 SETPIN i, 9
370 NEXT i
380 LCD_byte = &B0011
390 GOSUB 960 ' LCD_SEND_NIBBLE_
400 PAUSE 5 ' reset
410 LCD_byte = &B0011
420 GOSUB 960 ' LCD_SEND_NIBBLE_
430 PAUSE 5 ' reset
440 LCD_byte = &B0011
450 GOSUB 960 ' LCD_SEND_NIBBLE_
460 PAUSE 5 ' reset
470 LCD_byte = &B0010
480 GOSUB 960 ' LCD_SEND_NIBBLE_
490 PAUSE 2 ' 4 bit mode
500 LCD_byte = &B00101100
510 GOSUB 840 ' LCD_SEND_BYTE_ ' 4 bit, 2 lines
520 LCD_byte = &B00001100
530 GOSUB 840 ' LCD_SEND_BYTE_ ' display on, no cursor
540 LCD_byte = &B00000110
550 GOSUB 840 ' LCD_SEND_BYTE_ ' increment on write
560 LCD_byte = &B00000001
570 GOSUB 840 ' LCD_SEND_BYTE_ ' clear display
580 RETURN
590 '
600 '
610 ' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''
620 ' _LCD_SEND_
630 ' send the two lines to the LCD
640 ' the text is in LCD_Line1$ and LCD_Line2$
650 '
660 LCD_byte = &H80
670 GOSUB 840 ' LCD_SEND_BYTE_ ' select the 1st line
680 FOR _LCD = 1 TO 16
690 LCD_byte = ASC(MID$(LCD_Line1$, _LCD, 1))
700 PIN(11) = 1
710 GOSUB 840 ' LCD_SEND_BYTE_ ' send the character
720 NEXT _LCD
730 LCD_byte = &B11000000
740 GOSUB 840 ' LCD_SEND_BYTE_ ' select the 2nd line
750 FOR _LCD = 1 TO 16
760 LCD_byte = ASC(MID$(LCD_Line2$, _LCD, 1))
770 PIN(11) = 1
780 GOSUB 840 ' LCD_SEND_BYTE_ ' send the character
790 NEXT _LCD
800 RETURN
810 '
820 '
830 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''
840 ' _LCD_SEND_BYTE_
850 ' Send a byte to the LCD
860 ' the data to be sent is in LCD_byte
870 '
880 PIN(13) = LCD_byte AND &B00010000 ' output the 1st 4 bits
890 PIN(14) = LCD_byte AND &B00100000
900 PIN(15) = LCD_byte AND &B01000000
910 PIN(16) = LCD_byte AND &B10000000
920 PIN(12) = 1
930 PIN(12) = 0 ' tell lcd to accept data
940 '
950 '
960 ' _LCD_SEND_NIBBLE_
970 ' Entry point to send just 4 bits to the LCD
980 PIN(13) = LCD_byte AND &B00000001 ' output the 2nd 4 bits
990 PIN(14) = LCD_byte AND &B00000010
1000 PIN(15) = LCD_byte AND &B00000100
1010 PIN(16) = LCD_byte AND &B00001000
1020 PIN(12) = 1
1030 PIN(12) = 0
1040 PIN(11) = 0 ' tell lcd to accept data
1050 RETURN


Cheers,

LanceEdited by crackerjack 2011-08-17
 
Print this page


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

© JAQ Software 2024