axe033 oled bas help needed

I am trying to configure the axe033.bas for my 20x4 oled where the welcome message at the start uses the first 4 message locations but i cannot get it to display them it just shows the message in 0 location on all four lines where am i going wrong the code with my changes is as follows;-
Code:
; AXE133 Serial LCD/OLED using PICAXE-18M2
; Emulates basic serial operation of the popular AXE033 module
; CPS, May 2011
; v2 18/01/2012

#picaxe 18M2

; ********************************************
; Note you must uncomment just one of these two options
; depending on whether you have an LCD or OLED module
#define use_OLED
;#define use_LCD
; ********************************************


; Supported Commands
; 0-7, 8-15	CGRAM characters
; 16-252	normal ASCII characters, according to selected character map table
; 253, X	display 16 character pre-saved message from EEPROM memory, X can be 0-15
; 254, X	LCD command, X can be 0 to 255 
; 255, X	control outputs C.2, C.1, C.0 (via lower 3 bits of X)
;		So, if using a backlit LCD with the active low transistor driver
;		on output C.2, then 255,%000 switches backlight on and 255,%100 switches off


#define use_welcome	; display the welcome message upon power up
symbol line_length = 20	; change to 20 for displays with 20 character lines

symbol baud = N2400_16	; Serial baud rate 2400,N,8,1. Note main program runs at 16MHz

symbol spare0 	= C.0 ; spare output 0
symbol spare1 	= C.1 ; spare output 1
symbol spare2 	= C.2 ; spare output 2 (or optional backlight)
symbol backlight 	= C.2 ; optional backlight control for backlit LCDs, active low
symbol RX		= C.5	; serial receive pin
symbol enable 	= C.6	; LCD enable
symbol rs 		= C.7	; LCD RS 


; LCD data pins are on B.0 to B.7

; Store the 20 character user defined messages in EEPROM data memory
; First two messages are optionally used as welcome message

; If using a display with 20 characters you will need to edit 
; the start addresses to be multiples of 20 (currently at 16) 
; and add 4 characters to each message.
; Please remember 4 line displays always use the strange 1-3-2-4 layout.

#ifdef use_OLED		
EEPROM $00, ("   Studio Odyssey   ") 	; store msg in the EEPROM memory
#else
EEPROM $00, ("     Serial LCD     ") 	; store msg in the EEPROM memory
#endif


EEPROM $14, ("This is msg 0       ") 	; store msg in the EEPROM memory

EEPROM $28, ("This is msg 1       ") 	; store msg in the EEPROM memory
EEPROM $3C, ("This is msg 2       ") 	; store msg in the EEPROM memory
EEPROM $50, ("This is msg 3       ") 	; store msg in the EEPROM memory
EEPROM $64, ("This is msg 4       ") 	; store msg in the EEPROM memory
EEPROM $78, ("This is msg 5       ") 	; store msg in the EEPROM memory
EEPROM $8C, ("This is msg 6       ") 	; store msg in the EEPROM memory
EEPROM $A0, ("This is msg 7       ") 	; store msg in the EEPROM memory
EEPROM $B4, ("This is msg 8       ") 	; store msg in the EEPROM memory
EEPROM $C8, ("This is msg 9       ") 	; store msg in the EEPROM memory
EEPROM $DC, ("This is msg 10      ") 	; store msg in the EEPROM memory

;initialise LCD
init:
	gosub LCD_init 		; initialise LCD

; display welcome message if desired
#ifdef use_welcome	
	let b1 = 0			; message 0 on top line
	gosub msg			; do it

	low rs			; command mode
	let pinsB = 192		; move to line 2, instruction 192
	pulsout enable,3  	; pulse the enable pin to send data.
	high rs			; character mode again
	
	let b1 = 1			; message 1 on line 2
	gosub msg			; do it
