Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 17:49 23 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 : LCD code

     Page 2 of 2    
Author Message
VK6MRG

Guru

Joined: 08/06/2011
Location: Australia
Posts: 347
Posted: 07:22am 10 Jul 2011
Copy link to clipboard 
Print this post

Looks like eBay is the best for a test unit to experiment with, less than $10 delivered.
Its easier to ask forgiveness than to seek permission!

............VK6MRG.............VK3MGR............
 
Ray B
Senior Member

Joined: 16/02/2007
Location: Australia
Posts: 219
Posted: 12:34pm 13 Jul 2011
Copy link to clipboard 
Print this post

Found / Tested source of low cost 20 x 4 backlit LCD. When ordered cost me AU$9.58 inc shipping - see price slightly increased today.
9 days from ordering from HongKong to Perth - received it today through Aussie Post

Example of James Code Running on the display attached

http://cgi.ebay.com/HD44780-20X4-Character-LCD-Display-BLUE- backlight-1-pcs-/380349890122?_trksid=p4340.m263&

picture attached2011-07-13_223227_20x4_LCD_on_MM.pdf


RayB from Perth WA
 
Keith @

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 167
Posted: 04:24am 14 Jul 2011
Copy link to clipboard 
Print this post

Ray

Thanks for the picture ... it really does paint a thousand words ... particularly the way you have done the pins for the ribbon cable and the printing of the pin outs.

Good work on the LCD too. I'm keen to get get one working with the MM embedded version.

Keith
The more we know, the more we know we don't know !
 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 08:36am 16 Jul 2011
Copy link to clipboard 
Print this post

I now have a 17 x 10 prototype board. I think it's supposed to be for Arduinos, but it does a good job of supporting a 16 pin LCD screen. It was an interesting Saturday afternoon project to fit it all in - and I still had one row left over!

I did my MM to prototype board connection differently to Ray. I put the pins in order. The cable split is messier, but less confusing for me.

Here's a photo of the whole system



and one of the prototype board.



I particularly like the 10K Resistor Network which has 6 x 10K resistors in one unit. It's the flat blue unit in front of all the yellow and brown cables. That made life a lot easier.

I'm really starting to enjoy this. 10/10 for the Maximite!

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

Hedley Lamarr, Blazing Saddles (1974)
 
VK6MRG

Guru

Joined: 08/06/2011
Location: Australia
Posts: 347
Posted: 02:24am 23 Jul 2011
Copy link to clipboard 
Print this post

James,
I got my LCD today.
Any chance of the schematic for your design?

Its easier to ask forgiveness than to seek permission!

............VK6MRG.............VK3MGR............
 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 07:34am 23 Jul 2011
Copy link to clipboard 
Print this post

I don't have any schematic - I just followed Geoff's new LCD.pdf diagram.
It's in the MMBasic Library V1.4 zip file available from Geoff's site.

I'll PM you my LCD test harness program though. It's very much a work in progress, but it will allow you to change each command bit using a menu, so you can see the results on your LCD screen.

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

Hedley Lamarr, Blazing Saddles (1974)
 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 06:50am 30 Jul 2011
Copy link to clipboard 
Print this post

I've rewritten my original LCD program so it's more useful.
I'd like some comments on what should be added or changed before I finish it up.

Here's some brief notes about it.

It follows Julyan Ilett's LCD tutorial Part 1 and Part 2 closely. If you're new to using LCD screens you should read them.

You'll need to change lines 120 and 130 to include the number of lines and columns on your LCD screen.

It's split into two menus - one sets control values, the other displays text.

For your first try, I suggest you just start the program, select option 8, enter 1,1 then select option 12 and display a message.

The message display section doesn't change any controls. It's up to you to clear the screen, select cursors, set the line and column where you want the message etc. I didn't want any of my code disturbing the control settings you select. Hence the name LCD_Explorer. You're exploring what the LCD control settings do.

Lines and Columns start at 1, not 0.

You can enter text into areas of memory that will never be displayed.

Scrolling behaves differently on 2 and 4 line displays.

Even though you may have a 4 line display, the control chip treats it as a 2 line with output split to different places. When you see scrolling, you'll see the consequences.

Some chunks of code are not implemented yet, and some code could be enhanced - like the custom message code - it scrolls across a whole line. With a bit of tweaking it could just scroll over a subset of a line.

Anyway, let me know how it could be improved. Once it's complete I'll submit it to Don's site along with proper documentation.


Thanks

James

2011-07-30_164429_LCD_Explorer.zip
My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
Ray B
Senior Member

Joined: 16/02/2007
Location: Australia
Posts: 219
Posted: 01:54pm 30 Jul 2011
Copy link to clipboard 
Print this post


james, excellent clear coding with lots of comments
Regards from Bali.
RayB from Perth WA
 
James_From_Canb

Senior Member

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

Well, I didn't get any comments about functionality. Either only one person looked at it, or it was almost perfect. Which it wasn't. The cursor direction only went one way, there were code stubs for missing functionality, and it was really clunky.

