Learning to Drive an LCD DISPLAY

marks

Senior Member
Blame ! Saborn for this Thread he pointed out those cheap LCD's on ebay
I just couldn't resist those blue ones lol.

Going to start a project where i can use 1 so it was about time I learnt how to drive it !
seems quick enough dont think i'll need a serial driver again lol.
Code:
''         COMMAND SUMMARY
'senddata = $38 : GOSUB Command             '(56) Function 8bit/2line/5x8
'senddata = $01 : GOSUB Command             '( 1) Clear Display
'senddata = $02 : GOSUB Command '           '( 2) Cursor Home
'senddata = $07 : GOSUB Command '           '( 7) Character Entry Mode
'senddata = $08 : GOSUB Command '           '( 8) Display Off
'senddata = $0C : GOSUB Command             '(12) Display On/Restore Cursor Off
'senddata = $80 : GOSUB Command	        '(128-147)  Line 1 Cursor Position ($80 + 1 to 19)
'senddata = $C0 : GOSUB Command	        '(192-211)  Line 2 Cursor Position ($C0 + 1 to 19)
'senddata = $94 : GOSUB Command	        '(148-167)  Line 3 Cursor Position ($94 + 1 to 19) continuation of line 1
'senddata = $D4 : GOSUB Command	        '(212-231)  Line 4 Cursor Position ($D4 + 1 to 19) continuation of line 2
'senddata = $0D : GOSUB Command '           '(13) Blinking Cursor
'senddata = $0E : GOSUB Command '           '(14) Underline Cursor 
'senddata = $10 : GOSUB Command '           '(16) Move Cursor Left
'senddata = $14 : GOSUB Command '           '(20) Move Cursor Right
'senddata = $18 : GOSUB Command '           '(24) Shift Display Left
'senddata = $1C : GOSUB Command '           '(28) Shift Display Right

	#picaxe 20X2						
	#no_data
	#terminal off	
'            DB7  = B.7	
'            DB6  = B.6	
'            DB5  = B.5	
'            DB4  = B.4	
'            DB3  = B.3	
'            DB2  = B.2	
'            DB1  = B.1		
'            DB0  = B.0
	SYMBOL E    = C.7			                  
	SYMBOL RS   = A.0			                  
	SYMBOL senddata  = b0			
	SYMBOL index     = b1
	
	SYMBOL D1       = b11 'minutes
	SYMBOL D2       = b12 'minutes
	SYMBOL D3       = b13 'seconds
	SYMBOL D4       = b14 'seconds
	SYMBOL D5       = b15 'tenths
	SYMBOL minutes  = w10 				
	SYMBOL seconds  = w11
	SYMBOL looptime = w12
		
	TABLE  0, ("marks  ")
	TABLE 16, ("PICAXE 20X2 LCD")
	
 	dirsB = %11111111			
 	dirsC = %10111111								
 	
Intialise: 	
	FOR  index = 0 to 2                            ' Initialise LCD
          senddata = $38 : GOSUB Command             '(56) Function 8bit/2line/5x8						
 	NEXT index
 	
	    senddata = $0C : GOSUB Command             '(12) Display On/Restore Cursor Off
	    senddata = $01 : GOSUB Command             '( 1) Clear Display									

CountTIMEofLoop:                                    ' just for fun
SETTIMER 62411
TIMER = 0
Main:

FOR looptime = 1 TO 100

minutes = timer/600
seconds = timer//600/10
bintoascii minutes,D1,D1,D2
bintoascii seconds,D3,D3,D4
D5 = timer//600//10+48
                       
LCDdisplay:
       
          senddata = $80 : GOSUB Command	        '(128-147)  Line 1 Cursor Position ($80 + 1 to 19)
        
      FOR index = 0 TO 6                 
 	  READTABLE index, senddata : GOSUB Display ' sending characters to line one      
 	NEXT index    
         
 	FOR  index = 0 TO 6
 	  LOOKUP index,(D1,D2,":",D3,D4,32,D5),senddata 
 	                              GOSUB Display ' sending characters to line one       
 	NEXT index
 	  
        senddata = 193 : GOSUB Command	        '(192-211)  Line 2 Cursor Position ($C0 + 1 to 19)	
     								
  	FOR index = 16 TO 30                 
 	  READTABLE index, senddata : GOSUB Display ' sending characters to line two      
 	NEXT index
 	  

NEXT looptime : end                               ' Display time of 100 loops of program (9.8seconds)	

Command:
	LOW  RS					        ' set to command
	  outpinsB = senddata			        ' > send command to LCD
	  PULSOUT E,1                               ' \ valid data failing edge
	HIGH RS                                     ' set to character	            	
                           RETURN	
Display: 
	  outpinsB = senddata			        ' > send character to LCD
	  PULSOUT E,1                               ' \ valid data failing edge	
                                    RETURN
Ive created a command summary where i can just cut and paste as required
havent tested all of of them yet but think they are correct.
The example program shows how we can display some text
and for fun included a counter so we can see some moving numbers.

The LCD module was a Bona 1602-18 # note the backlight was only 4.2v
I calculated a 10 ohm resistor but best start with something larger.
for contrast Vee i found 1.5k res works well.
Also tested the code on my Sure 4x20 LCD Display, interestingly that display
worked without any connection to vee(contrast).
 

Attachments

Last edited:

nick12ab

Senior Member
Using A.0 for Enable isn't a good idea for when it comes to downloading a program - use A.0 for RS instead.
 

marks

Senior Member
Thanks ! nicka2ab
Always looking for useful comments.
When downloading a new program the LCD display will just be filled with characters,
on reinitialising we are Clearing the Display anyway.
it does tie up the S.0 pin i thought instead of displaying info on the terminal just doit on the LCD .
those who wish can easily change the pinouts of RS and E in SYMBOLS
* the main aim was just to display some info on an LCD without having to use a serial driver*
I may look lateron at pin configuration freeing up Hi2c and Hser pins
creating a serial driver does seem achievable just need to learn a few new commands lol.
 

hippy

Technical Support
Staff member
I agree with nick12ab on moving RS to A.0, E to C.7

Not only avoiding garbage during download, but also allows DEBUG and/or SERTXD to be used when debugging a program without corrupting the display.

It also means you could use the project as a mini-terminal; serial to LCD plus button inputs or a keypad matrix on C.x with the data passed back via serial using SERTXD.
 

nick12ab

Senior Member
The loop in the initialization part seems a bit of an overkill and using gosubs for every byte to send to the LCD would have to be changed in speed critical applications.

Anyway, here's a schematic for the PICAXE-40X2 i you want to use it on that. Note that my LCD has Vss next to K rather than D7 next to K.

 

hippy

Technical Support
Staff member
HIGH E
outpinsB = senddata
LOW E
RETURN
I'm never sure when a specific LCD updates the data on E ( rising edge, while high or on falling edge ) as I rarely read the LCD manuals unless something doesn't work. I recall having an LCD which changed the data whenever E was high which meant there was disconcerting update of the character as it was first changed to what was on the output pins when E went high before being set correctly.

It's easy to code so it doesn't matter whichever way the LCD works; set the data then activate the strobe -

outpinsB = senddata
HIGH E
LOW E

Or more simply ...

outpinsB = senddata
PULSOUT E,1

Because most writes will be Data bytes rather than Command codes, and a Command code is always sent first by the program the two routines can be optimised as -

Command:
LOW RS
Display:
outpinsB = senddata
PULSOUT E,1
HIGH RS
RETURN

That will also help ( in that there's only one place to change things ) if you wish to use the code on a PICAXE which doesn't have the full 8-bits of Port B available or does but some pins are used for other things (I2C, high-speed serial ).

A final note is on initialisation; sending three $38 command codes as is done in this program. While it often seems to work with a single code sent and it's tempting to optimise to that it's not a good idea.

Some LCD's have an amazing capacity to retain their memories long after power is removed so I'm guessing they are usually always in a previously initialised state and only one $38 does the job, but if powered-off and left a longer time, just one $38 doesn't always work and it needs to be power-cycled or the PICAXE reset to send another $38.

Once working an LCD keeps on working, but turn it off and leave it long enough then it may not initialise when turned on again which is confusing to say the least. Best to simply send three $38 and have done with it.

Note also that some LCD's specify longish time gaps between initialisation command codes sent. Again it often seems to work without but best to add them. Rather than worry about decreasing gaps simply send all with the longest gap time. It will still be quick on human time scales.
 
Last edited:

marks

Senior Member
I Know Dippy,s often recommending to read the data sheet!

But there's really no point Hippys far better ! lol
I wasnt going to reply for a while until I had a chance to think about some changes.
but Hippy put too much effort in i thought i better respond.

changed the code and drawing slightly to add some of the suggestions
the program will now do 100 loops and stop and display a time on the LCD.

The high E and low E gave a time of 10.5 seconds
surprisingly using pulseout improved this to 9.9 seconds
and swapping a0 and c7 pins improved to 9.8 seconds lol thanks nick12ab
and i think two 20x2 are better than a 40x2 picaxe i wish i had 1

your other part of the code wasnt quite efficient it blew 10.6 seconds,
as the display has that extra high command in it.
I was not really concerned with speed as i thought around 10 updates a second was pretty good
it did make it interesting tho and now with the program set up this way makes it easy to see
the effects of different commands
as always thanks Hippy ! and thanks too nick12ab !
 

nick12ab

Senior Member
You can speed stuff up using the SETFREQ command on all X2 parts to up to a guaranteed 64MHz at 5v and still use PULSOUT E,1.

I don't see why the repeated sending of $38 is necessary
 

marks

Senior Member
I thought Hippy explained things pretty well
from memory the datasheet shows an example
if the lcd fails to initialise during powerup
the lcd can also be initialised by software by the micro
using a sequence of 3 %0011xxxx
interestly its the same for 4 bit mode
so you start in 8 bit mode and set it to 4 bit mode.
 

nick12ab

Senior Member
Hippy, your now shut down LCD interfacing site has an error
Most LCD modules will have a single 14-way connector, and 16-way if backlit, and are normally numbered as shown, with Pin 1 being 0V ( or "Vdd" ).
You mean Vss don't you?

Repeated sending of the same number doesn't happen in your LCD interfacing page either.


I thought Hippy explained things pretty well
from memory the datasheet shows an example
if the lcd fails to initialise during powerup
the lcd can also be initialised by software by the micro
using a sequence of 3 11xxxx
Which datasheet?
 
Last edited:

hippy

Technical Support
Staff member
Hippy, your now shut down LCD interfacing site has an error
Most LCD modules will have a single 14-way connector, and 16-way if backlit, and are normally numbered as shown, with Pin 1 being 0V ( or "Vdd" ).
You mean Vss don't you?
Yes, and that was corrected, but the site had grabbed a January 2005 version but they never copied the updated page.

http://galia.fc.uaslp.mx/~cantocar/microcontroladores/PICAXE/PICAXE_LCD_INTERFACING.HTM

Repeated sending of the same number doesn't happen in your LCD interfacing page either.
It does, but it's not so obvious -

' Nibble commands - To initialise 4-bit mode

EEPROM 0,( $33 ) ; %0011---- %0011---- 8-bit / 8-bit
EEPROM 1,( $32 ) ; %0011---- %0010---- 8-bit / 4-bit

Because two E strobes are issued for every write ( ready for 4-bit mode later ) that actually sends (as an 8-bit mode LCD sees things ) -

%0011 0000
%0011 0000
%0011 0000
%0010 0000

Which datasheet?
I've got a paper printed RS Data Library datasheet from 1986 which I rely on for the 'worst case' situation as new controllers are likely faster and better but people will often be dealing with old recycled LCD's. I've attached a later PDF datasheet which still shows the three $3x initialisation sequence and timing on page 45 for 8-bit mode -

1) Power-On
2) Wait 15ms+ after +V is 4V5 / Wait 40ms+ after +V is 2V7
3) Send $3x
4) Wait 4.1ms+
5) Send $3x
6) Wait 100us+
7) Send $3x
8) Send $2x

For 4-bit mode it's on page 46 and is the same except for only sending nibbles. I actually violate the 4-bit timing in my code, don't have the 4.1ms pause between (3) and (5). That's noted in the page but it hasn't proven a problem for me yet.

I've just spotted that when the LCD +V reaches 2V7 that's effectively the same time as it reaches 4V5 in reality so for (1) I should perhaps delay 40ms rather than the 15ms I have in my code, however it 's worked so far with 15ms delay for (2) and (6). The PICAXE reset probably adds the delay which I'm missing anyway (25ms), and usually the LCD has been powered up for a while when the PICAXE is reset. Maybe I had considered all that or maybe I just got lucky :)

It's always a problem trying to write truly generic code which will work with anything. It's relatively easy to make it work with what you have but harder to tell what is needed for what you don't have and may not even exist yet !

The original aim was smallest size LCD driver code and full compliance was sacrificed for the sake of it working with all the HD44780 I had and that seems to have been good enough for everything else anyone has thrown at it. I think there's been one case of it not working with some non-Hitachi controller and the configuration sequence may have had to be tweaked for a few other cases, but otherwise it's worked, even though not even fully compliant with Hitachi timing.
 

Attachments

marks

Senior Member
8 Bit / 4 Bit Shootout !

I thought it may be interesting to compare default speed 8Mhz
with 4Bit we seem to be able to achieve 6.5 updates per second
while 8Bit we get arround 10 updates (35% quicker)
<<4 is much quicker than *16
using | in place of + slight difference faster

As i'm impatiently waiting for my Blue Oled to appear on TECHSUPPLIES
decided to get a 18m2 to tryout penciling out a serial board
i can already see the 20m2 would be a much better option
But it will be interesting to use something similiar to what others seem to be using!

Code:
'         COMMAND SUMMARY 4 BIT MODE