; added lines 3 and 4 to welcome message
;	low rs			; command mode
;	let pinsB = 148		; move to line 3, instruction 148
;	pulsout enable,3  	; pulse the enable pin to send data.
;	high rs			; character mode again
;	
;	let b1 = 2			; message 1 on line 3
;	gosub msg
;	
;	low rs			; command mode
;	let pinsB = 212		; move to line 4, instruction 212
;	pulsout enable,3  	; pulse the enable pin to send data.
;	high rs			; character mode again
;	
;	let b1 = 3			; message 1 on line 4
;	gosub msg
#endif		
		
; main program loop, runs at 16MHz

main:

	serin RX,baud,b1			; wait for the next byte

	; NB keep character mode test as first item in this list to optimise speed
	if b1 < 253 then
		let pinsB = b1 		; output the data
		pulsout enable,1  	; pulse the enable pin to send data.
		goto main			; quickly loop back to top
	else if b1 = 254 then
		low rs 	     		; change to command mode for next character
		serin RX,baud,b1		; wait for the command byte
		let pinsB = b1 		; output the data
		pulsout enable,1  	; pulse the enable pin to send data.
		high rs			; back to character mode
		goto main			; quickly loop back to top
	else if b1 = 253 then
		serin RX,baud,b1		; wait for the next byte
		gosub msg			; do the 16 character message
		goto main			; back to top
	else ; must be 255
		serin RX,baud,b1		; wait for the next byte
		let pinsC = b1 & %00000111 | %10000000
						; output the data on C.0 to C.1, keep RS high
		goto main			; back to top
	end if


; power on LCD initialisation sub routine
LCD_init:
	let dirsC = %11000111	; PortC 0,1,2,6,7 all outputs
	let dirsB = %11111111	; PortB all outputs
	

	
#ifdef use_OLED
	; Winstar OLED Module Initialisation
	; according to WS0010 datasheet (8 bit mode)

	pause 500 			; Power stabilistation = 500ms

	; Function set - select only one of these 4 character table modes
	;let pinsB = %00111000 	; 8 bit, 2 line, 5x8 , English_Japanese table
	let pinsB = %00111001 	; 8 bit, 2 line, 5x8 , Western_European table1
	;let pinsB = %00111010 	; 8 bit, 2 line, 5x8 , English_Russian  table
	;let pinsB = %00111011 	; 8 bit, 2 line, 5x8 , Western_European table2
	
	pulsout enable,1  	; 
		
	let pinsB = %00001100	; Display on, no cursor, no blink
	pulsout enable,1 	

	let pinsB = %00000001 	; Display Clear
	pulsout enable,1
	pause 7			; Allow 6.2ms to clear display

	setfreq m16			; now change to 16Mhz

	let pinsB = %00000010 	; Return Home
	pulsout enable,1

	let pinsB = %00000110 	; Entry Mode, ID=1, SH=0
	pulsout enable, 1


#else	
	; Standard LCD Module Initialisation
	pause 15 			; Wait 15ms for LCD to reset.

	let pinsB = %00110000 	; 8 bit, 2 line
	pulsout enable,1  	; Send data by pulsing enable
	pause 5 			; Wait 5 ms
	pulsout enable,1 	 	; Send data 48 again
	pulsout enable,1  	; Send data 48 again
	
	setfreq m16			; now change to 16Mhz

	let pinsB = %00111000 	; LCD  - 8 bit, 2 line, 5x8  
	pulsout enable,1
			
	let pinsB = %00000001	; Clear Display
	pulsout enable,1 	
	pause 8			; 8 = 2ms at 16MHz
	
	let pinsB = %00000010 	; return home
	pulsout enable,1

	let pinsB = %00000110	; Entry mode
	pulsout enable,1 	
	pause 1			

	let pinsB = %00001100	; Display on, no cursor, no blink
	pulsout enable,1 	
#endif
	
	high rs			; Leave in character mode
	return


