Subs/macros for I2C displays

A while ago I asked the forum about how to use these cheap ebay I2C displays (like Hitachi 1602), and I was made aware of work by Rick100 and Hippy.
Based on their work, I made an #include file containing macros and subroutines implementing these display functions for ..M2 chips:
; InitD......................... Initialize display
; ClrD..........................Clear display
; WriteN(number,adjust)...Write byte or word number variable or constant at cursor pos, right og left adjusted
; WriteC(byte)..............Write char at cursor pos (byte)
; GotoXY(xpos,line)......Place cursor at pos x, line y
; EraseC......................Erase character at cursor
; EraseCN(N)................Erase N char starting at cursor
; BackStp....................Backstep cursor
; HideCur.....................Hide cursor
; BlinkCur....................Blink cursor on top of ev. char
; push(mspar)..............Push/pop var or const onto/from stack,
; pop(mspar)................beginning at RAM loc 127 and downwards

Quite useful , and to anyone who might like to use the file, please find it attached. Just replace .txt with .basinc before use. (That file extension is not accepted for upload to the forum)

The file Displaytest.bas is a kind of demo/test file for the #include file itself.
It seems to work well, but of course, there might be undiscovered bugs, so no guarantee issued
If this is posted to the wrong part of the forum, I trust it can be moved to the proper place..

The file Displaytest.bas is not attached as intended.
 

Attachments

Last edited:

Speddo

New Member
Hello Rofi.
Thank you for your code.
Are you able to send the code for "Displaytest.bas" ?
I am not fully experienced with the PicAxe code, with the "Displaytest.bas" code, I can experiment with it.
What is the file suffix ".basinc"?
Does this have something to do with the "#Include" instruction?
Thanking you
Regards
Bill
 

lbenson

Senior Member
What is the file suffix ".basinc"?
Can't answer for the first question (and don't know if you'll get a response on a thread from 5 years ago), but the file suffix ".basinc" is a convention for naming "#Include" files, as you suspected. There is no requirement that the convention be followed (so far as I know--I've never tried anything else), but typically if you have a program named "someName.bas" and it has a "#Include" statement, the included file will be "someName.basinc".
 

Speddo

New Member
Thanks Ibenson.
I really wanted to have some examples of how to invoke the various commands(?) in the #include file.
i.e.
InitD
or some other syntax to invoke the initialize (or other) LCD command.
My impression is that they behave just like an embedded command
I will be setting up a 20M2 tomorrow to try out the #include and experiment with the commands
Speddo
 

lbenson

Senior Member
For the included file in the post, if your program has the line, InitD, that is defined in the include file as a macro, which means that the text in the macro replaces "InitD" in your program. The InitD macro contains a single line, "gosub initDisp", so that is where your program flow will go. You would have to read and understand the code in the subroutine initDisp in order to see what will happen.

This is fairly complex code with macros intended to make the programmer's life easier, but it is necessary to understand what the program is trying to do. This cleans up and standardizes some of the earlier examples (e.g., hippy's), and uses "push" and "pop" a great deal so that the routines called do not use (i.e. destroy) variables that your program may be using.
 

Speddo

New Member
Hello Ibenson.
Thanking you for your replay.
After a few false starts, I have the #Include code up and running.
All working quite well, although it is a little slow for the LCD to display the data, but fast enough for my purposes
All is needed it to place the desired command on a line (with modifiers as per instructions) and away it goes.
i.e. GoToXY(xpos,line) is quite simple with position 1 on line 1 being GoToXY(1,1) without a space! - GoToXY (1,1) returns an error
One trap for the unwary, GREAT CAUTION WITH THE USE OF VARIABLES as many are used in the #Include code!
Serial LCD backpaks DO WORK in PicAxe code!
Cheers
Speddo
 

lbenson

Senior Member
Glad you have it working. Can you paste simple sample code so that people may see how to use this code snippet?
 

Speddo

New Member
Hello Ibenson.
Sorry for the delay.
My project was/is for the PicAxe to read a voltage and display to equivalent current on the LCD.
Using a Hall Effect Sensor (HY10-P) which is to monitor a dc charging current - with excellent isolation 2.5kV!
0 to 10Amp input into the Hall Effect Sensor produces 0-4v output and that is converted to read 0-10Amp on the LCD.
A voltage divider is used in the external circuit as the PicAxe pin can only read 0-2VDC.
I attach 3 codes samples.
SubsMacros_Serial_LCD.txt
Which is the original code slightly modified (with credits to original authors) - pay attention to the original post with regards to renaming from ".txt" to ".basinc"!!!!!
A simple demo "Hello World" in code "Test_The_Include.bas"
And my project code using variables to load data into the LCD Backpak in "Measure_Voltage.bas"
Of course, any comments would be welcome.
 

Attachments

Top