'RS = 0 :senddata =   1 : GOSUB Send : RS = 4             '( 1) Clear Display
'RS = 0 :senddata =   2 : GOSUB Send : RS = 4             '( 2) Cursor Home
'RS = 0 :senddata =   8 : GOSUB Send : RS = 4             '( 8) Display Off
'RS = 0 :senddata =  12 : GOSUB Send : RS = 4             '(12) Display On/Restore Cursor Off
'RS = 0 :senddata = 128 : GOSUB Send : RS = 4        '(128-147) Line 1 Cursor Position 
'RS = 0 :senddata = 192 : GOSUB Send : RS = 4        '(192-211) Line 2 Cursor Position 
'RS = 0 :senddata = 148 : GOSUB Send : RS = 4	     '(148-167) Line 3 Cursor Position ~ continuation of line 1
'RS = 0 :senddata = 212 : GOSUB Send : RS = 4	     '(212-231) Line 4 Cursor Position ~ continuation of line 2
'RS = 0 :senddata =  13 : GOSUB Send : RS = 4             '(13) Blinking Cursor
'RS = 0 :senddata =  14 : GOSUB Send : RS = 4             '(14) Underline Cursor 
'RS = 0 :senddata =  16 : GOSUB Send : RS = 4             '(16) Move Cursor Left
'RS = 0 :senddata =  20 : GOSUB Send : RS = 4             '(20) Move Cursor Right
'RS = 0 :senddata =  24 : GOSUB Send : RS = 4             '(24) Shift Display Left
'RS = 0 :senddata =  28 : GOSUB Send : RS = 4             '(28) Shift Display Right

	#picaxe 20X2						
	#no_data
	#terminal off		
'            DB7     = B.7	
'            DB6     = B.6	
'            DB5     = B.5	
'            DB4     = B.4	        	
	SYMBOL E       = B.3
'            RS      = B.2				                  
     		                  
	SYMBOL senddata = W3  :  SYMBOL senddataMSB  = b7  : SYMBOL senddataLSB  = b6		
	SYMBOL index    = b8
	SYMBOL RS       = b9
	
	SYMBOL D1       = b11 'minutes
	SYMBOL D2       = b12 'minutes
	SYMBOL D3       = b13 'seconds
	SYMBOL D4       = b14 'seconds
	SYMBOL D5       = b15 'tenths
	SYMBOL minutes  = w8 				
	SYMBOL seconds  = w9
	SYMBOL looptime = w10 
	
	
	TABLE	  0, ($30,$30,$30,$20,$20,$80,$0,$C0,$0,$10)  '(4Bit)(Function 8bit/2line/5x8)(Display On)(Clear Display)	
	TABLE  40, ("marks  ")
	TABLE  16, ("PICAXE 20X2 LCD")
	
 	dirsB = %11111111			
 	dirsC = %10111111	
 								
IntialiseLCD: 
      FOR  index = 0 to 9                                               
 READTABLE index, senddata : outpinsB = senddata : PULSOUT E,1 ' Initialise LCD 
 	NEXT index  :  PAUSE 10	
 	 	
CountTIMEofLoop:                                               ' just for fun
SETTIMER 62411
TIMER = 0

Main:
FOR looptime = 1 TO 100

minutes = timer/600
seconds = timer//600/10
bintoascii minutes,D1,D1,D2
bintoascii seconds,D3,D3,D4
D5 = timer//600//10+48						

LCDdisplay:
           RS = 0 :senddata = 128 : GOSUB Send : RS = 4        '(128-147) Line 1 Cursor Position
        
      FOR index = 40 TO 46                 
 	  READTABLE index, senddata : GOSUB Send ' sending characters to line one      
 	NEXT index    
         
 	FOR  index = 0 TO 6
 	  LOOKUP index,(D1,D2,":",D3,D4,32,D5),senddata 
 	                              GOSUB Send ' sending characters to line one       
 	NEXT index
 	  
           RS = 0 :senddata = 192 : GOSUB Send : RS = 4        '(192-211) Line 2 Cursor Position	
     								
  	FOR index = 16 TO 30                 
 	  READTABLE index, senddata : GOSUB Send ' sending characters to line two      
 	NEXT index
 	  
NEXT looptime : end                            ' Display time of 100 loops of program (15.3seconds)	

                	
   Send:  senddata = senddata <<4                    ' > send 4Bit Mode to LCD
	 outpinsB = senddataMsb <<4 | RS : PULSOUT E,1 ' \ valid data falling edge 
	 outpinsB = senddataLsb | RS     : PULSOUT E,1 ' \ valid data falling edge 
	                              RETURN
 

Attachments

hippy

Technical Support
Staff member
You might even find that not getting overly clever with nibble manipulation is faster ...

Code:
Send: outpinsB = senddata & $F0 | RS : PULSOUT E,1
      outpinsB = senddata << 4  | RS : PULSOUT E,1
      RETURN
If you can put the RS pin on a different port you can improve speed even more by losing both "|RS" and, if you've done that, then you can go to 8-bit output.

While RS should be stable before E pulses you may be able to diode mix ( maybe using an RC ) so you can use 4-bit and pulse one of two pins so you get an E with RS and an E without RS which can be on the same port and still lose the "|RS".
 

marks

Senior Member
Make your own 8 bit board

Thanks for that Hippy!
I guess I over nibbled
too many refreshments too lol.

Using your code gives a 3% improvement again.
Selection of those pinouts were because they seem to be in common use
and was just after a rough comparison.

When using RS on a different port we get another 5% improvement
so the gap is narrowing 8 Bit is now only 28% faster than 4 Bit.

I must amit i,ve only used the AND OR statements for single bits
now yourve pointed that out it does look obvious now!
well when you write it out it does lol and reread manual 2.
Code:
Senddata  0101 0101
AND $F0   1111 0000
      =   0101 0000
OR RS     0000 0100
      =   0101 0100
Ive just finished making an 8 Bit board for those interested in making your own ax133copy
now someone whats a clock for Chrissy! so I guess i'll look at a 4 Bit version
using the 18m2 which i'm liking more & more. with i2c and the ds3231.
 

Attachments

hippy

Technical Support
Staff member
I guess i'll look at a 4 Bit version using the 18m2 which i'm liking more & more. with i2c and the ds3231.
Note that using I2C pins will mess up existing data bit to physical pin mapping which means more complicated bit-twiddling or reallocating pins. On the 18M2 when using I2C you can't put the 4-bit LCD data nibble on B.0-B.3 nor B.4-B.7. Using C.0-C.3 could however work. Or you could do software bit-banged I2C.
 

marks

Senior Member
Thanks hippy ! yes I'll be using c0 to c3
and hopefully reduce the code too
Code:
Send: outpinsB = senddata /16: PULSOUT E,1
          outpinsB = senddata     : PULSOUT E,1
untested lol
 

marks

Senior Member
Make your own 4 bit board for the 18m2

Wow its almost Christmas!
hope its a good one for us all...

I just finished making a 4 Bit Board and thought it turned out quite good
we can also now make use of the hi2c pins too.
having both Boards we are now able to make some real comparisons with the 18m2.
Interestingly the 4bit board does really well being only 17% slower than the 8bit board.
here,s the test code for each.
Code:
'         COMMAND SUMMARY 4 BIT MODE

'RS = 0 :senddata =   1 : GOSUB Send : RS = 4             '( 1) Clear Display
'RS = 0 :senddata =   2 : GOSUB Send : RS = 4             '( 2) Cursor Home
'RS = 0 :senddata =   8 : GOSUB Send : RS = 4             '( 8) Display Off
'RS = 0 :senddata =  12 : GOSUB Send : RS = 4             '(12) Display On/Restore Cursor Off
'RS = 0 :senddata = 128 : GOSUB Send : RS = 4        '(128-147) Line 1 Cursor Position 
'RS = 0 :senddata = 192 : GOSUB Send : RS = 4        '(192-211) Line 2 Cursor Position 
'RS = 0 :senddata = 148 : GOSUB Send : RS = 4	     '(148-167) Line 3 Cursor Position ~ continuation of line 1
'RS = 0 :senddata = 212 : GOSUB Send : RS = 4	     '(212-231) Line 4 Cursor Position ~ continuation of line 2
'RS = 0 :senddata =  13 : GOSUB Send : RS = 4             '(13) Blinking Cursor
'RS = 0 :senddata =  14 : GOSUB Send : RS = 4             '(14) Underline Cursor 
'RS = 0 :senddata =  16 : GOSUB Send : RS = 4             '(16) Move Cursor Left
'RS = 0 :senddata =  20 : GOSUB Send : RS = 4             '(20) Move Cursor Right
'RS = 0 :senddata =  24 : GOSUB Send : RS = 4             '(24) Shift Display Left
'RS = 0 :senddata =  28 : GOSUB Send : RS = 4             '(28) Shift Display Right

	#picaxe 18m2							
	#terminal off	
'            DB7  = C.3	
'            DB6  = C.2	
'            DB5  = C.1	
'            DB4  = C.0	
'            SCK  = B.4	
'            SDA  = B.1		
	SYMBOL E    = B.6			                  
	SYMBOL RS   = B.7			                  
	SYMBOL senddata    = b0			
	SYMBOL index       = b1
	SYMBOL Refreshrate = b2 
      SYMBOL D1          = b3 
	SYMBOL D2          = b4 
	SYMBOL D3          = b5 
	SYMBOL D4          = b6 
	SYMBOL D5          = b7 
	
	EEPROM	  0,($03,$03,$03,$02,$02,$08,$0,$0C,$0,$01)  '(4Bit)(Function 4bit/2line/5x8)(Display On)(Clear Display)
	EEPROM 40, ("marks  ")
	EEPROM 16, ("PICAXE 18M2 LCD")
	
      SETFREQ M8
 	dirsB = %11101101			
 	dirsC = %00001111								
 	
Intialise: 	
	FOR  index = 0 to 9                                               
          READ index, senddata : pinsC = senddata :PULSOUT E,1 ' Initialise LCD						
 	NEXT index : PAUSE 10
Main:
   ENABLETIME 
   BINTOASCII Refreshrate,D3,D2,D1
            
LCDdisplay:
       
LOW RS  :senddata = 128 : GOSUB Send : HIGH RS '(128-147) Line 1 Cursor Position
       
      FOR index = 40 TO 46                 
 	  READ index, senddata : GOSUB Send ' sending characters to line one      
 	NEXT index    
         
      FOR  index = 0 TO 5
 	  LOOKUP index,("  ",D3,D2," ",D1),senddata 
 	                         GOSUB Send ' sending characters to line one 
 	NEXT index
 	
LOW RS  :senddata = 192 : GOSUB Send : HIGH RS '(192-211) Line 2 Cursor Position	
     								
  	FOR index = 16 TO 30                 
 	  READ index, senddata : GOSUB Send ' sending characters to line two      
 	NEXT index
 	 
 	 INC Refreshrate 
 	 IF time = 10 THEN Finish	  	  	  
     GOTO main

Send:  pinsC = senddata / 16 : PULSOUT E,1 :  pinsC = senddata : PULSOUT E,1 ' 4Bitmode to LCD (14.2per second)
                            RETURN
Finish:END
Code:
'         COMMAND SUMMARY 8 BIT MODE

'RS = 0 :senddata =   1 : GOSUB Send : RS = 4             '( 1) Clear Display
'RS = 0 :senddata =   2 : GOSUB Send : RS = 4             '( 2) Cursor Home
'RS = 0 :senddata =   8 : GOSUB Send : RS = 4             '( 8) Display Off
'RS = 0 :senddata =  12 : GOSUB Send : RS = 4             '(12) Display On/Restore Cursor Off
'RS = 0 :senddata = 128 : GOSUB Send : RS = 4        '(128-147) Line 1 Cursor Position 
'RS = 0 :senddata = 192 : GOSUB Send : RS = 4        '(192-211) Line 2 Cursor Position 
'RS = 0 :senddata = 148 : GOSUB Send : RS = 4	     '(148-167) Line 3 Cursor Position ~ continuation of line 1
'RS = 0 :senddata = 212 : GOSUB Send : RS = 4	     '(212-231) Line 4 Cursor Position ~ continuation of line 2
'RS = 0 :senddata =  13 : GOSUB Send : RS = 4             '(13) Blinking Cursor
'RS = 0 :senddata =  14 : GOSUB Send : RS = 4             '(14) Underline Cursor 
'RS = 0 :senddata =  16 : GOSUB Send : RS = 4             '(16) Move Cursor Left
'RS = 0 :senddata =  20 : GOSUB Send : RS = 4             '(20) Move Cursor Right
'RS = 0 :senddata =  24 : GOSUB Send : RS = 4             '(24) Shift Display Left
'RS = 0 :senddata =  28 : GOSUB Send : RS = 4             '(28) Shift Display Right

	#picaxe 18m2							
	#terminal off	
'            DB7  = B.7	
'            DB6  = B.6	
'            DB5  = B.5	
'            DB4  = B.4	
'            DB3  = B.3	
'            DB2  = B.2	
'            DB1  = B.1		
'            DB0  = B.0
	SYMBOL E    = C.6			                  
	SYMBOL RS   = C.7			                  
	SYMBOL senddata    = b0			
	SYMBOL index       = b1
	SYMBOL Refreshrate = b2 
      SYMBOL D1          = b3 
	SYMBOL D2          = b4 
	SYMBOL D3          = b5 
	SYMBOL D4          = b6 
	SYMBOL D5          = b7 
	
	EEPROM	  0,($38,$38,$38,$0C,$01) '(Function 8bit/2line/5x8)(Display On)(Clear Display)
	EEPROM 40, ("marks  ")
	EEPROM 16, ("PICAXE 18M2 LCD")
	
      SETFREQ M8
 	dirsB = %11111111			
 	dirsC = %11001111								
 	
Intialise: 	
	FOR  index = 0 to 4                                               
          READ index, senddata : pinsB = senddata :PULSOUT E,1 ' Initialise LCD						
 	NEXT index : PAUSE 10
Main:
   ENABLETIME 
   BINTOASCII Refreshrate,D3,D2,D1
            
LCDdisplay:
       
LOW RS  :senddata = 128 : GOSUB Send : HIGH RS '(128-147) Line 1 Cursor Position
       
      FOR index = 40 TO 46                 
 	  READ index, senddata : GOSUB Send ' sending characters to line one      
 	NEXT index    
         
      FOR  index = 0 TO 5
 	  LOOKUP index,("  ",D3,D2," ",D1),senddata 
 	                         GOSUB Send ' sending characters to line one 
 	NEXT index
 	