; display message from EEPROM sub routine
; message number 0-15 must be in b1 when called
; uses (alters) b1, b2, b3, b4
msg:
	let b2 = b1 & %0010100 * line_length
						; EEPROM start address is 0 to 15 multiplied by 16
	let b3 = b2 + line_length - 1 ; end address is start address + (line_length - 1)
	for b4 = b2 to b3			; for 16 times
		read b4,b1			; read next character from EEPROM data memory into b1
		let pinsB = b1 		; output the data
		pulsout enable,1  	; pulse the enable pin to send data.
	next b4				; next loop
	return
	
; Check end user has defined just one type of display
#ifndef use_OLED
#ifndef use_LCD
#error "Oops - no OLED / LCD type defined at top of program!"
#endif
#endif

#ifdef use_OLED
#ifdef use_LCD
#error "Oops - both OLED / LCD types defined at top of program!"
#endif
#endif
 

nick12ab

Senior Member
What you've said:
  • You want the welcome message to use four message locations.
  • It shows the message on all four lines
What is the problem?
 
sorry if i did not make my problem clear, with the code i have attached i cannot get it to show the first four stored messages to show on the display at start i.e. message 0 on line 1, message 1 on line 2, message 2 on line 3 and message 3 on line 4. What i get is message 0 on all four lines of the oled, as i am actually going to the four lines then that must be correct but why does it only take message 0 ?
 

neiltechspec

Senior Member
Why not use AXE134 OLED code to start with ?. I do.

Code:
; AXE134 Serial 20x4 OLED using PICAXE-18M2
; Emulates basic serial operation of the popular AXE033 module
; CPS, May 2011
; JB,  Jan 2012

#picaxe 18M2


; Supported Commands
; 0-7, 8-15	CGRAM characters
; 16-252	normal ASCII characters, according to selected character map table
; 253, X	display 12 character pre-saved message from EEPROM memory, X can be 0-11
; 254, X	OLED command, X can be 0 to 255 
; 255, X	control outputs C.2, C.1, C.0 (via lower 3 bits of X)

#define use_welcome	; display the welcome message upon power up

symbol baud = N2400_16	; Serial baud rate 2400,N,8,1. Note main program runs at 16MHz

symbol spare0 	= C.0 ; spare output 0
symbol spare1 	= C.1 ; spare output 1
symbol spare2 	= C.2 ; spare output 2
symbol RX		= C.5	; serial receive pin
symbol enable 	= C.6	; OLED enable
symbol rs 		= C.7	; OLED RS 

; OLED data pins are on B.0 to B.7

; Store the 20 character user defined messages in EEPROM data memory
; First two messages are optionally used as welcome message

; Please remember 4 line displays always use the strange 1-3-2-4 line layout.

EEPROM  00, ("Serial OLED Display ") 	; store msg 0 in the EEPROM memory
EEPROM  20, (" 20 by 4 Character  ") 	; store msg 1 in the EEPROM memory
EEPROM  40, ("  2400 Baud  8,N,1  ") 	; store msg 2 in the EEPROM memory
EEPROM  60, ("This is Message No 3") 	; store msg 3 in the EEPROM memory
EEPROM  80, ("This is Message No 4") 	; store msg 4 in the EEPROM memory
EEPROM 100, ("This is Message No 5") 	; store msg 5 in the EEPROM memory
EEPROM 120, ("This is Message No 6") 	; store msg 6 in the EEPROM memory
EEPROM 140, ("This is Message No 7") 	; store msg 7 in the EEPROM memory
EEPROM 160, ("This is Message No 8") 	; store msg 8 in the EEPROM memory
EEPROM 180, ("This is Message No 9") 	; store msg 9 in the EEPROM memory
EEPROM 200, ("This is Message No10") 	; store msg 10 in the EEPROM memory
EEPROM 220, ("This is Message No11") 	; store msg 11 in the EEPROM memory

;initialise OLED
init:
	gosub OLED_init 		; initialise OLED