Here's my next version. All the exercises in part 1 of the tutorials work, except it doesn't handle 8 bits, and it doesn't read values from the LCD (yet). Also, the "Write to CG RAM" is rudimentary, and is only there to show how it can be done.

Try this version. I reorganised the menus to more strictly follow the split between control and display. The Control Menu now just sets control bits, and the Display menu lets you test the results.

One useful change is that you can pre-select the display option. Instead of pressing D to get to the Display menu, then (for example) 3 to choose option 3, you only need to enter D3.

If you want to code a module for it, write a separate .BAS file for it, starting from line 40,000, load LCD_Explorer, then merge in your code. It will run from the main menu.

I had one weird bug. I set up constants at the start of the program renaming pins 13 to 16 to D4 to D7, and changed Geoff's "Write to LCD" routine to use those names, for instance pin(13) = xxx was changed to pin(D4) = xxx. Rubbish was written to the LCD screen and my case power LED light went out. I tried adding pauses in case it was a timing issue, but it didn't help. I went back to just using the numbers.

Anyway - have fun with the program and let me know if you find any problems or if you have any suggestions on how to improve it.

I've included the change log in case you want to see the fixes and improvements so far.

2011-08-05_230823_LCD_Explorer_1-1.zip

2011-08-05_231158_LCD_Explorer_Change_Log.zip

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:33pm 05 Aug 2011
Copy link to clipboard 
Print this post

  James_From_Canb said   changed Geoff's "Write to LCD" routine to use those names, for instance pin(13) = xxx was changed to pin(D4) = xxx. Rubbish was written to the LCD screen and my case power LED light went out.

The power light going out is not a good sign... it could mean that the MIPS CPU had thrown an exception and crashed.

Do you have a code fragment that demonstrates this effect?

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

Senior Member

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

Well, the program kept working, so if it crashed it recovered well.

Another possibility is that pin(PinName) did not resolve the value PinName so it was interpreted as zero, which would alter the status of pin(0), the power LED controller. The only problem with that theory is that other code did not turn it back on, so it was not consistent.

I'll see if I can replicate the problem with your original LCD code, otherwise I'll modify mine to the minimum needed to demonstrate it.

Your laptop obviously survived the corrugations on the Gibb River Road. Welcome back to civilisation.

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

Hedley Lamarr, Blazing Saddles (1974)
 
James_From_Canb

Senior Member

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

I couldn't get your original LCD code to fail by changing the pin numbers to constants.

Here's some code where the display on the LCD is different depending on whether you use constants or numbers to select the data pins (it's fine with Enable and RS). My power LED turns off if I use constants.

James


210 _C_L1_Start = 0
220 _C_L2_Start = 64
230 _C_L3_Start = 20
240 _C_L4_Start = 84
250 '
260 DIM _Offset(4)
270 _Offset(1) = _C_L1_Start ' load all the offsets into an array
280 _Offset(2) = _C_L2_Start
290 _Offset(3) = _C_L3_Start
300 _Offset(4) = _C_L4_Start
310 '
320 DIM _Text$(4) ' An array to hold the 4 display lines
380 '
390 _Text$(1) = "Hello World, I'm " ' load initial display values for the screen
400 _Text$(2) = "a Maximite LCD "
410 _Text$(3) = "communicating with a" ' if you have a 2 line display, there's no harm leaving these extra lines here
420 _Text$(4) = "4 line HD44780 LCD. "
430 '
440 ' Define the pin names
450 RS = 11
460 Enable = 12
470 D4 = 13
480 D5 = 14
480 D6 = 15
490 D7 = 16
500 '
510 ' define LCD screen values
560 _LCD_Lines = 4
570 _LCD_LineLength = 20
580 '
10020 Input "Run display using Constants or Numbers (C,N) "; RunType$ : RunType$ = UCASE$(RunType$)
10030 GOSUB 29000 'Initialise the LCD
10070 GOSUB 20000 'Show that text displays differently under the 2 options
10090 END
10100 ' ------------------------------------------------------------ ------
10110 '
20000 ' 1. Display the default messages for the lines (defined at beginning of the code)
20010 ' ----------- ------------------------------------------------------------ ------
20020 ' This ignores whatever DDRAM location you have set up with the Control menu.
20030 ' It relies on the values for _C_Lines and _C_LineLength being correct.
20040 '
20050 for _Line_out = 1 to _LCD_Lines
20060 _LCD_byte = 128 + _Offset(_Line_out) : GOSUB 30000 ' select the output line on the LCD
20070 for _LCD = 1 to _LCD_LineLength
20080 _LCD_byte = ASC(MID$(_Text$(_Line_out), _LCD, 1))
20090 pin(RS) = 1 : GOSUB 30000 ' send the character
20100 next _LCD
20110 next _Line_out
20120 '
20130 RETURN