LOW RS  :senddata = 192 : GOSUB Send : HIGH RS '(192-211) Line 2 Cursor Position	
     								
  	FOR index = 16 TO 30                 
 	  READ index, senddata : GOSUB Send ' sending characters to line two      
 	NEXT index
 	 
 	 INC Refreshrate 
 	 IF time = 10 THEN Finish	  	  	  
     GOTO main

Send:  pinsB = senddata : PULSOUT E,1 ' 8Bitmode to LCD (16.6per second)
                            RETURN
Finish:END
 

Attachments

marks

Senior Member
4 BIT 8 BIT LCD Serial driver

Wow this code snipet has turned into a full blown project lol.Got myself another 18m2 unfortunately there both an early version 2.A
Hopefully when the BLUE OLED becomes available on TECHSUPPLIES I may get the latest version withit lol.
The LCD driver for both boards is almost identical.
When we power up the supply voltage is read form the internal adc which is very accurate.and will display (LCD Supply 5.0v)
We also load our Custom Characters just edit the eeprom statements for whats required.
You can uncomment statements to test and display your characters.
The display may operate a little diffferently but you still should be able to use the same standard commands.
We also have a control section to do our stuff ! lol
an example if we what output 1 high we send (254,$21) and to make output 1 low (254,$20)
Both 4bit and 8bit boards run at 4800 bps and 32mhz they seem quick
so really the 4 bit board has the advantage and makes native Hi2c available.
Code:
#picaxe 18m2  ' version 2.A * Testdrive 4bit/8bit Serial driver boards* marks
SETFREQ M16

main:
serout c.0,n4800_16,(254,192)   ' Command Line 2 Cursor Position
serout c.0,n4800_16,("can't wait Santa")

  serout c.0,n4800_16,(254,$21) ' Control High OUTPUT 1
pause 1200
              
serout c.0,n4800_16,(254,192)   ' Command Line 2 Cursor Position
serout c.0,n4800_16,("                ") 

  serout c.0,n4800_16,(254,$20) ' Control Low OUTPUT 1  
pause 1200
goto main
Code:
	#picaxe 18m2    'version 2.A * 8 BIT SERIAL DRIVER 4800 baud * marks							
	#terminal off	
'            DB7  = B.7	
'            DB6  = B.6	
'            DB5  = B.5	
'            DB4  = B.4	
'            DB3  = B.3	
'            DB2  = B.2	
'            DB1  = B.1		
'            DB0  = B.0
      SYMBOL Rx   = C.5
	SYMBOL E    = C.6			                  
	SYMBOL RS   = C.7			                  
	SYMBOL senddata    = b0	 SYMBOL sentdata    = b0			
	SYMBOL index       = b1
	SYMBOL batV        = b2 
	SYMBOL ADCval      = b3
      SYMBOL D1          = b4 
	SYMBOL D2          = b5 
	
      EEPROM 0 ,($38,$38,$38,$0C,$01)    '(Function 8bit/2line/5x8)(Display On)(Clear Display)	 16  8  4  2  1                                                
      EEPROM 10,(6 ,9 ,9 ,6 ,0 ,0 ,0 ,0) ' load custom character (o) =0                           *  '  '  '  *  17
      EEPROM 18,(14,17,17,31,17,17,0 ,0) ' load custom character (A) =1                           *  *  '  *  *  27
      EEPROM 26,(30,17,17,30,16,16,0 ,0) ' load custom character (P) =2                           *  '  *  '  *  21
      EEPROM 34,(17,27,21,17,17,17,0 ,0) ' load custom character (M) =3                           *  '  '  '  *  17
      EEPROM 42,(14,17,16,16,17,14,0 ,0) ' load custom character (C) =4                           *  '  '  '  *  17
      EEPROM 50,(30,16,16,28,16,16,0 ,0) ' load custom character (F) =5                           *  '  '  '  *  17
      EEPROM 58,(0 ,31,1 ,31,16,16,31,0) ' load custom character (2) =6                           '  '  '  '  '  0
      EEPROM 66,(14,10,14,0 ,14,10,10,0) ' load custom character (on)=7                           '  '  '  '  '  0
                                         '                                                     custom character example (M)=3
	CALIBADC10 ADCval
      SETFREQ M32
 	dirsB = %11111111			
 	dirsC = %11001111								
 	batV = 10475 / ADCval
      BinToAscii batV,D2,D2,D1 
      
Initialise: 	
	FOR  index = 0 to 4                                               
          READ index, senddata : pinsB = senddata : PULSOUT E,1 ' Initialise LCD						
 	NEXT index : PAUSE 10
 	
DisplaySupply:
	HIGH RS
      FOR  index = 0 TO 15
 	    LOOKUP index,("LCD Supply ",D2,".",D1,"V "),sentdata 
 	                           pinsB = senddata : PULSOUT E,1 ' sending characters to line one 
      NEXT index

LoadCustomCharactersFromEEPROM:
       LOW RS : senddata = $40 : pinsB = senddata : PULSOUT E,1 : HIGH RS ' Load Characters to LCD	
 	FOR  index =10 TO 73                 
 	    READ index, senddata : pinsB = senddata : PULSOUT E,1 ' sending characters to LCD      
 	NEXT index    
 
' TestCustomCharacters:
'       LOW RS  :senddata = 192 : pinsB = senddata : PULSOUT E,1 '(192-211) Line 2 Cursor Position
' HIGH RS
'      FOR  index = 0 TO 12
' 	    LOOKUP index,("Test ",0,1,2,3,4,5,6,7),sentdata 
' 	                            pinsB = senddata : PULSOUT E,1 ' sending characters to line two 
'      NEXT index

Main:
   SERIN Rx,N4800_32,sentdata
   
   IF sentdata = 254 THEN Commands
   pinsB = sentdata : PULSOUT E,1
   GOTO Main
   
Commands:
   SERIN Rx,N4800_32,sentdata
   pinsB = sentdata 
   index = sentdata / 16: IF index = $2 then Control
   LOW RS
    PULSOUT E,1
   HIGH RS 
    GOTO Main
    
Control: 
   SELECT CASE sentdata
   case  $20  low c.0
   case  $21 high c.0
   case  $22  low c.1
   case  $23 high c.1
   case  $24  low c.2
   case  $25 high c.2
   END SELECT
    GOTO Main
Code:
	#picaxe 18m2    'version 2.A * 4 BIT SERIAL DRIVER 4800 baud * marks							
	#terminal off	
'            DB7  = C.3	
'            DB6  = C.2	
'            DB5  = C.1	
'            DB4  = C.0	           
      SYMBOL Rx   = C.5
	SYMBOL E    = B.6			                  
	SYMBOL RS   = B.7			                  
	SYMBOL senddata    = b0	 SYMBOL sentdata    = b0			
	SYMBOL index       = b1
	SYMBOL batV        = b2 
	SYMBOL ADCval      = b3
      SYMBOL D1          = b4 
	SYMBOL D2          = b5 
	
      EEPROM 0 ,($03,$03,$03,$02,$02,$08,$0,$0C,$0,$01)'(4Bit)(2line/5x8)(Display On)(Clear Display)   16  8  4  2  1                                                
      EEPROM 10,(6 ,9 ,9 ,6 ,0 ,0 ,0 ,0) ' load custom character (o) =0                                 *  '  '  '  *  17
      EEPROM 18,(14,17,17,31,17,17,0 ,0) ' load custom character (A) =1                                 *  *  '  *  *  27
      EEPROM 26,(30,17,17,30,16,16,0 ,0) ' load custom character (P) =2                                 *  '  *  '  *  21
      EEPROM 34,(17,27,21,17,17,17,0 ,0) ' load custom character (M) =3                                 *  '  '  '  *  17
      EEPROM 42,(14,17,16,16,17,14,0 ,0) ' load custom character (C) =4                                 *  '  '  '  *  17
      EEPROM 50,(30,16,16,28,16,16,0 ,0) ' load custom character (F) =5                                 *  '  '  '  *  17
      EEPROM 58,(0 ,31,1 ,31,16,16,31,0) ' load custom character (2) =6                                 '  '  '  '  '  0
      EEPROM 66,(14,10,14,0 ,14,10,10,0) ' load custom character (on)=7                                 '  '  '  '  '  0
                                         '                                                           custom character example (M)=3
	CALIBADC10 ADCval
      SETFREQ M32
 	dirsB = %11101101			
 	dirsC = %00001111								
 	batV = 10475 / ADCval
      BinToAscii batV,D2,D2,D1 
      
Initialise: 	
	FOR  index = 0 to 9                                               
          READ index, senddata : pinsC = senddata : PULSOUT E,1 ' Initialise LCD						
 	NEXT index : PAUSE 10
 	
DisplaySupply:
	HIGH RS
      FOR  index = 0 TO 15
 	    LOOKUP index,("LCD Supply ",D2,".",D1,"V "),sentdata 
 	                           pinsC = senddata / 16 : PULSOUT E,1 : pinsC = senddata : PULSOUT E,1 ' sending characters to line one 
      NEXT index

LoadCustomCharactersFromEEPROM:
       LOW RS : senddata = $40 : pinsC = senddata / 16 : PULSOUT E,1 : pinsC = senddata : PULSOUT E,1 : HIGH RS ' Load Characters to LCD	
 	FOR  index =10 TO 73                 
 	    READ index, senddata : pinsC = senddata / 16 : PULSOUT E,1 : pinsC = senddata : PULSOUT E,1 ' sending characters to LCD      
 	NEXT index    
 
' TestCustomCharacters:
'       LOW RS  :senddata = 192 : pinsC = senddata / 16 : PULSOUT E,1 : pinsC = senddata : PULSOUT E,1  '(192-211) Line 2 Cursor Position
'      HIGH RS
'      FOR  index = 0 TO 12
' 	    LOOKUP index,("Test ",0,1,2,3,4,5,6,7),sentdata 
' 	                            pinsC = senddata / 16 : PULSOUT E,1 : pinsC = senddata : PULSOUT E,1 ' sending characters to line two 
'      NEXT index

Main:
   SERIN Rx,N4800_32,sentdata
   IF sentdata = 254 THEN Commands
   pinsC = senddata / 16 : PULSOUT E,1 : pinsC = senddata : PULSOUT E,1
   GOTO Main
   
Commands:
   SERIN Rx,N4800_32,sentdata
   pinsC = senddata / 16 
   IF pinsc = $2 then Control 
   LOW RS
    PULSOUT E,1 : pinsC = senddata : PULSOUT E,1
   HIGH RS 
    GOTO Main
    
Control: 
   SELECT CASE sentdata
   case  $20  low b.0
   case  $21 high b.0
   case  $22  low b.5
   case  $23 high b.5
   case  $24  low b.2
   case  $25 high b.2
   case  $26  low b.3
   case  $27 high b.3
   END SELECT
    GOTO Main
 

marks

Senior Member
4 BIT 8 BIT LCD SERIAL DRIVER @ 9600bps 18m2

While 4800 baud is good we dont need to use any pauses!
9600 baud is quite popular as an Industry standard.
If we want our 18m2 to go faster we need to send a PAUSE 2 between bytes so it can keep up,
this does make our code a bit messy lol! and not very practical.

Another alternative could be using the byte-scratchpad pointer.
as i'm using a 1602 LCD this example is limited to sending upto 16 characters together
and proberly all thats needed for larger LCD's anyway thats easily changed.
here's the code for our 4 bit and 8bit Boards every time we serial out we should use a PAUSE 2.

They also make handy project boards lol!

Code:
#picaxe 18m2  ' version 2.A * Testdrive 4bit/8bit Serial driver boards* marks
SETFREQ M16
                                ' when using 4bit board to send I use c.0 
main:
serout b.0,n9600_16,(254,192)   ' Command Line 2 Cursor Position
pause 2
serout b.0,n9600_16,("Marks 9600 bps")

  serout b.0,n9600_16,(254,$21) ' Control High OUTPUT 1
pause 4000
              
serout b.0,n9600_16,(254,192)   ' Command Line 2 Cursor Position
pause 2
serout b.0,n9600_16,("                ") 

  serout b.0,n9600_16,(254,$20) ' Control Low OUTPUT 1  
pause 2000
goto main
Code:
	#picaxe 18m2    'version 2.A * 8 BIT SERIAL DRIVER 9600 baud * marks							
	#terminal off	
'            DB7  = B.7	
'            DB6  = B.6	
'            DB5  = B.5	
'            DB4  = B.4	
'            DB3  = B.3	
'            DB2  = B.2	
'            DB1  = B.1		
'            DB0  = B.0
      SYMBOL Rx   = C.5
	SYMBOL E    = C.6			                  
	SYMBOL RS   = C.7			                  
	SYMBOL senddata    = b0	 SYMBOL sentdata    = b0
	SYMBOL index       = b1
	SYMBOL batV        = b2 
	SYMBOL ADCval      = b3
      SYMBOL D1          = b4 
	SYMBOL D2          = b5 
	
	EEPROM 0 ,($38,$38,$38,$0C,$01)    '(Function 8bit/2line/5x8)(Display On)(Clear Display)	 16  8  4  2  1 
      EEPROM 10,(6 ,9 ,9 ,6 ,0 ,0 ,0 ,0) ' load custom character (o) =0                           *  '  '  '  *  17
      EEPROM 18,(14,17,17,31,17,17,0 ,0) ' load custom character (A) =1                           *  *  '  *  *  27
      EEPROM 26,(30,17,17,30,16,16,0 ,0) ' load custom character (P) =2                           *  '  *  '  *  21
      EEPROM 34,(17,27,21,17,17,17,0 ,0) ' load custom character (M) =3                           *  '  '  '  *  17
      EEPROM 42,(14,17,16,16,17,14,0 ,0) ' load custom character (C) =4                           *  '  '  '  *  17
      EEPROM 50,(30,16,16,28,16,16,0 ,0) ' load custom character (F) =5                           *  '  '  '  *  17
      EEPROM 58,(0 ,31,1 ,31,16,16,31,0) ' load custom character (2) =6                           '  '  '  '  '  0
      EEPROM 66,(14,10,14,0 ,14,10,10,0) ' load custom character (on)=7                           '  '  '  '  '  0
                                         '                                                     custom character example (M)=3
	CALIBADC10 ADCval
      SETFREQ M32
 	dirsB = %11111111			
 	dirsC = %11001111			
 	batV = 10475 / ADCval
      BinToAscii batV,D2,D2,D1 
      