; display welcome message if desired
#ifdef use_welcome	
	let b1 = 0			; message 0
	gosub msg			; do it
	pause 100

	low rs			; command mode
	let pinsB = 192		; move to line 2, instruction 192
	pulsout enable,1  	; pulse the enable pin to send data.
	high rs			; character mode again
	let b1 = 1 			; message 1
	gosub msg			; do it
	pause 100

	low rs			; command mode
	let pinsB = 148		; move to line 3, instruction 148
	pulsout enable,1  	; pulse the enable pin to send data.
	high rs			; character mode again
	let b1 = 2  		; message 2
	gosub msg			; do it
	pause 1000
	
	low rs
	let pinsB = %00000001 	; Display Clear
	pulsout enable,1
	pause 100
	let pinsB = %00000010 	; Return Home
	pulsout enable,1
	pause 200
	high rs
	
#endif		
		
; main program loop, runs at 16MHz

main:

	serin RX,baud,b1			; wait for the next byte

	; NB keep character mode test as first item in this list to optimise speed
	if b1 < 253 then
		let pinsB = b1 		; output the data
		pulsout enable,1  	; pulse the enable pin to send data.
		goto main			; quickly loop back to top
	else if b1 = 254 then
		low rs 	     		; change to command mode for next character
		serin RX,baud,b1		; wait for the command byte
		let pinsB = b1 		; output the data
		pulsout enable,1  	; pulse the enable pin to send data.
		high rs			; back to character mode
		goto main			; quickly loop back to top
	else if b1 = 253 then
		serin RX,baud,b1		; wait for the next byte
		gosub msg			; do the 16 character message
		goto main			; back to top
	else ; must be 255
		serin RX,baud,b1		; wait for the next byte
		let pinsC = b1 & %00000111 | %10000000
						; output the data on C.0 to C.1, keep RS high
		goto main			; back to top
	end if


; power on OLED initialisation sub routine
OLED_init:
	let dirsC = %11000111	; PortC 0,1,2,6,7 all outputs
	let dirsB = %11111111	; PortB all outputs

	; Winstar OLED Module Initialisation
	; according to WS0010 datasheet (8 bit mode)

	pause 500 			; Power stabilistation = 500ms

	; Function set - select only one of these 4 character table modes
	;let pinsB = %00111000 	; 8 bit, 2 line, 5x8 , English_Japanese table
	let pinsB = %00111001 	; 8 bit, 2 line, 5x8 , Western_European table1
	;let pinsB = %00111010 	; 8 bit, 2 line, 5x8 , English_Russian  table
	;let pinsB = %00111011 	; 8 bit, 2 line, 5x8 , Western_European table2
	
	pulsout enable,1  	; 
		
	let pinsB = %00001100	; Display on, no cursor, no blink
	pulsout enable,1 	

	let pinsB = %00000001 	; Display Clear
	pulsout enable,1
	pause 7			; Allow 6.2ms to clear display

	setfreq m16			; now change to 16Mhz

	let pinsB = %00000010 	; Return Home
	pulsout enable,1

	let pinsB = %00000110 	; Entry Mode, ID=1, SH=0
	pulsout enable, 1

	high rs			; Leave in character mode
	return


; display message from EEPROM sub routine
; message number 0-11 must be in b1 when called
; uses (alters) b1, b2, b3, b4
msg:
	let b2 = b1 // 12 * 20		; EEPROM start address is 0 to 11 multiplied by 20
	let b3 = b2 + 20 - 1 		; end address is start address + (20 - 1)
	for b4 = b2 to b3			; for 20 times
		read b4,b1			; read next character from EEPROM data memory into b1
		let pinsB = b1 		; output the data
		pulsout enable,1  	; pulse the enable pin to send data.
	next b4				; next loop
	return
Note: clears the display after a brief period.

Neil.
 

nick12ab