29000 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''
29010 ' Initialise the LCD
29020 '
29030 FOR i = 11 TO 16 : SETPIN i, 9 : NEXT i ' set the pins to Open collector digital output to 5V
29040 _LCD_byte = &B0011 : GOSUB 30100 ' reset
29050 _LCD_byte = &B0011 : GOSUB 30100 ' reset
29060 _LCD_byte = &B0011 : GOSUB 30100 ' reset
29070 _LCD_byte = &B0010 : GOSUB 30100 ' 4 bit mode
29080 _LCD_byte = &B00101100 : GOSUB 30000 ' 4 bit, 2 lines (or 4 lines)
29090 _LCD_byte = &B00001100 : GOSUB 30000 ' display on, no cursor
29100 _LCD_byte = &B00000110 : GOSUB 30000 ' increment on write
29110 _LCD_byte = &B00000001 : GOSUB 30000 ' clear display
29120 pause 2
29130 RETURN
30000 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''
30010 ' Send a byte to the LCD
30020 ' the data to be sent is in _LCD_byte
30025 ' USE CONSTANTS TO CONTROL PINS
30030 IF RunType$ = "N" THEN GOTO 40000
30040 Pin(D4) = _LCD_byte AND &B00010000 ' output the 1st 4 bits
30050 Pin(D5) = _LCD_byte AND &B00100000
30060 Pin(D6) = _LCD_byte AND &B01000000
30070 Pin(D7) = _LCD_byte AND &B10000000
30080 pin(Enable) = 1 : pin(Enable) = 0 ' tell lcd to accept data
30100 ' Entry point to send just 4 bits to the LCD
30105 IF RunType$ = "N" THEN GOTO 40100
30110 Pin(D4) = _LCD_byte AND &B00000001 ' output the 2nd 4 bits
30120 Pin(D5) = _LCD_byte AND &B00000010
30130 Pin(D6) = _LCD_byte AND &B00000100
30140 Pin(D7) = _LCD_byte AND &B00001000
30150 pin(Enable) = 1 : pin(Enable) = 0 : pin(RS) = 0 ' tell lcd to accept data
30160 RETURN
30170 '

40000 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''
40010 ' Send a byte to the LCD
40020 ' the data to be sent is in _LCD_byte
40030 ' USE NUMERIC VALUES TO CONTROL PINS
40040 Pin(13) = _LCD_byte AND &B00010000 ' output the 1st 4 bits
40050 Pin(14) = _LCD_byte AND &B00100000
40060 Pin(15) = _LCD_byte AND &B01000000
40070 Pin(16) = _LCD_byte AND &B10000000
40080 pin(Enable) = 1 : pin(Enable) = 0 ' tell lcd to accept data
40100 ' Entry point to send just 4 bits to the LCD
40110 Pin(13) = _LCD_byte AND &B00000001 ' output the 2nd 4 bits
40120 Pin(14) = _LCD_byte AND &B00000010
40130 Pin(15) = _LCD_byte AND &B00000100
40140 Pin(16) = _LCD_byte AND &B00001000
40150 pin(Enable) = 1 : pin(Enable) = 0 : pin(RS) = 0 ' tell lcd to accept data
40160 RETURN


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: 02:41am 06 Aug 2011
Copy link to clipboard 
Print this post

OK, thanks. Thankfully it is not an exception so there must be a subtle bug in the handling of the I/O pins.

I cannot see what it could be and without an LCD I cannot reproduce it so I will keep looking through the source trying to find it.

  James_From_Canb said   Your laptop obviously survived the corrugations on the Gibb River Road. Welcome back to civilisation.

Yes, the laptop made it but I almost did not. I contracted a tropical infection in my leg and ended up spending 4 days in Derby hospital. I am now recuperating in a luxury hotel in Broome which sort of makes up for the ordeal.

GeoffEdited by Geoffg 2011-08-07
Geoff Graham - http://geoffg.net
 
James_From_Canb

Senior Member

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

I wouldn't put any effort into it, especially as you don't have the gear to track it down. It's a low priority bug with an easy workaround.

The main thing is that people know about it and use numbers until the problem is corrected in a later version.

James

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

Hedley Lamarr, Blazing Saddles (1974)
 
James_From_Canb

Senior Member

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

AAARGH. A thousand pardons. Two thousand.
I could have sworn I checked my line numbers. There were two line 480s, so D5 was never defined. I wish I could put that in even smaller print.

I'm an idiot and have no idea how that got past me.

I really apologise for raising it. Next time I'll be much more careful.

Time to find an editor that highlights duplicate lines.
My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2914
Posted: 02:23am 07 Aug 2011
Copy link to clipboard 
Print this post

  James_From_Canb said   AAARGH. A thousand pardons. Two thousand.
I could have sworn I checked my line numbers. There were two line 480s, so D5 was never defined. I wish I could put that in even smaller print.

I'm an idiot and have no idea how that got past me.

I really apologise for raising it. Next time I'll be much more careful.

Time to find an editor that highlights duplicate lines.


Ahahaaa,

Good Work James,

I looked at your code and couldnt see much wrong and my adaptation of Geoff's LCD routine (I modified to use the Arduino LCD+switch shield on Don's DonDuino Cross PCB) worked fine using variables so I couldnt see what was wrong but with TWO line 480 would negate the first line 480... Much better if we can do away with line numbers all together and use labels... but all for a later firmware.

Mik
Edited by bigmik 2011-08-08
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
     Page 2 of 2    
Print this page


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

© JAQ Software 2024