Initialise: 	
	FOR  index = 0 to 4                                               
          READ index, senddata : pinsB = senddata : PULSOUT E,1 ' Initialise LCD	
 	NEXT index : PAUSE 10
 	
DisplaySupply:
	HIGH RS
      FOR  index = 0 TO 15
 	    LOOKUP index,("LCD Supply ",D2,".",D1,"V "),senddata 
 	                           pinsB = senddata : PULSOUT E,1 ' sending characters to line one 
      NEXT index

LoadCustomCharactersFromEEPROM:
       LOW RS : senddata = $40 : pinsB = senddata : PULSOUT E,1 : HIGH RS ' Load Characters to LCD	
 	FOR  index =10 TO 73                 
 	    READ index, senddata : pinsB = senddata : PULSOUT E,1 ' sending characters to LCD      
 	NEXT index    
 
' TestCustomCharacters:
'       LOW RS  :senddata = 192 : pinsB = senddata : PULSOUT E,1 '(192-211) Line 2 Cursor Position
' HIGH RS
'      FOR  index = 0 TO 12
' 	    LOOKUP index,("Test ",0,1,2,3,4,5,6,7),senddata 
' 	                            pinsB = senddata : PULSOUT E,1 ' sending characters to line two 
'      NEXT index

Main:
     bptr=28
   SERIN Rx,N9600_32,@bptr
   IF @bptrinc = 254 THEN Commands
   SERIN [10],Rx,N9600_32,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc
    @bptr = 254
     bptr = 28
       do until @bptr = 254
         pinsB = @bptrinc : PULSOUT E,1
       loop
   GOTO Main
   
Commands:
   SERIN Rx,N9600_32,sentdata
   pinsB = sentdata 
   index = sentdata / 16: IF index = $2 then Control
   LOW RS
    PULSOUT E,1
   HIGH RS 
    GOTO Main
    
Control: 
   SELECT CASE sentdata
   case  $20  low c.0
   case  $21 high c.0
   case  $22  low c.1
   case  $23 high c.1
   case  $24  low c.2
   case  $25 high c.2
   END SELECT
    GOTO Main
Code:
	#picaxe 18m2    'version 2.A * 4 BIT SERIAL DRIVER 9600 baud * marks							
	#terminal off	
'            DB7  = C.3	
'            DB6  = C.2	
'            DB5  = C.1	
'            DB4  = C.0	           
      SYMBOL Rx   = C.5
	SYMBOL E    = B.6			                  
	SYMBOL RS   = B.7			                  
	SYMBOL senddata    = b0	 SYMBOL sentdata    = b0			
	SYMBOL index       = b1
	SYMBOL batV        = b2 
	SYMBOL ADCval      = b3
      SYMBOL D1          = b4 
	SYMBOL D2          = b5 
	
	EEPROM 0 ,($03,$03,$03,$02,$02,$08,$0,$0C,$0,$01)'(4Bit)(2line/5x8)(Display On)(Clear Display)	 16  8  4  2  1                                                
      EEPROM 10,(6 ,9 ,9 ,6 ,0 ,0 ,0 ,0) ' load custom character (o) =0                                 *  '  '  '  *  17
      EEPROM 18,(14,17,17,31,17,17,0 ,0) ' load custom character (A) =1                                 *  *  '  *  *  27
      EEPROM 26,(30,17,17,30,16,16,0 ,0) ' load custom character (P) =2                                 *  '  *  '  *  21
      EEPROM 34,(17,27,21,17,17,17,0 ,0) ' load custom character (M) =3                                 *  '  '  '  *  17
      EEPROM 42,(14,17,16,16,17,14,0 ,0) ' load custom character (C) =4                                 *  '  '  '  *  17
      EEPROM 50,(30,16,16,28,16,16,0 ,0) ' load custom character (F) =5                                 *  '  '  '  *  17
      EEPROM 58,(0 ,31,1 ,31,16,16,31,0) ' load custom character (2) =6                                 '  '  '  '  '  0
      EEPROM 66,(14,10,14,0 ,14,10,10,0) ' load custom character (on)=7                                 '  '  '  '  '  0
                                         '                                                           custom character example (M)=3
	CALIBADC10 ADCval
      SETFREQ M32
 	dirsB = %11101101			
 	dirsC = %00001111								
 	batV = 10475 / ADCval
      BinToAscii batV,D2,D2,D1 
      
Initialise: 	
	FOR  index = 0 to 9                                               
          READ index, senddata : pinsC = senddata : PULSOUT E,1 ' Initialise LCD						
 	NEXT index : PAUSE 10
 	
DisplaySupply:
	HIGH RS
      FOR  index = 0 TO 15
 	    LOOKUP index,("LCD Supply ",D2,".",D1,"V "),sentdata 
 	                           pinsC = senddata / 16 : PULSOUT E,1 : pinsC = senddata : PULSOUT E,1 ' sending characters to line one 
      NEXT index

LoadCustomCharactersFromEEPROM:
       LOW RS : senddata = $40 : pinsC = senddata / 16 : PULSOUT E,1 : pinsC = senddata : PULSOUT E,1 : HIGH RS ' Load Characters to LCD	
 	FOR  index =10 TO 73                 
 	    READ index, senddata : pinsC = senddata / 16 : PULSOUT E,1 : pinsC = senddata : PULSOUT E,1 ' sending characters to LCD      
 	NEXT index    
 
' TestCustomCharacters:
'       LOW RS  :senddata = 192 : pinsC = senddata / 16 : PULSOUT E,1 : pinsC = senddata : PULSOUT E,1  '(192-211) Line 2 Cursor Position
'      HIGH RS
'      FOR  index = 0 TO 12
' 	    LOOKUP index,("Test ",0,1,2,3,4,5,6,7),senddata 
' 	                            pinsC = senddata / 16 : PULSOUT E,1 : pinsC = senddata : PULSOUT E,1 ' sending characters to line two 
'      NEXT index
 
Main:
    bptr=28
   SERIN Rx,N9600_32,@bptr
   IF @bptrinc = 254 THEN Commands
   SERIN [10],Rx,N9600_32,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc
    @bptr = 254
     bptr = 28
       do until @bptr = 254
        pinsC = @bptr / 16 : PULSOUT E,1 : pinsC = @bptrinc : PULSOUT E,1
       loop
   GOTO Main
   
Commands:
   SERIN Rx,N9600_32,sentdata
   pinsC = sentdata / 16 
   IF pinsc = $2 then Control 
   LOW RS
    PULSOUT E,1 : pinsC = sentdata : PULSOUT E,1
   HIGH RS 
    GOTO Main
    
Control: 
   SELECT CASE sentdata
   case  $20  low b.0
   case  $21 high b.0
   case  $22  low b.5
   case  $23 high b.5
   case  $24  low b.2
   case  $25 high b.2
   case  $26  low b.3
   case  $27 high b.3
   END SELECT
    GOTO Main
 

Attachments

marks

Senior Member
4 BIT OLED/LCD DRIVER FOR THE 20x2 using 9600Bps or Hi2C fast/slow

9600 Bps works really well on 20x2 driving a 4Bit OLED/LCD (B.0,B.1,B.2,B.3)
without using background receive
and our sending picaxe doesnt need any pauses
unlike the 18m2 driver that required a pause 4 at 32mhz from our sending picaxe.

We can also use Hi2C fast or slow to drive an OLED/LCD just use the same codes
we do need a few pauses tho example in the testdrive code.
i dont think we need another drawing every ones had enuff
2k pullups recommended for Hi2c and
for serial a 10k pulldown should be used.

default is usually 9600 mode if we want Hi2C power off
and power on both boards together so it can catch the interupt before it gets into 9600 serial mode.
Code:
#picaxe 18m2  ' version 2.A * Testdrive  4bit/20x2 Serial driver * marks
SETFREQ M32
                                  
main:
serout c.0,n9600_32,(254,192)   ' Command Line 2 Cursor Position

serout c.0,n9600_32,("* *   9600 bps..")

serout c.0,n9600_32,(254,$21) ' Control A0 high
pause 4000
              
serout c.0,n9600_32,(254,192)   ' Command Line 2 Cursor Position

serout c.0,n9600_32,(" * *  9600 bps..") 

serout c.0,n9600_32,(254,$20) ' Control A0 low  
pause 4000
goto main
Code:
picaxe 18m2  ' version 2.A * Testdrive  4bit/20x2 Hi2C driver * marks
SETFREQ M32

HI2CSETUP I2CMASTER,%10100000,I2Cfast_32,I2Cbyte
pause 4000
main:

HI2COUT 0,(254,192) ' Command Line 2 Cursor Position
pause 10
HI2COUT 0,("*    Hi2C ABCDEF")
pause 40
HI2COUT 0,(254,$21) ' Control A0 high
pause 4000 '15 minimum
HI2COUT 0,(254,192)
pause 10
HI2COUT 0,(" *   Hi2C ABCDEF")
pause 40
HI2COUT 0,(254,$20) ' Control A0 low
pause 4000 '15 minimum

HI2COUT 0,(254,192) ' Command Line 2 Cursor Position
pause 10
HI2COUT 0,("  *  Hi2C ABCDEF")
pause 40
HI2COUT 0,(254,$21) ' Control A0 high
pause 4000 '15 minimum 
HI2COUT 0,(254,192)
pause 10
HI2COUT 0,("   * Hi2C ABCDEF")
pause 40
HI2COUT 0,(254,$20) ' Control A0 low
pause 4000 '15 minimum

goto main
Code:
	#picaxe 20X2 ' version C.0 * 20x2 LCD/OLED driver 4Bit (9600Bps or Hi2C fast/slow )* marks						
	#no_data
	#terminal off
'            SCK	   = B.7
'            SDA     = B.5			
'            DB7     = B.3	
'            DB6     = B.2	
'            DB5     = B.1	
'            DB4     = B.0	        	
	SYMBOL E       = c.3
      SYMBOL RS      = c.2       				                  
     	SYMBOL Rx      = c.7	                  
	SYMBOL senddata = b0 : SYMBOL sentdata = b0 		
	SYMBOL index    = b1
	
	TABLE   0, ($3,$3,$3,$2,$2,$8,$0,$C,$0,$1,$0,$2,$0,$6)  '(4Bit)(2line/5x8)(Display On)(Clear Display)(Return Home)(Entry Mode Set)
	TABLE  40, ("marks......")
		
	SETFREQ M64
	HI2CSETUP I2CSLAVE, %10100000
 	dirsB = %00001111			
 	dirsC = %10111111
 	SETINTFLAGS %01000000 , %01000000
 								
IntialiseDisplay: 
      FOR  index = 0 to 13                                               
READTABLE index, senddata : outpinsB = senddata : PULSOUT E,1 ' Initialise LCD/OLED 
 	NEXT index  :  PAUSE 10	
 	 	
Display:
      LOW RS                                                                                                                              
      senddata = 128 : outpinsB = senddata >> 4 : PULSOUT E,1 : outpinsB = senddata : PULSOUT E,1'(128-147) Line 1 Cursor Position
      HIGH RS                                                                                                                              
               
      FOR index = 40 TO 50                                                   
READTABLE index, senddata 
 	   outpinsB = senddata >> 4 : PULSOUT E,1 : outpinsB = senddata : PULSOUT E,1 ' sending characters to line one
 	   pause 500     
 	NEXT index
                                   
 Main:
  SERIN Rx,N9600_64,sentdata
   IF sentdata = 254 THEN Commands
   outpinsB = sentdata >> 4 : PULSOUT E,1 : outpinsB = sentdata : PULSOUT E,1
   GOTO main
   
 Commands:
   SERIN Rx,N9600_64,sentdata
    outpinsB = sentdata >> 4 
    IF outpinsB = $2 then Control 
    LOW RS : PULSOUT E,1 : outpinsB = sentdata : PULSOUT E,1 : HIGH RS
    GOTO Main
    
 Control: 
    SELECT CASE sentdata
    case  $20  low a.0
    case  $21 high a.0
    END SELECT
    GOTO Main
   
  Hi2C: 
  ptr = 0
  hi2cflag = 0
  HI2CSETUP I2CSLAVE , %10100000
  SETINTFLAGS %01000000 , %01000000 
                               
Interrupt:
PAUSE 1000
 ptr = 0
 IF @ptrinc = 254 THEN CommandsHi2c
 FOR  ptr = 0 TO hi2clast 
 outpinsB = @ptr >> 4  PULSOUT E,1 : outpinsB = @ptr  PULSOUT E,1 
 NEXT ptr                                      
 GOTO Hi2C
 
 CommandsHi2c:
 outpinsB = @ptr >> 4
 IF outpinsB = $2 THEN ControlHi2c 
 LOW RS : PULSOUT E,1 : outpinsB = @ptr : PULSOUT E,1 : HIGH RS   
 GOTO Hi2C 
 
 ControlHi2c: 
    SELECT CASE @ptr
    case  $20  low a.0
    case  $21 high a.0
    END SELECT
    GOTO Hi2C
 
Last edited:

marks

Senior Member
Use your supplied 8 BIT Serial Board with your OLED at 4800 Bps