Senior Member
sorry if i did not make my problem clear, with the code i have attached i cannot get it to show the first four stored messages to show on the display at start i.e. message 0 on line 1, message 1 on line 2, message 2 on line 3 and message 3 on line 4. What i get is message 0 on all four lines of the oled, as i am actually going to the four lines then that must be correct but why does it only take message 0 ?
That's probably because of this line:
Code:
let b2 = b1 & %0010100 * line_length
Where does it come from? It won't work properly because of the bit mask (%0010100) which results in the message selected being 0 regardless of whether you set it to 0, 1, 2 or 3. The code just posted by neiltechspec has a completely different line there.
Code:
let b2 = b1 // 12 * 20
 
That line of code is in the original code and i made no change to it as line_length was change to 20 so i assumed its all it would need. I have just tried the 134 code and this works perfect so i will use this and attempt to find out why my changes have a problem so that i can understand the code a bit better. The line of code works ok in original file with 16x2 oled
 
hi, my first post with code is the axe133 code not the axe134 which i am now using thanks to neiltechspec, i just assumed this would be ok with the 20x4 as in the comments it does tell you to modify for a 20 character display but maybe it is only for 2 line
 
I have hit another problem with the eeprom stored messages, i have now placed the 10 messages into the file and if i change the code to load messages 3/4/5/6 at the welcome everything works ok and the messages are displayed on the oled. However if i try to call the same messages from within a program they do not appear correctly meaning line 1 is ok line 2 is missing line 3 is ok and line 4 is missing what am i doing wrong as i think i have followed the instructions on the datasheet.
apologies for no code tags but sometimes i cannot find them on the reply to thread !!

loadmenu:
serout c.4, n2400, (254,1) ;clear screen
pause 30
serout c.4, n2400, (254,128) ; move to line 1
serout c.4, n2400, (253,3) ;message 3 from eeprom
serout c.4, n2400, (254,192) ; move to line 2
serout c.4, n2400, (253,4) ;message 4 from eeprom
serout c.4, n2400, (254,148) ; move to line 3
serout c.4, n2400, (253,5) ;message 5 from eeprom
serout c.4, n2400, (254,212) ;move to line 4
serout c.4, n2400, (253,6) ;message 6 from eeprom
goto main
 

Technical

Technical Support
Staff member
Put some pause commands after the eeprom message serouts, you need to give them time to process.
 

neiltechspec

Senior Member
I don't think you read the required part of the AXE134 datasheet on page 3, the bit that gives the following example.

serout B.7,N2400,(254,128) ; move to start of first line
serout B.7,N2400,(253,1) ; display predefined message 1
pause 10 ; allow message to update

Note: the pause after the command to display a predefined message.

Neil.
 
Yeah missed it in my haste to try it out, everything loads ok now with a pause 20 was intermittent with pause 10. I know that 254.1 clears the whole screen is there a way to just clear certain parts on lines so when you have some fixed text and adding changing text at certain points as i seem to be getting the wrong results when changing from two numbers (10) to one number (1)
 
I found a fix for the post above by checking the value first to see if it is less than 10 and if so adding a space to the number thus deleting the last value if it was 10 or more, but there is maybe a simpler way of doing this ?
 

nick12ab

Senior Member
I found a fix for the post above by checking the value first to see if it is less than 10 and if so adding a space to the number thus deleting the last value if it was 10 or more, but there is maybe a simpler way of doing this ?
Use the bintoascii command. If you don't want the leading zeros then use if statements to replace them with spaces and remember you don't have to send all the output bytes from that command to the LCD anyway.

Something was posted earlier - Formatting numbers - which may also work however it is overly convoluted and it's overkill for what you want to do.
 

neiltechspec

Senior Member
The suggestion from nick12ab -

Using 'bin2ascii' and using 'if' statements to put spaces where needed with only the required bytes, is exactly what i do for similar displays.

Neil.
 
Top