This is turning into a bit of a blog hope nobody minds lol!
Well I just couldn't wait for a blue one ending up with a 20x4 OLED
yellow on black from techsupplies.(Fast n Easy I think i'll being going direct from now on)

(was happy to get version 2.D on my 18m2)
On the supplied serial driver does not use the standard pinouts for lcd's with backlight being 15 and 16
A tantulam capacitor can be easily added for smoother supply if using the adc's where the contrast pot would usually go.

Not much time to roadtest this weekend >
The brightness was not a problem like some report'
nice and clear and can be seen from some distance.
The specs are 30ma @ 5v with a brightness level of 125 nits
with a minimum of 3v and 80 nits hardly noticing any drop in brightness
although it still works down to about 2v.
So for displays that are always on those wanting longer life i guess 3v is best.

I did have too change the code slightly it behaves just like an lcd should.
So for those wanting to try 4800 bps with there OLED some example code follows!
Really its what should be used for an lcd so this code can be used for both without change.
After reprogramming the code resets the OLED so no need to power off and on !
Default character font is EnglishJapanese which everyone seems to be most familiar with.

Well verdict I guess everyone should have at least 1 lol!
I do wonder how it compares to one of those RGB on Black LCD's (good if they supplied these too lol)
Code:
#picaxe 18m2  ' version 2.A * Testdrive 4bit/8bit Serial driver boards* marks
SETFREQ M32

main:
serout c.0,n4800_32,(254,192)   ' Command Line 2 Cursor Position
serout c.0,n4800_32,("can't wait for a")

  serout c.0,n4800_32,(254,$21) ' Control High OUTPUT 1
pause 5000
              
serout c.0,n4800_32,(254,192)   ' Command Line 2 Cursor Position
serout c.0,n4800_32,("blue Oled  Santa") 

  serout c.0,n4800_32,(254,$20) ' Control Low OUTPUT 1  
pause 5000
goto main
Code:
	#picaxe 18m2    'version 2.D * 8 BIT SERIAL DRIVER OLED FRIENDLY 4800 baud * marks							
	#terminal off	
'            DB7  = B.7	
'            DB6  = B.6	
'            DB5  = B.5	
'            DB4  = B.4	
'            DB3  = B.3	
'            DB2  = B.2	
'            DB1  = B.1		
'            DB0  = B.0
      SYMBOL Rx   = C.5
	SYMBOL E    = C.6			                  
	SYMBOL RS   = C.7			                  
	SYMBOL senddata    = b0	 SYMBOL sentdata    = b0
	SYMBOL index       = b1
	SYMBOL batV        = b2 
	SYMBOL ADCval      = b3
      SYMBOL D1          = b4 
	SYMBOL D2          = b5 
	
	EEPROM 0 ,($38,$38,$38,$0C,$01)      '(Function 8bit/2line/5x8)(Display On)(Clear Display)   16  8  4  2  1
	EEPROM 5 ,($2,$6)                    '(Return Home)(Entry Mode Set) 
      EEPROM 10,(6 ,9 ,9 ,6 ,0 ,0 ,0 ,0)   ' load custom character (o) =0                           *  '  '  '  *  17
      EEPROM 18,(14,17,17,31,17,17,0 ,0)   ' load custom character (A) =1                           *  *  '  *  *  27
      EEPROM 26,(30,17,17,30,16,16,0 ,0)   ' load custom character (P) =2                           *  '  *  '  *  21
      EEPROM 34,(17,27,21,17,17,17,0 ,0)   ' load custom character (M) =3                           *  '  '  '  *  17
      EEPROM 42,(14,17,16,16,17,14,0 ,0)   ' load custom character (C) =4                           *  '  '  '  *  17
      EEPROM 50,(30,16,16,28,16,16,0 ,0)   ' load custom character (F) =5                           *  '  '  '  *  17
      EEPROM 58,(0 ,31,1 ,31,16,16,31,0)   ' load custom character (2) =6                           '  '  '  '  '  0
      EEPROM 66,(14,10,14,0 ,14,10,10,0)   ' load custom character (on)=7                           '  '  '  '  '  0
                                           '                                                     custom character example (M)=3
	CALIBADC10 ADCval
      SETFREQ M32
 	dirsB = %11111111			
 	dirsC = %11001111			
 	batV = 10475 / ADCval
      BinToAscii batV,D2,D2,D1 
      
Initialise: 	
	FOR  index = 0 to 6                                               
          READ index, senddata : pinsB = senddata : PULSOUT E,1           ' Initialise OLED	
 	NEXT index : PAUSE 10
  	
DisplaySupply:
	HIGH RS
      FOR  index = 0 TO 15
 	    LOOKUP index,("OLED Supply ",D2,".",D1,"V"),senddata 
 	                           pinsB = senddata : PULSOUT E,1           ' sending characters to line one 
      NEXT index

LoadCustomCharactersFromEEPROM:
       LOW RS : senddata = $40 : pinsB = senddata : PULSOUT E,1 : HIGH RS ' Load Custom Characters into OLED	
 	FOR  index =10 TO 73                 
 	    READ index, senddata : pinsB = senddata : PULSOUT E,1           ' sending characters to OLED      
 	NEXT index    
 
      TestCustomCharacters:
           LOW  RS  :senddata = 192 : pinsB = senddata : PULSOUT E,1      '(192-211) Line 2 Cursor Position
           HIGH RS
           FOR  index = 0 TO 13
 	          LOOKUP index,("Test ",0,1,2,3,4,5,6,7,223),senddata 
 	          pinsB = senddata : PULSOUT E,1                            ' sending characters to line two 
           NEXT index
Main:
   SERIN Rx,N4800_32,sentdata
   
   IF sentdata = 254 THEN Commands
   pinsB = sentdata : PULSOUT E,1
   GOTO Main
   
Commands:
   SERIN Rx,N4800_32,sentdata
   pinsB = sentdata 
   index = sentdata / 16: IF index = $2 then Control
   LOW RS
    PULSOUT E,1
   HIGH RS 
    GOTO Main
    
Control: 
   SELECT CASE sentdata
   case  $20  low c.0
   case  $21 high c.0
   case  $22  low c.1
   case  $23 high c.1
   case  $24  low c.2
   case  $25 high c.2
   END SELECT
    GOTO Main
 
Last edited:

Captain Haddock

Senior Member
Marks.
I have your lcd code running on a 20x2 and just can't puzzle out how to get a variable to display on the lcd, I'm trying to do a readtemp as the tester, whats the trick to it?
I can get stuff pre-saved to tables onto it but making my head hurt with the variable direct.
 

marks

Senior Member
Hi Captain Haddock,
your not alone my head hurts too sometimes LOL!
the easiest way I,ve found is using the BINTOASCII and LOOKUP commands.
here's an example...
Code:
	#picaxe 18m2    'version 2.A  * 8 BIT SERIAL DRIVER OLED/LCD FRIENDLY * marks							
	#terminal off   'version 2.D  * tested O.K. also *	
'            DB7  = B.7	
'            DB6  = B.6	
'            DB5  = B.5	
'            DB4  = B.4	
'            DB3  = B.3	
'            DB2  = B.2	
'            DB1  = B.1		
'            DB0  = B.0
	SYMBOL Ds18b20 = C.0
      SYMBOL Rx      = C.5
	SYMBOL E       = C.6			                  
	SYMBOL RS      = C.7			                  
	SYMBOL senddata    = b0	 SYMBOL sentdata    = b0
	SYMBOL index       = b1
	SYMBOL ADCval      = b2
	SYMBOL SupplyV     = b3
	SYMBOL Temperature = W2  SYMBOL TempMsb  = b5  SYMBOL TempLsb = b4
	SYMBOL Sign        = b6
	SYMBOL D0          = b7
      SYMBOL D1          = b8 
	SYMBOL D2          = b9 
	SYMBOL D3          = b10 
	SYMBOL D4          = b11 

	EEPROM 0 ,($38,$38,$38,$C,$1,$2,$6)'(Function 8bit/2line/5x8)(Display On)(Clear Display)(Return Home)(Entry Mode Set)   	                                   '                                                             
	CALIBADC10 ADCval
      SETFREQ M32
 	dirsB = %11111111			
 	dirsC = %11001111			
 	SupplyV = 10475 / ADCval
      BinToAscii SupplyV,D2,D2,D1 
      
Initialise: 	
	FOR  index = 0 to 6                                               
          READ index, senddata : pinsB = senddata : PULSOUT E,1 ' Initialise OLED/LCD	
 	NEXT index : PAUSE 10
 	
DisplaySupplyAtPowerUp:
	HIGH RS                                                   ' charactermode
	
      FOR  index = 0 TO 14
 	    LOOKUP index,("   Supply ",D2,".",D1," V"),senddata 
 	                           pinsB = senddata : PULSOUT E,1 ' sending characters to line one 
      NEXT index : PAUSE 8000
    
ClearDisplay:
      LOW RS  :senddata = 1 : pinsB = senddata : PULSOUT E,1 : HIGH RS ' ClearDisplay
      
Main:
Readtemp12 Ds18b20,Temperature                               
                    
  Convert:                                      
       Sign = " "                                               '  Display +                                
    
     IF TempMsb > 127 THEN                       
       Sign = "-"                                               '  Display - 
     Temperature = - Temperature                                     
     ENDIF
     
     Temperature = Temperature * 25 / 4 + 5                     '  Celsius + rounding up 0.05 to 0.09 (0.1)resolutuion   
     
     BINTOASCII Temperature,D4,D3,D2,D1,D0  
      IF  D4 = "0" THEN : D4 = " "                              ' zero blanking 
       IF D3 = "0" THEN : D3 = " " : ENDIF                      ' zero blanking 
      ENDIF
         
   Display:
   LOW RS  :senddata = 192 : pinsB = senddata : PULSOUT E,1 : HIGH RS '(192-211) Line 2 Cursor Position
   
   FOR  index = 0 TO 15
    	    LOOKUP index,("  ",Sign, D4,D3,D2,".",D1,223,"Celsius"),senddata 
 	                           pinsB = senddata : PULSOUT E,1 ' sending characters to line one 
   NEXT index 

GOTO Main
 

Captain Haddock

Senior Member
Thanks Marks
At my level of axeing I'll probably stick to serial drivers for the projects on the go but I am going to keep playing with this as I love the idea of driving the display directly, I was chuffed just to see the 'marks-picaxe 20x2 ldc' come up:D
Thanks for all the hard work put in.
 

Captain Haddock

Senior Member
bintoascii,poke,and lookup seems to do the trick, I was originally assuming there was a way to just send the output in a similar way to the serout command with the serial driver.
I'll get there!
Many thanks again for the original code.
Edit:
Don't know why I thought I had to use the poke command, Doh!
After having more of a play it is surprisingly easy to use realy, is there a 20x2 version of the 4 bit code? I tried the convert wizard with the 18m2 version but with no luck, it'd be nice to free up a few pins, especially the hi2c pins.
 
Last edited:

marks

Senior Member
Hi Captain Haddock,
yes I can see there would be a problem with that conversion.

Post #20 already has (20x2 4bit for oled/lcd).
main: program which is the serial and hi2c driver

based on this drawing now provided
and heres some code too hope it helps ....

Unfortunately I may have confused many with the use of the 20x2 and 18m2 mixed in this thread
hopefully if it is read from start to finish it will be a bit more clearer for the end user.

Code:
	#picaxe 20X2 ' version C.0 * 20x2 4Bit LCD/OLED * marks						
	#no_data
	#terminal off
'            SCK	   = B.7
'            SDA     = B.5			
'            DB7     = B.3	
'            DB6     = B.2	
'            DB5     = B.1	
'            DB4     = B.0	        	
	SYMBOL E       = C.3
	SYMBOL RS      = C.2       				                  
     	SYMBOL Rx      = C.7
     	SYMBOL Ds18b20 = C.0	                  
	SYMBOL senddata = b0 : SYMBOL sentdata = b0 		
	SYMBOL index    = b1
	SYMBOL ADCval      = b2
	SYMBOL SupplyV     = b3
	SYMBOL Temperature = W2  SYMBOL TempMsb  = b5  SYMBOL TempLsb = b4
	SYMBOL Sign        = b6
	SYMBOL D0          = b7
	SYMBOL D1          = b8 
	SYMBOL D2          = b9 
	SYMBOL D3          = b10 
	SYMBOL D4          = b11 
	
	TABLE   0, ($3,$3,$3,$2,$2,$8,$0,$C,$0,$1,$0,$2,$0,$6)  '(4Bit)(2line/5x8)(Display On)(Clear Display)(Return Home)(Entry Mode Set)
	TABLE  40, ("marks......")
	CALIBADC10 ADCval	
	SETFREQ M64
	
 	dirsB = %00001111			
 	dirsC = %10111111
 	SupplyV = 10475 / ADCval
      BinToAscii SupplyV,D2,D2,D1
 								
IntialiseDisplay: 
      FOR  index = 0 to 13                                               
READTABLE index, senddata : outpinsB = senddata : PULSOUT E,1 ' Initialise LCD/OLED 
 	NEXT index  :  PAUSE 10	
 	 	
DisplayMarks:
      HIGH RS                                                 ' charactermode

      FOR index = 40 TO 50                                                   
READTABLE index, senddata 
 	  outpinsB = senddata >> 4 : PULSOUT E,1 : outpinsB = senddata : PULSOUT E,1 ' sending characters to line one
 	  pause 500     
 	NEXT index
 	
DisplaySupplyAtPowerUp:
	LOW RS  :senddata = 192  
        outpinsB = senddata >> 4 : PULSOUT E,1 : outpinsB = senddata : PULSOUT E,1 : HIGH RS '(192-211) Line 2 Cursor Position
	
      FOR  index = 0 TO 14
 	  LOOKUP index,("   Supply ",D2,".",D1," V"),senddata 
 	  outpinsB = senddata >> 4 : PULSOUT E,1 : outpinsB = senddata : PULSOUT E,1 ' sending characters 
      NEXT index : PAUSE 10000  
                                      
 Main:
Readtemp12 Ds18b20,Temperature 
          
  Convert:                                      
       Sign = " "                                                   '  Display +                                  
'    Temperature = Temperature  + 880 * 9 / 5 - 1072                 ' *uncomment for Fahrenheit (-67.0 to 257.0)
'    Temperature =  Temperature + 4370                               ' *uncomment for Kelvin     (218.1 to 398.1)    
     IF TempMsb > 127 THEN                       
       Sign = "-"                                                   '  Display - 
     Temperature = - Temperature                                     
     ENDIF 
    Temperature = Temperature  * 5 / 4 * 5 + 5                      '  Celsius (-55.0 to 125.0) rounding up 0.05 to 0.09    
     
     BINTOASCII Temperature,D4,D3,D2,D1,D0  
      IF  D4 = "0" THEN : D4 = " "                                  ' leading zero blanking 
       IF D3 = "0" THEN : D3 = " " : ENDIF                          ' leading zero blanking 
      ENDIF 
                               
  DisplayTemperature:
    LOW RS  :senddata = 192  
        outpinsB = senddata >> 4 : PULSOUT E,1 : outpinsB = senddata : PULSOUT E,1 : HIGH RS '(192-211) Line 2 Cursor Position
   
    FOR  index = 0 TO 15
    	  LOOKUP index,("  ",Sign, D4,D3,D2,".",D1,223,"Celsius"),senddata 
 	  outpinsB = senddata >> 4 : PULSOUT E,1 : outpinsB = senddata : PULSOUT E,1 ' sending characters to line one
    NEXT index 

GOTO Main
 

Attachments

Last edited:

Captain Haddock

Senior Member
Thanks again Marks, working in 20 seconds from pulling 8 bit circuit apart!
I think I may have got lost somewhere back in the thread, I've been through it a few times but always been in a rush due to looking at work.
 

Captain Haddock

Senior Member
been trying this on a 40x2 port D on a breadboard.(to suit pre-made board in a control box I have)
Is there any reason why I can't get pins 4-7 of a port to work in 4 bit mode? I've changed dirsD to %11110000/%00001111/%11111111 and can't seem to get anything happening, I've tried port B using pins 0-3 with no problems as well as 0-7 in 8 bit mode and that worked ok.
How do you get the pulseout to just work with the 4 top pins of the port?

I've edited this to take out all the bits I've found answers to as it was getting too confusing.
 
Last edited:

marks

Senior Member
Hi Captain Haddock,
No no reason ,I think you'll need to swap these lines as well

TABLE 0, ($30,$30,$30,$20,$20,$80,$0,$C0,$0,$10,$0,$20,$0,$60) '(4Bit)(2line/5x8)(Display On)(Clear Display)(Return Home)(Entry Mode Set)for pins 4 5 6 7
IntialiseDisplay: 'code stays the same

Send: ' statements become
outpinsB = senddata : PULSOUT E,1 : outpinsB = senddata << 4 : PULSOUT E,1 for pins 4 5 6 7

not tested just cut from the 20x2 code above , hopefully should work lol.
 
Last edited:

Captain Haddock

Senior Member
Thanks Marks I'll try that, I think I just got it stuck in my head that the pulseout was only working from the bottom of the port upwards, no idea why but once you get an idea it tends to stick, it's all good learning.
 

Captain Haddock

Senior Member
ARRGGH!
It's just not happening for me, I can't seem to get it working using db4-7 on outpinsD 4-7 with E on A.2 and RS on A.4 whatever I do.

Edit: I think I finally understand how it all works thanks to a reply by Hippy on the active picaxe forum, I now have a very simple program running on a 20x2 with 4bit pins spread all over the place just to see if it works.
Now back to the 40x2....
Thanks to all for all the help on this subject!:)
I also have a sneaking suspicion I have been getting stitched up by a dodgy jumper wire on my breadboard giving bad results and a lot of confusion :mad:

This is the code I now have working which may help others getting confused by working with nibbles:
Code:
       #picaxe 20X2 						
       #no_data
       #terminal off
       SYMBOL E       = C.2
       SYMBOL RS      = C.1      				                  
       SYMBOL senddata = b0  		
       SYMBOL index    = b1
       dirsB = %11111111			
       dirsC = %10111111
         								
Init: 
      FOR  index = 0 to 13                                               
      LOOKUP index,($38,$38,$38,$2,$2,$8,$0,$C,$0,$1,$0,$2,$0,$6),senddata 
      outpinB.4 = bit0 : outpinC.5 = bit1 : outpinB.6 = bit2 : outpinB.1 = bit3 
      PULSOUT E,1
      NEXT index  :  PAUSE 10	
         	 	
Main:
      senddata = 128 : gosub command
      FOR  index = 0 TO 9
      LOOKUP index,("    Hello!"),senddata : gosub display
      NEXT index 
      senddata = 192 : gosub command
      FOR  index = 0 TO 9
      LOOKUP index,("    World!"),senddata : gosub display
      NEXT index 
      PAUSE 1000  
      senddata = 1 : gosub command
      GOTO Main

display:
	outpinB.4 = bit4 : outpinC.5 = bit5 : outpinB.6 = bit6 : outpinB.1 = bit7 
	PULSOUT E,1 
	outpinB.4 = bit0 : outpinC.5 = bit1 : outpinB.6 = bit2 : outpinB.1 = bit3  
	PULSOUT E,1
	return  
	
command:
	LOW RS  
      outpinB.4 = bit4 : outpinC.5 = bit5 : outpinB.6 = bit6 : outpinB.1 = bit7 
      PULSOUT E,1 
      outpinB.4 = bit0 : outpinC.5 = bit1 : outpinB.6 = bit2 : outpinB.1 = bit3 
      PULSOUT E,1 : HIGH RS 
      return
 
Last edited:

marks

Senior Member
Hi Captain Haddock,

ARRGGH! noticed you were having fun lol!
got myself a 40x2 today to tryout "ouch" no lunch for 3 days.
and all those pins confused me too dont know what to do with em.
heres an example for you to try using D port D.4,D.5,D.6,D.7
and A.2 enable / A.3 RS
Code:
	#picaxe 40X2 ' version B.3 * 4Bit OLED/LCD * marks						
	#no_data
	#terminal off			
'            DB7     = D.7	
'            DB6     = D.6	
'            DB5     = D.5	
'            DB4     = D.4	        	
	SYMBOL E       = a.2
	SYMBOL RS      = a.3       				                  
   
     	SYMBOL Ds18b20 = C.0	                  
	SYMBOL senddata = b0 : SYMBOL sentdata = b0 		
	SYMBOL index    = b1
	SYMBOL ADCval      = b2
	SYMBOL SupplyV     = b3
	SYMBOL Temperature = W2  SYMBOL TempMsb  = b5  SYMBOL TempLsb = b4
	SYMBOL Sign        = b6
	SYMBOL D0          = b7
	SYMBOL D1          = b8 
	SYMBOL D2          = b9 
	SYMBOL D3          = b10 
	SYMBOL D4          = b11 
	
	TABLE   0, ($30,$30,$30,$20,$20,$80,$0,$C0,$0,$10,$0,$20,$0,$60)  '(4Bit)pins4567(2line/5x8)(Display On)(Clear Display)(Return Home)(Entry Mode Set)
	TABLE  40, ("CaptainHaddock..")
	CALIBADC10 ADCval	
	SETFREQ M16

 	dirsD = %11110000			
 	dirsA = %11111111
 	SupplyV = 10475 / ADCval
      BinToAscii SupplyV,D2,D2,D1
 								
IntialiseDisplay: 
      FOR  index = 0 to 13                                               
READTABLE index, senddata : outpinsD = senddata : PAUSE 2 : PULSOUT E,1 ' Initialise OLED/LCD
 	NEXT index  :  PAUSE 10	
 	 	
DisplayMarks:
      HIGH RS                                                                      ' charactermode
      FOR index = 40 TO 55                                                   
READTABLE index, senddata 
 	  outpinsD = senddata  : PULSOUT E,1 : outpinsD = senddata << 4: PULSOUT E,1 ' sending characters to line one
 	  pause 800     
 	NEXT index
 	
DisplaySupplyAtPowerUp:
	LOW RS  :senddata = 192  
        outpinsD = senddata  : PULSOUT E,1 : outpinsD = senddata << 4: PULSOUT E,1 : HIGH RS '(192-211) Line 2 Cursor Position
	
      FOR  index = 0 TO 14
 	  LOOKUP index,("   Supply ",D2,".",D1," V"),senddata 
 	  outpinsD = senddata  : PULSOUT E,1 : outpinsD = senddata << 4: PULSOUT E,1 ' sending characters 
      NEXT index : PAUSE 4000 
       
Clearline:
 	LOW RS  :senddata = 128  
        outpinsD = senddata  : PULSOUT E,1 : outpinsD = senddata << 4: PULSOUT E,1 : HIGH RS '(128-147) Line 1 Cursor Position
	
      FOR  index = 0 TO 15
 	  Let senddata =" "
 	  outpinsD = senddata  : PULSOUT E,1 : outpinsD = senddata << 4: PULSOUT E,1 ' sending characters
 	  pause 200 
      NEXT index
                                           
 Main:
Readtemp12 Ds18b20,Temperature 
          
  Convert:                                      
       Sign = " "                                                   '  Display +                                  
'    Temperature = Temperature  + 880 * 9 / 5 - 1072                 ' *uncomment for Fahrenheit (-67.0 to 257.0)
'    Temperature =  Temperature + 4370                               ' *uncomment for Kelvin     (218.1 to 398.1)    
     IF TempMsb > 127 THEN                       
       Sign = "-"                                                   '  Display - 
     Temperature = - Temperature                                     
     ENDIF 
    Temperature = Temperature  * 5 / 4 * 5 + 5                      '  Celsius (-55.0 to 125.0) rounding up 0.05 to 0.09    
     
     BINTOASCII Temperature,D4,D3,D2,D1,D0  
      IF  D4 = "0" THEN : D4 = " "                                  ' leading zero blanking 
       IF D3 = "0" THEN : D3 = " " : ENDIF                          ' leading zero blanking 
      ENDIF 
                               
  DisplayTemperature:
    LOW RS  :senddata = 192  
        outpinsD = senddata  : PULSOUT E,1 : outpinsD = senddata << 4: PULSOUT E,1 : HIGH RS '(192-211) Line 2 Cursor Position
   
    FOR  index = 0 TO 15
    	  LOOKUP index,("  ",Sign, D4,D3,D2,".",D1,223,"Celsius"),senddata 
 	  outpinsD = senddata  : PULSOUT E,1 : outpinsD = senddata << 4: PULSOUT E,1 ' sending characters to line one
    NEXT index 

GOTO Main
 

wlie

Member
Problems with transmission to LCD

Following this thread, I tried to play around with an equivalent LCD, but have run into the following problem.
In the following program fragments I try to change to a lower frequency in the LCD program. I've tried to change the transmission speed accordingly so that when I change to M16 I also change the transmission to N4800_16. What I'd like to achieve is to run the program in "standard" rate. But the transmission only works when the numbers are unchanged, as shown.

LCD prg.:
Code:
	#picaxe 18m2 						
	#terminal off	

	SYMBOL Rx   = C.5
	SYMBOL E    = C.6			                  
	SYMBOL RS   = C.7			                  
	SYMBOL senddata    = b0	 			
	SYMBOL index       = b1
	SYMBOL batV        = b2 
	SYMBOL ADCval      = b3
     SYMBOL D1          = b4 
	SYMBOL D2          = b5 
	SYMBOL baud = N4800_32
	
	SETFREQ M32
	
	EEPROM 0 ,($38,$38,$38,$0C,$01)    '(Function 8bit/2line/5x8)(Display On)(Clear Display)	 16  8  4  2  1                                                
	EEPROM 10,($00,$00,$1A,$05,$0F,$14,$0F,$00);æ=0
	EEPROM 18,($00,$00,$01,$0E,$15,$15,$0E,$10);ø=1
	EEPROM 26,($04,$00,$0E,$01,$0F,$11,$0f,$00);å=2
	EEPROM 34,($07,$0C,$14,$17,$1C,$14,$17,$00);Æ=3
	EEPROM 42,($01,$0E,$13,$15,$19,$0E,$10,$00);Ø=4
	EEPROM 50,($04,$0A,$04,$0E,$11,$1F,$11,$00);Å=5
	EEPROM 58,(0 ,31,1 ,31,16,16,31,0)
	EEPROM 66,(14,10,14,0 ,14,10,10,0)

 	dirsB = %11111111			
 	dirsC = %11001111								

Initialise: 	
	FOR  index = 0 to 4                                               
     	READ index, senddata
          pinsB = senddata
          PULSOUT E,1 ' Initialise LCD						
 	NEXT index
 	PAUSE 10

LoadCustomCharactersFromEEPROM:
     LOW RS
     senddata = $40
     pinsB = senddata
     PULSOUT E,1
     HIGH RS ' Load Characters to LCD	
 	FOR  index =10 TO 73                 
 	    	READ index, senddata
 	    	pinsB = senddata
 	     PULSOUT E,1 ' sending characters to LCD      
 	NEXT index    
 
 TestCustomCharacters:
     LOW RS
     senddata = 192
     pinsB = senddata
     PULSOUT E,1 '(192-211) Line 2 Cursor Position
 	HIGH RS
     FOR  index = 0 TO 12
 	    	LOOKUP index,("Test ",0,1,2,3,4,5,6,7),senddata 
 	    	pinsB = senddata
 	    	PULSOUT E,1 ' sending characters to line two 
    	NEXT index

Main:
   	SERIN Rx,baud,senddata
   	IF senddata = 254 then Commands
   	pinsB = senddata
   	PULSOUT E,1
   	GOTO Main
   
Commands:
   	SERIN Rx,baud,senddata
   	pinsB = senddata 
   	index = senddata / 16
   	IF index = $2 then Control
   	LOW RS
   	PULSOUT E,1
   	HIGH RS 
   	GOTO Main
    
Control: 
   	SELECT CASE senddata
   	case  $20 low c.0
   	case  $21 high c.0
   	case  $22 low c.1
   	case  $23 high c.1
   	case  $24 low c.2
   	case  $25 high c.2
   	END SELECT
    	GOTO Main
Transmission Prg.:
Code:
#PICAXE 08m2
#Terminal off
#No_Data

	SYMBOL baud = N4800_16

	SETFREQ M16
	pause 500

main:
	if pin3 = 0 then main
	serout 1,baud, (254,1)
	pause 30
	serout 1,baud, (254,128)
	pause 10
	SerOut 1, baud, ("Hallo ",0,1,2,3,4,5);Shows "Hallo æøåÆØÅ"

	Do
		serout 1,baud, (254,192)
		serout 1,baud,(#w5)
		if w5 = 65535 then gosub clear1
		inc w5
		pause 500
	Loop

clear1:
	serout 1,baud, (254,192)
	serout 1,baud,("     ")
	return
Maybe I don't understand the relationship between Setfreq and Baudmode??
Any hints?
 

marks

Senior Member
Hi wlie,
thanks for your interest

Your receiving 18m2 with the lcd program needs to run at 32mhz so it is fast enough
to process a serial stream at 4800 baud.

processor time is needed to update the display between each byte sent in a serial stream.
At 16mhz you'll proberly only achieve 2400 baud.
 

wlie

Member
Thanks Marks

This cleared every things for me - it now works like I want it to do.
And also the part which translate the 6 special danish characters.

(Sorry if my English is difficult to understand - I read it better than I write it)
 

marks

Senior Member
Initialising a LCD or OLED on the AXE132.

Its good to see there's been plenty of interest LCD's lately
As some are just after some simple code to get them started
here's some we can try on the AXE132 using 8Bit or 4Bit.

If our Display fails to initialise at Power up we can wake it up by sending (Wakeup) ($30,$30,$30)
Newer Displays will also reset by sending (Reset)($0,$0,$0,$0,$0)

8Bit command sequence.
($38,$38,$38) combined wakeup and function set 8Bit/2line
($0C) Display On / no cursor
($01) Clear Display
($02) Send Home
($06) Entry Mode
Code:
#picaxe 18m2  '  AXE132 8Bit marks
'           DB7  = B.7
'           DB6  = B.6
'           DB5  = B.5
'           DB4  = B.4
'           DB3  = B.3
'           DB2  = B.2
'           DB1  = B.1
'           DB0  = B.0
 SYMBOL Rx  = C.5
 SYMBOL  E  = C.6
 SYMBOL RS  = C.7
 SYMBOL senddata    = pinsb
 SYMBOL index       = b0

      SETFREQ M32
 	dirsB = %11111111
 	dirsC = %11001111
 
Initialise: 	
	FOR  index = 0 to 6 
          LOOKUP index, ($38,$38,$38,$0F,$01,$02,$06),senddata : PULSOUT E,1 ' Initialise LCD/OLED
          '(8bit/2line/5x8)*3(Display On/flashing Cursor)(Clear Display)(Return Home)(Entry Mode Set)
 	NEXT index : PAUSE 10 

      Display:
            LOW  RS                                     ' commandmode 
            senddata = $01 : PULSOUT E,1  : PAUSE 12    ' Clear Display 
            senddata = 132 : PULSOUT E,1                ' (128-147) Line 1 Cursor Position

           HIGH RS                                      ' charactermode
           FOR  index = 0 TO 12
 	          LOOKUP index,("18M2 Picaxe!!"),senddata 
 	                       PULSOUT E,1                ' sending characters  
           NEXT index
The same command sequence for 4Bit
$28 sets the Function to 4Bit/2line
after being set to 4Bit mode the command word is sent in two parts.
Code:
#picaxe 18m2  '  AXE132 4Bit marks
'            DB7  = B.7
'            DB6  = B.6
'            DB5  = B.5
'            DB4  = B.4
 SYMBOL Rx   = C.5
 SYMBOL E    = C.6
 SYMBOL RS   = C.7
 SYMBOL senddata  = pinsb
 SYMBOL index     = b0

      SETFREQ M32
 	dirsB = %11111111
 	dirsC = %11001111 
Initialise: 	
	FOR  index = 0 to 6                                             
          LOOKUP index, ($33,$32,$28,$0C,$01,$02,$06),senddata : GOSUB Send    ' Initialise LCD/OLED
                       '(WakeUp)*3(Set4Bit)(4Bit/2Line)(DisplayOn)(Clear Display)(Return Home)(Entry Mode Set)
 	NEXT index : PAUSE 10

          Display:
            LOW  RS                                                                      ' commandmode
            senddata = $01 :                                     GOSUB Send : PAUSE 10   ' Clear Display 
            senddata = 192 :                                     GOSUB Send              ' (192-211) Line 2 Cursor Position

           HIGH RS                                                                       ' charactermode
           FOR  index = 0 TO 12
 	        LOOKUP index,("Axe132 Picaxe"),senddata :        GOSUB Send              ' sending characters
pause 1000 
           NEXT index
pause 500
goto display

       Send:
       PULSOUT E,1 : senddata = senddata*16 : PULSOUT E,1 :      RETURN
Picaxe18M2 (Count seconds INCremented by simple loop)
Code:
#picaxe 18m2  '  4Bit Using Alternative pins marks
 SYMBOL DB7  = outpinB.5
 SYMBOL DB6  = outpinB.4
 SYMBOL DB5  = outpinB.3 
 SYMBOL DB4  = outpinB.2 
 SYMBOL E    = B.1  
 SYMBOL RS   = B.0  
 SYMBOL senddata  = b0
 SYMBOL index     = b1
      'value of count    = W1    ' b3,b2
      'display  count    = b4,b5,b6,b7,b8

      
      EEPROM 25,("Picaxe18M2")
      SETFREQ M32
 	dirsB = %11111111
 	dirsC = %11001111
 
Initialise: 	
	FOR  index = 0 to 6 
          LOOKUP index, ($33,$32,$28,$0C,$01,$02,$06),senddata : GOSUB Send    ' Initialise LCD/OLED
                       '(WakeUp)*3(Set4Bit)(4Bit/2Line)(DisplayOn)(Clear Display)(Return Home)(Entry Mode Set)
 	NEXT index : PAUSE 10
  
      DisplayHello:
            LOW  RS                                                                      ' commandmode
            senddata = 132 :                                     GOSUB Send              ' (128-147) Line 1 Cursor Position
           HIGH RS                                                                       ' charactermode
            senddata = "H" :                                     GOSUB Send
            senddata = "e" :                                     GOSUB Send
            senddata = "l" :                                     GOSUB Send
            senddata = "l" :                                     GOSUB Send
            senddata = "o" :                                     GOSUB Send
pause 10000
            LOW  RS                                                                      ' commandmode
            senddata = $01 :                                     GOSUB Send : PAUSE 10   ' Clear Display
            senddata = 192 :                                     GOSUB Send              ' (192-211) Line 2 Cursor Position
           HIGH RS                                                                       ' charactermode 
           FOR  index = 25 to 34
           READ index, senddata :                                GOSUB Send              ' sending character    
 	     NEXT index 
pause 4000

      Count1:
            LOW  RS                                                                      ' commandmode 
            senddata = 202 :                                     GOSUB Send              ' (192-211) Line 2 Cursor Position
      HIGH RS                                                                            ' charactermode 
      INC W1                                                                             ' add to W1
           BinToAscii W1,b8,b7,b6,b5,b4
           FOR  index = 0 TO 5                                                           ' sending characters
 	     LOOKUP index,(" ",b8,b7,b6,b5,b4),senddata :          GOSUB Send                 
           NEXT index
      PAUSE 8000                                                                         ' 1 second (M32)   
            
goto count1

       Send:
         DB7 =   bit7    	
         DB6 =   bit6    	
         DB5 =   bit5    	
         DB4 =   bit4   	
        PULSOUT E,1 
         DB7 =   bit3   	
         DB6 =   bit2    	
         DB5 =   bit1    
         DB4 =   bit0   	
        PULSOUT E,1        :                                     RETURN
Picaxe18X (Counter INCremented by INPUT1)
Code:
#picaxe 18x  '  4Bit Using Alternative pins marks
#terminal off
 SYMBOL DB7  = outpin5      	
 SYMBOL DB6  = outpin4    	
 SYMBOL DB5  = outpin3    	
 SYMBOL DB4  = outpin2    	
 'reset pin leg4 for 18x 4.7k to V+
 SYMBOL E   = B.1 
 SYMBOL RS  = B.0        
 SYMBOL InputSensor = INPUT1
 SYMBOL senddata  = b0
 SYMBOL index     = b1
 SYMBOL Counter   = W1  ' b3,b2
 '  display CounterValue  = b4,b5,b6,b7,b8

      
      EEPROM 25,("GO Speedy ")
      SETFREQ M8
 Initialise: 	
	FOR  index = 0 to 6 
          LOOKUP index, ($33,$32,$28,$0C,$01,$02,$06),senddata : GOSUB Send    ' Initialise LCD/OLED
                       '(WakeUp)*3(Set4Bit)(4Bit/2Line)(DisplayOn)(Clear Display)(Return Home)(Entry Mode Set)
 	NEXT index : PAUSE 10

        DisplaySpeedy:           
            LOW  RS                                                                      ' commandmode
            senddata = $01 :                                     GOSUB Send : PAUSE 10   ' Clear Display
            senddata = 192 :                                     GOSUB Send              ' (192-211) Line 2 Cursor Position
           HIGH RS                                                                       ' charactermode 
           FOR  index = 25 to 34
           READ index, senddata :                                GOSUB Send              'sending character    
 	     NEXT index 
     
      DisplayCount:
            LOW  RS                                                                      ' commandmode 
            senddata = 202 :                                     GOSUB Send              ' (192-211) Line 2 Cursor Position
      HIGH RS                                                                            ' charactermode 
           BinToAscii Counter,b8,b7,b6,b5,b4
           FOR  index = 0 TO 5                                                           ' sending characters
 	     LOOKUP index,(" ",b8,b7,b6,b5,b4),senddata :          GOSUB Send                 
           NEXT index

         DO      
        IF InputSensor = 1 then Count1                                                   ' INPUT PIN as per SYMBOL
         LOOP
 
      Count1:
        IF InputSensor = 1 then Count1 : PAUSE 100                                       ' debounce abit
      Counter = Counter +1
      IF Counter > 9999 THEN : Counter = 0 : ENDIF                                       ' reset to zero
      
      GOTO DisplayCount

       Send:
         DB7 =   bit7
         DB6 =   bit6
         DB5 =   bit5
         DB4 =   bit4 
        PULSOUT E,1 
         DB7 =   bit3 
         DB6 =   bit2
         DB5 =   bit1
         DB4 =   bit0
        PULSOUT E,1                                    :         RETURN
See schematic for common 8Bit /4Bit Layouts.
When an LCD is first powered on without initialising . The first line will be filled with block characters, this is so contrast can easily be adjusted.
If nothing can be seen check contrast adjustment there should be about 0.6v between PIN1(GND) and PIN3(VO) of the LCD.
Your supply should also be around 4.7v to 5v PIN1(GND) and PIN2 (VDD) for adequate pixel brightness.
 

Attachments

Last edited:

ac21

Member
I'm using this code to drive a 20x4 display, but it looks like its setup for 16 character displays, I tried changing some of the code which i thought set it to 16 but didnt work

Code:
	#picaxe 18m2    'version 2.A * 4 BIT SERIAL DRIVER 9600 baud * marks							
	#terminal off	
'            DB7  = C.3	
'            DB6  = C.2	
'            DB5  = C.1	
'            DB4  = C.0	           
      SYMBOL Rx   = C.5
	SYMBOL E    = B.6			                  
	SYMBOL RS   = B.7			                  
	SYMBOL senddata    = b0	 SYMBOL sentdata    = b0			
	SYMBOL index       = b1
	SYMBOL batV        = b2 
	SYMBOL ADCval      = b3
      SYMBOL D1          = b4 
	SYMBOL D2          = b5 
	
	EEPROM 0 ,($03,$03,$03,$02,$02,$08,$0,$0C,$0,$01)'(4Bit)(2line/5x8)(Display On)(Clear Display)	 16  8  4  2  1                                                
      EEPROM 10,(6 ,9 ,9 ,6 ,0 ,0 ,0 ,0) ' load custom character (o) =0                                 *  '  '  '  *  17
      EEPROM 18,(14,17,17,31,17,17,0 ,0) ' load custom character (A) =1                                 *  *  '  *  *  27
      EEPROM 26,(30,17,17,30,16,16,0 ,0) ' load custom character (P) =2                                 *  '  *  '  *  21
      EEPROM 34,(17,27,21,17,17,17,0 ,0) ' load custom character (M) =3                                 *  '  '  '  *  17
      EEPROM 42,(14,17,16,16,17,14,0 ,0) ' load custom character (C) =4                                 *  '  '  '  *  17
      EEPROM 50,(30,16,16,28,16,16,0 ,0) ' load custom character (F) =5                                 *  '  '  '  *  17
      EEPROM 58,(0 ,31,1 ,31,16,16,31,0) ' load custom character (2) =6                                 '  '  '  '  '  0
      EEPROM 66,(14,10,14,0 ,14,10,10,0) ' load custom character (on)=7                                 '  '  '  '  '  0
                                         '                                                           custom character example (M)=3
	CALIBADC10 ADCval
      SETFREQ M32
 	dirsB = %11101101			
 	dirsC = %00001111								
 	batV = 10475 / ADCval
      BinToAscii batV,D2,D2,D1 
      
Initialise: 	
	FOR  index = 0 to 9                                               
          READ index, senddata : pinsC = senddata : PULSOUT E,1 ' Initialise LCD						
 	NEXT index : PAUSE 10
 	
DisplaySupply:
	HIGH RS
      FOR  index = 0 TO 15
 	    LOOKUP index,("LCD Supply ",D2,".",D1,"V "),sentdata 
 	                           pinsC = senddata / 16 : PULSOUT E,1 : pinsC = senddata : PULSOUT E,1 ' sending characters to line one 
      NEXT index

LoadCustomCharactersFromEEPROM:
       LOW RS : senddata = $40 : pinsC = senddata / 16 : PULSOUT E,1 : pinsC = senddata : PULSOUT E,1 : HIGH RS ' Load Characters to LCD	
 	FOR  index =10 TO 73                 
 	    READ index, senddata : pinsC = senddata / 16 : PULSOUT E,1 : pinsC = senddata : PULSOUT E,1 ' sending characters to LCD      
 	NEXT index    
 
' TestCustomCharacters:
'       LOW RS  :senddata = 192 : pinsC = senddata / 16 : PULSOUT E,1 : pinsC = senddata : PULSOUT E,1  '(192-211) Line 2 Cursor Position
'      HIGH RS
'      FOR  index = 0 TO 12
' 	    LOOKUP index,("Test ",0,1,2,3,4,5,6,7),senddata 
' 	                            pinsC = senddata / 16 : PULSOUT E,1 : pinsC = senddata : PULSOUT E,1 ' sending characters to line two 
'      NEXT index
 
Main:
    bptr=28
   SERIN Rx,N9600_32,@bptr
   IF @bptrinc = 254 THEN Commands
   SERIN [10],Rx,N9600_32,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc
    @bptr = 254
     bptr = 28
       do until @bptr = 254
        pinsC = @bptr / 16 : PULSOUT E,1 : pinsC = @bptrinc : PULSOUT E,1
       loop
   GOTO Main
   
Commands:
   SERIN Rx,N9600_32,sentdata
   pinsC = sentdata / 16 
   IF pinsc = $2 then Control 
   LOW RS
    PULSOUT E,1 : pinsC = sentdata : PULSOUT E,1
   HIGH RS 
    GOTO Main
this is what i'm sending

Code:
[color=Navy]#picaxe [/color][color=Black]08m2[/color]
[color=Navy]#no_data[/color]
[color=Blue]setfreq m8[/color]
[color=Black]init:[/color]
[color=Blue]pause [/color][color=Navy]1000 [/color][color=Green]; wait for display to initialise[/color]
[color=Black]main:[/color]
[color=Blue]do
serout [/color][color=Navy]0[/color][color=Black],[/color][color=Blue]n9600_8[/color][color=Black],[/color][color=Blue]([/color][color=Navy]254[/color][color=Black],[/color][color=Navy]1[/color][color=Blue])
pause [/color][color=Navy]2[/color]
[color=Blue]serout [/color][color=Navy]0[/color][color=Black],[/color][color=Blue]n9600_8[/color][color=Black],[/color][color=Blue]([/color][color=Navy]254[/color][color=Black],[/color][color=Navy]128[/color][color=Blue]) [/color][color=Green]; move to start of first line[/color]
[color=Blue]pause [/color][color=Navy]2     [/color]
[color=Blue]serout [/color][color=Navy]0[/color][color=Black],[/color][color=Blue]n9600_8[/color][color=Black],[/color][color=Blue]([/color][color=Red]""[/color][color=Blue]) [/color][color=Green]; output text[/color]
[color=Blue]pause [/color][color=Navy]2     [/color]
[color=Blue]serout [/color][color=Navy]0[/color][color=Black],[/color][color=Blue]n9600_8[/color][color=Black],[/color][color=Blue]([/color][color=Navy]254[/color][color=Black],[/color][color=Navy]192[/color][color=Blue]) [/color][color=Green]; move to start of first line[/color]
[color=Blue]pause [/color][color=Navy]2     [/color]
[color=Blue]serout [/color][color=Navy]0[/color][color=Black],[/color][color=Blue]n9600_8[/color][color=Black],[/color][color=Blue]([/color][color=Red]"88888888888888888885"[/color][color=Blue]) [/color][color=Green]; output text[/color]
[color=Blue]pause [/color][color=Navy]2     [/color]
[color=Blue]serout [/color][color=Navy]0[/color][color=Black],[/color][color=Blue]n9600_8[/color][color=Black],[/color][color=Blue]([/color][color=Navy]254[/color][color=Black],[/color][color=Navy]148[/color][color=Blue]) [/color][color=Green]; move to start of first line[/color]
[color=Blue]pause [/color][color=Navy]2     [/color]
[color=Blue]serout [/color][color=Navy]0[/color][color=Black],[/color][color=Blue]n9600_8[/color][color=Black],[/color][color=Blue]([/color][color=Red]"88888888888888888885"[/color][color=Blue]) [/color][color=Green]; output text[/color]
[color=Blue]pause [/color][color=Navy]2     [/color]
[color=Blue]serout [/color][color=Navy]0[/color][color=Black],[/color][color=Blue]n9600_8[/color][color=Black],[/color][color=Blue]([/color][color=Navy]254[/color][color=Black],[/color][color=Navy]212[/color][color=Blue]) [/color][color=Green]; move to start of first line[/color]
[color=Blue]pause [/color][color=Navy]2     [/color]
[color=Blue]serout [/color][color=Navy]0[/color][color=Black],[/color][color=Blue]n9600_8[/color][color=Black],[/color][color=Blue]([/color][color=Red]"88888888888888888888"[/color][color=Blue]) [/color][color=Green]; output text
      [/color]
[color=Blue]pause [/color][color=Navy]1000[/color]
[color=Blue]serout [/color][color=Navy]0[/color][color=Black],[/color][color=Blue]n9600_8[/color][color=Black],[/color][color=Blue]([/color][color=Navy]254[/color][color=Black],[/color][color=Navy]1[/color][color=Blue])
pause [/color][color=Navy]2[/color]
[color=Blue]serout [/color][color=Navy]0[/color][color=Black],[/color][color=Blue]n9600_8[/color][color=Black],[/color][color=Blue]([/color][color=Navy]254[/color][color=Black],[/color][color=Navy]128[/color][color=Blue]) [/color][color=Green]; move to start of first line[/color]
[color=Blue]pause [/color][color=Navy]2     [/color]
[color=Blue]serout [/color][color=Navy]0[/color][color=Black],[/color][color=Blue]n9600_8[/color][color=Black],[/color][color=Blue]([/color][color=Red]"33333333333333333333"[/color][color=Blue]) [/color][color=Green]; output text[/color]
[color=Blue]pause [/color][color=Navy]2     [/color]
[color=Blue]serout [/color][color=Navy]0[/color][color=Black],[/color][color=Blue]n9600_8[/color][color=Black],[/color][color=Blue]([/color][color=Navy]254[/color][color=Black],[/color][color=Navy]192[/color][color=Blue]) [/color][color=Green]; move to start of first line[/color]
[color=Blue]pause [/color][color=Navy]2     [/color]
[color=Blue]serout [/color][color=Navy]0[/color][color=Black],[/color][color=Blue]n9600_8[/color][color=Black],[/color][color=Blue]([/color][color=Red]"33333333333333333333"[/color][color=Blue]) [/color][color=Green]; output text[/color]
[color=Blue]pause [/color][color=Navy]2     [/color]
[color=Blue]serout [/color][color=Navy]0[/color][color=Black],[/color][color=Blue]n9600_8[/color][color=Black],[/color][color=Blue]([/color][color=Navy]254[/color][color=Black],[/color][color=Navy]148[/color][color=Blue]) [/color][color=Green]; move to start of first line[/color]
[color=Blue]pause [/color][color=Navy]2     [/color]
[color=Blue]serout [/color][color=Navy]0[/color][color=Black],[/color][color=Blue]n9600_8[/color][color=Black],[/color][color=Blue]([/color][color=Red]"33333333333333333333"[/color][color=Blue]) [/color][color=Green]; output text[/color]
[color=Blue]pause [/color][color=Navy]2     [/color]
[color=Blue]serout [/color][color=Navy]0[/color][color=Black],[/color][color=Blue]n9600_8[/color][color=Black],[/color][color=Blue]([/color][color=Navy]254[/color][color=Black],[/color][color=Navy]212[/color][color=Blue]) [/color][color=Green]; move to start of first line[/color]
[color=Blue]pause [/color][color=Navy]2     [/color]
[color=Blue]serout [/color][color=Navy]0[/color][color=Black],[/color][color=Blue]n9600_8[/color][color=Black],[/color][color=Blue]([/color][color=Red]"33333333333333333333"[/color][color=Blue]) [/color][color=Green]; output text
      [/color][color=Blue]pause [/color][color=Navy]1000[/color]
[color=Blue]loop[/color]
but its cutting off at 16 characters.
what needs to be changed?
 

marks

Senior Member
Hi ac21,
increase the number of @bptrinc to whats required.

Code:
	#picaxe 18m2    'version 2.A * 4 BIT SERIAL DRIVER 9600 baud * marks							
	#terminal off	
'            DB7  = C.3	
'            DB6  = C.2	
'            DB5  = C.1	
'            DB4  = C.0	           
      SYMBOL Rx   = C.5
	SYMBOL E    = B.6			                  
	SYMBOL RS   = B.7			                  
	SYMBOL senddata    = b0	 SYMBOL sentdata    = b0			
	SYMBOL index       = b1
	SYMBOL batV        = b2 
	SYMBOL ADCval      = b3
      SYMBOL D1          = b4 
	SYMBOL D2          = b5 
	
	EEPROM 0 ,($03,$03,$03,$02,$02,$08,$0,$0C,$0,$01)'(4Bit)(2line/5x8)(Display On)(Clear Display)	 16  8  4  2  1                                                
      EEPROM 10,(6 ,9 ,9 ,6 ,0 ,0 ,0 ,0) ' load custom character (o) =0                                 *  '  '  '  *  17
      EEPROM 18,(14,17,17,31,17,17,0 ,0) ' load custom character (A) =1                                 *  *  '  *  *  27
      EEPROM 26,(30,17,17,30,16,16,0 ,0) ' load custom character (P) =2                                 *  '  *  '  *  21
      EEPROM 34,(17,27,21,17,17,17,0 ,0) ' load custom character (M) =3                                 *  '  '  '  *  17
      EEPROM 42,(14,17,16,16,17,14,0 ,0) ' load custom character (C) =4                                 *  '  '  '  *  17
      EEPROM 50,(30,16,16,28,16,16,0 ,0) ' load custom character (F) =5                                 *  '  '  '  *  17
      EEPROM 58,(0 ,31,1 ,31,16,16,31,0) ' load custom character (2) =6                                 '  '  '  '  '  0
      EEPROM 66,(14,10,14,0 ,14,10,10,0) ' load custom character (on)=7                                 '  '  '  '  '  0
                                         '                                                           custom character example (M)=3
	CALIBADC10 ADCval
      SETFREQ M32
 	dirsB = %11101101			
 	dirsC = %00001111								
 	batV = 10475 / ADCval
      BinToAscii batV,D2,D2,D1 
      
Initialise: 	
	FOR  index = 0 to 9                                               
          READ index, senddata : pinsC = senddata : PULSOUT E,1 ' Initialise LCD						
 	NEXT index : PAUSE 10
 	
DisplaySupply:
	HIGH RS
      FOR  index = 0 TO 15
 	    LOOKUP index,("LCD Supply ",D2,".",D1,"V "),sentdata 
 	                           pinsC = senddata / 16 : PULSOUT E,1 : pinsC = senddata : PULSOUT E,1 ' sending characters to line one 
      NEXT index

LoadCustomCharactersFromEEPROM:
       LOW RS : senddata = $40 : pinsC = senddata / 16 : PULSOUT E,1 : pinsC = senddata : PULSOUT E,1 : HIGH RS ' Load Characters to LCD	
 	FOR  index =10 TO 73                 
 	    READ index, senddata : pinsC = senddata / 16 : PULSOUT E,1 : pinsC = senddata : PULSOUT E,1 ' sending characters to LCD      
 	NEXT index    
 
' TestCustomCharacters:
'       LOW RS  :senddata = 192 : pinsC = senddata / 16 : PULSOUT E,1 : pinsC = senddata : PULSOUT E,1  '(192-211) Line 2 Cursor Position
'      HIGH RS
'      FOR  index = 0 TO 12
' 	    LOOKUP index,("Test ",0,1,2,3,4,5,6,7),senddata 
' 	                            pinsC = senddata / 16 : PULSOUT E,1 : pinsC = senddata : PULSOUT E,1 ' sending characters to line two 
'      NEXT index
 
Main:
    bptr=28
   SERIN Rx,N9600_32,@bptr
   IF @bptrinc = 254 THEN Commands
   SERIN [10],Rx,N9600_32,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,_
                          @bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc ' send upto 20 characters
    @bptr = 254
     bptr = 28
       do until @bptr = 254
        pinsC = @bptr / 16 : PULSOUT E,1 : pinsC = @bptrinc : PULSOUT E,1
       loop
   GOTO Main
   
Commands:
   SERIN Rx,N9600_32,sentdata
   pinsC = sentdata / 16 
   'IF pinsc = $2 then Control  '  to control outputs if used 
   LOW RS
    PULSOUT E,1 : pinsC = sentdata : PULSOUT E,1
   HIGH RS 
    GOTO Main
To send n9600 reliably , your picaxe needs to run at 16 mhz or more
Code:
#picaxe 08m2  'syntax only
'#picaxe 18m2 'ran ok 
#no_data
setfreq m16
init:
pause 1000 ; wait for display to initialise
main:
do
serout 0,n9600_16,(254,1)
pause 2

serout 0,n9600_16,(254,128) ; move to start of  line1
pause 2
     
serout 0,n9600_16,("1234567890") ; output text
pause 30
     
serout 0,n9600_16,(254,192) ; move to start of  line2
pause 2
     
serout 0,n9600_16,("28888888888888888882") ; output text
pause 45
     
serout 0,n9600_16,(254,148) ; move to start of  line3
pause 2
     
serout 0,n9600_16,("38888888888888888883") ; output text
pause 45  
   
serout 0,n9600_16,(254,212) ; move to start of  line4
pause 2
    
serout 0,n9600_16,("48888888888888888884") ; output text    
pause 2000

serout 0,n9600_16,(254,1)
pause 2

serout 0,n9600_16,(254,128) ; move to start of  line1
pause 2 
    
serout 0,n9600_16,("13333333333333333331") ; output text
pause 45
     
serout 0,n9600_16,(254,192) ; move to start of  line2
pause 2 
    
serout 0,n9600_16,("23333333333333333332") ; output text
pause 45
     
serout 0,n9600_16,(254,148) ; move to start of  line3
pause 2
     
serout 0,n9600_16,("30333333333333333303") ; output text
pause 45
     
serout 0,n9600_16,(254,212) ; move to start of  line4
pause 2
     
serout 0,n9600_16,("43333333333333333334") ; output text
      pause 2000
loop
 
Last edited:

marks

Senior Member
Hi ac21,
Unfortunately I dont have an 08m2 to try.
there can be a slight difference of execution speed using different picaxe chips
I am guessing an 08m2 may be faster?
When having problems always try adjusting pauses between code.
added example to post#38 for you to try hopefully you'll have success...
 
Top