Did I miss understand bptr

oracacle

Senior Member
While working on my timer project I found my self looking towards the bptr command. when I read the manual I thought that is was another way to access the variable, I found myself very confused @ 4am. the project will need to display it output ontp a parallel connected OLED. I could have gone serial but I had most of a 20x2 left spare. after trimming back the code for the firm ware and starting to add the timer code for a display test I found that I kept getting garbage displayed on the OLED, confused I started playing around with things and found that the pbtr does not correlate to the variable (pbtr 20 is not b20).

Code:
[color=Black]main:
      [/color][color=Blue]let [/color][color=Purple]w2 [/color][color=DarkCyan]= [/color][color=Navy]12345
      
      [/color][color=Blue]bintoascii [/color][color=Purple]w2[/color][color=Black], [/color][color=Purple]n5[/color][color=Black],[/color][color=Purple]n4[/color][color=Black],[/color][color=Purple]n3[/color][color=Black],[/color][color=Purple]n2[/color][color=Black],[/color][color=Purple]n1
      [/color][color=Blue]gosub [/color][color=Black]msg
      
      [/color][color=Blue]end[/color]
[color=Black]msg:
      [/color][color=Green];let b29 = b28 & %00001111 * line_length
                                    ; EEPROM start address is 0 to 15 multiplied by 16
      ;let b30 = b29 + line_length - 1 ; end address is start address + (line_length - 1)
      
            ;let n5 = "1"
      [/color][color=Purple]bptr [/color][color=DarkCyan]= [/color][color=Navy]20
      [/color][color=Blue]poke [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]n5
      [/color][color=Green];let n4 = "2"
      [/color][color=Blue]poke [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]n4
      [/color][color=Green];let n3 = "3"
      [/color][color=Blue]poke [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]n3
      [/color][color=Green];let n2 = "4"
      [/color][color=Blue]poke [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]n2
      [/color][color=Green];let n1 = "5"
      [/color][color=Blue]poke [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]n1
      b30 [/color][color=DarkCyan]= [/color][color=Navy]4
      
      [/color][color=Purple]bptr [/color][color=DarkCyan]= [/color][color=Navy]20
      [/color][color=Blue]for [/color][color=Purple]b31 [/color][color=DarkCyan]= [/color][color=Purple]b29 [/color][color=Blue]to [/color][color=Purple]b30
            [/color][color=Blue]peek [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]b28
            [/color][color=Green];let b28 = b0
            ;read b31,b28           ; read next character from EEPROM data memory into b1
            [/color][color=Blue]let [/color][color=Purple]pinsB [/color][color=DarkCyan]= [/color][color=Purple]b28         [/color][color=Green]; output the data
                  [/color][color=Blue]debug
            pulsout enable[/color][color=Black],[/color][color=Navy]1        [/color][color=Green]; pulse the enable pin to send data.
      [/color][color=Blue]next [/color][color=Purple]b31                      [/color][color=Green]; next loop
      [/color][color=Purple]b29 [/color][color=DarkCyan]= [/color][color=Navy]0
      [/color][color=Blue]return[/color]
this is still a bit of a mess but was actually the only way I could get the ascii stored on the variable to the pbtr.
I cant help either feeling a bit dumb or that I have missed something that is staring me right in the face.
 

BESQUEUT

Senior Member
Rosetta Stone

Have I missed something that is staring me right in the face ?
Maybe this will help (3 ways to write the same thing, as Rosetta_Stone ) :
Code:
main:
      w2 = 56789
      
      bptr = 20
      bintoascii w2, @bptrinc, @bptrinc, @bptrinc, @bptrinc, @bptrinc
      gosub msg
      
      end
msg:
       bptr = 20
	 sertxd("With bptr :",13,10)
	 for b3 = 1 to 5
		sertxd(#b3,"=>",@bptrinc,13,10)
       next b3                    ; next loop (stupid comment)
 
	 sertxd(13,10,"With peek :",13,10)
	 for b3 = 20 to 24
		peek b3,b4
		sertxd(#b3,"->",b4,13,10)
       next b3

 
	 sertxd(13,10,"With variables :",13,10)
	 sertxd("b20=",b20,13,10)
	 sertxd("b21=",b21,13,10)
	 sertxd("b22=",b22,13,10)
	 sertxd("b23=",b23,13,10)
	 sertxd("b24=",b24,13,10)

      return
 
Last edited:

hippy

Technical Support
Staff member
The problem is in "poke @bptrinc"; The @ does the same as peek/poke. What you probably want is ...

bptr = 20
@bptrinc = 1
@bptrinc = 2
@bptrinc = 3

That will put 1,2,3 in variables b20,b21,b22
 

techElder

Well-known member
Yeah, and PICAXE just conveniently chose to call the variable names for RAM locations ( for example 0 ---> 55 ) "b0, b1, b2 ---> b55".

"b0" is where bptr = 0, "b1" is where bptr = 1, "b2" is where bptr = 2, ---> "b55" is where bptr = 55

These are the locations in RAM where some value is.

That value can be set by using @bptr =; for instance bptr = 20 : @bptr = 1 is equivalent to b20 = 1.

The advantage to using an indirect reference to the RAM location is that with @bptrinc and @bptrdec one can programmatically move through many RAM locations and make changes or read the values.

You can't do that easily by referring to "b0, b1, b2, ---> b55" variable names.
 

BESQUEUT

Senior Member
The advantage to using an indirect reference to the RAM location is that with @bptrinc and @bptrdec one can programmatically move through many RAM locations and make changes or read the values.
Another advantage is that there are up to 256 general purpose variables.
With X2 parts, you also can uses 1024 bytes of scratchpad memory.
 

oracacle

Senior Member
thanks guys, I have the code working as I expected it too now, and its an important to note that trying these things when tired can hide the obvious mistakes

I have the code working as I expected it too now so I can press on with the rest of the project.

here's what I ended up with in my test code.
Code:
[color=Black]LCD_init:
      [/color][color=Blue]let [/color][color=Purple]dirsC [/color][color=DarkCyan]= [/color][color=Navy]%00110111         [/color][color=Green]; PortC 0,1,2,6,7 all outputs
      [/color][color=Blue]let [/color][color=Purple]dirsB [/color][color=DarkCyan]= [/color][color=Navy]%11111111         [/color][color=Green]; PortB all outputs
      
      [/color][color=Blue]pause [/color][color=Navy]500                     [/color][color=Green]; Power stabilistation = 500ms
      [/color][color=Blue]let [/color][color=Purple]pinsB [/color][color=DarkCyan]= [/color][color=Navy]%00111001         [/color][color=Green]; 8 bit, 2 line, 5x8 , Western_European table1
      
      [/color][color=Blue]pulsout enable[/color][color=Black],[/color][color=Navy]1 
            
      [/color][color=Blue]let [/color][color=Purple]pinsB [/color][color=DarkCyan]= [/color][color=Navy]%00001100         [/color][color=Green]; Display on, no cursor, no blink
      [/color][color=Blue]pulsout enable[/color][color=Black],[/color][color=Navy]1  

      [/color][color=Blue]let [/color][color=Purple]pinsB [/color][color=DarkCyan]= [/color][color=Navy]%00000001         [/color][color=Green]; Display Clear
      [/color][color=Blue]pulsout enable[/color][color=Black],[/color][color=Navy]1
      [/color][color=Blue]pause [/color][color=Navy]7                       [/color][color=Green]; Allow 6.2ms to clear display

      [/color][color=Blue]setfreq m16                   [/color][color=Green]; now change to 16Mhz

      [/color][color=Blue]let [/color][color=Purple]pinsB [/color][color=DarkCyan]= [/color][color=Navy]%00000010         [/color][color=Green]; Return Home
      [/color][color=Blue]pulsout enable[/color][color=Black],[/color][color=Navy]1

      [/color][color=Blue]let [/color][color=Purple]pinsB [/color][color=DarkCyan]= [/color][color=Navy]%00000110         [/color][color=Green]; Entry Mode, ID=1, SH=0
      [/color][color=Blue]pulsout enable[/color][color=Black], [/color][color=Navy]1
      
      [/color][color=Blue]high rs                 [/color][color=Green]; Leave in character mode
      
;must rest frequency to 16mhz from 64 before printing on display - maybe
      
      [/color]
[color=Black]main:
      [/color][color=Blue]let [/color][color=Purple]w2 [/color][color=DarkCyan]= [/color][color=Navy]12345
      
      [/color][color=Blue]bintoascii [/color][color=Purple]w2[/color][color=Black], [/color][color=Purple]n5[/color][color=Black],[/color][color=Purple]n4[/color][color=Black],[/color][color=Purple]n3[/color][color=Black],[/color][color=Purple]n2[/color][color=Black],[/color][color=Purple]n1
      [/color][color=Blue]gosub [/color][color=Black]msg
      
      [/color][color=Blue]end[/color]
[color=Black]msg:
      [/color][color=Purple]b30 [/color][color=DarkCyan]= [/color][color=Navy]4
      [/color][color=Purple]bptr [/color][color=DarkCyan]= [/color][color=Navy]20
      [/color][color=Blue]for [/color][color=Purple]b31 [/color][color=DarkCyan]= [/color][color=Purple]b29 [/color][color=Blue]to [/color][color=Purple]b30
            b28 [/color][color=DarkCyan]= [/color][color=Purple]@bptrinc
            [/color][color=Green];let b28 = b0
            ;read b31,b28           ; read next character from EEPROM data memory into b1
            [/color][color=Blue]let [/color][color=Purple]pinsB [/color][color=DarkCyan]= [/color][color=Purple]b28         [/color][color=Green]; output the data
            [/color][color=Blue]pulsout enable[/color][color=Black],[/color][color=Navy]1        [/color][color=Green]; pulse the enable pin to send data.
      [/color][color=Blue]next [/color][color=Purple]b31                      [/color][color=Green]; next loop
      [/color][color=Purple]b29 [/color][color=DarkCyan]= [/color][color=Navy]0
      [/color][color=Blue]return[/color]
 

lbenson

Senior Member
You may sometime find yourself running short of named variables, e.g., b31. If so, you could save the four used in your msg subroutine (b28, b29, b30, b31) by substituting the following:
Code:
msg:
  for bptr = 20 to 24
    let pinsB = @bptr
    pulsout enable,1        ; pulse the enable pin to send data.
  next bptr
  return
It might be useful for subsequent searchers if you changed "pbtr" in the post title to "bptr".
 
Last edited:

oracacle

Senior Member
thanks ibenson, I may actually use that in the final project. I am not short of variables but it saves a line of code and will look a bit neater.
Just glad I got my head around it now
 

oracacle

Senior Member
yes I did, I still need to examine it in detail.
the reason the next piece of test code was the way it was it due to the fact that I was heartily confused and had to get the information sorted in my head.
The project has come one quite a bit now, so its time to collate all the information and apply it.

however, bptr 20 being b20, I am still using the b20 variable and this not actually saving that variable (and its increments). bare in mind this project is going to be stand alone and not attached to a computer, any sertxd that I have in code is for debugging.
also some of the code is done in preparation for what the final output will be - what is test code for. I will not always read the entire set of n1-n5 back to the display as per hippys' timer which this project is based around

here is the display section of the current test code:
Code:
[color=Black]DisplayTime:[/color]
[color=Green]'Time still displayed in sertxd so that output on display can be checked
'current testing using serial OLED
      [/color][color=Blue]bintoascii [/color][color=Black]s, n5, n4, n3, n2, n1
      [/color][color=Blue]let [/color][color=Purple]b32 [/color][color=DarkCyan]= [/color][color=Navy]20
      [/color][color=Blue]let [/color][color=Purple]b30 [/color][color=DarkCyan]= [/color][color=Navy]4
      [/color][color=Blue]gosub [/color][color=Black]msg0
      [/color][color=Blue]gosub [/color][color=Black]msg
      [/color][color=Blue]bintoascii [/color][color=Black]ms, n5, n4, n3, n2, n1
      [/color][color=Blue]let [/color][color=Purple]b32 [/color][color=DarkCyan]= [/color][color=Navy]22
      [/color][color=Blue]let [/color][color=Purple]b30 [/color][color=DarkCyan]= [/color][color=Navy]2
      [/color][color=Blue]gosub [/color][color=Black]msg0
      [/color][color=Blue]bintoascii [/color][color=Black]us, n5, n4, n3, n2, n1
      [/color][color=Blue]gosub [/color][color=Black]msg0
      [/color][color=Blue]bintoascii [/color][color=Black]ns, n5, n4, n3, n2, n1
      [/color][color=Blue]gosub [/color][color=Black]msg0
      [/color][color=Blue]do
            if [/color][color=Purple]pinc.6 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=DarkCyan]and [/color][color=Purple]pinc.7 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]then exit
      let [/color][color=Purple]b40 [/color][color=DarkCyan]= [/color][color=Purple]pinsc
                  
      [/color][color=Blue]loop
      debug
      high c.4
      pause [/color][color=Navy]1000
      [/color][color=Blue]low c.4
      return[/color]
[color=Black]msg0:
      [/color][color=Purple]bptr [/color][color=DarkCyan]= [/color][color=Purple]b32

      [/color][color=Blue]for [/color][color=Purple]b31 [/color][color=DarkCyan]= [/color][color=Purple]b29 [/color][color=Blue]to [/color][color=Purple]b30
            b28 [/color][color=DarkCyan]= [/color][color=Purple]@bptrinc
            [/color][color=Blue]let [/color][color=Purple]pinsb [/color][color=DarkCyan]= [/color][color=Purple]b28
            [/color][color=Blue]pulsout [/color][color=Black]enable,[/color][color=Navy]1
      [/color][color=Blue]next [/color][color=Purple]b31
      [/color][color=Blue]let [/color][color=Purple]b29 [/color][color=DarkCyan]= [/color][color=Navy]0
      [/color][color=Blue]return[/color]
[color=Black]msg:
      [/color][color=Blue]let [/color][color=Purple]pinsB [/color][color=DarkCyan]= [/color][color=Red]"."         [/color][color=Green]; output the data
      [/color][color=Blue]pulsout [/color][color=Black]enable,[/color][color=Navy]1        [/color][color=Green]; pulse the enable pin to send data.
      [/color][color=Blue]return[/color]
 

BESQUEUT

Senior Member
As b30 never change, you can replace it with a symbol.

Or you can replace :
for b31 = b29 to b30
by
for b31 = 1 to b30
And initialize b30 to the number of bytes to be read.
In that case
bptr=24-b30
and you can forgot b32.

b28 = @bptrinc
let pinsb = b28

Why not writing directly ?
pinsb =@bptrinc
 
Last edited:

oracacle

Senior Member
been playing around here and found the if is use
Code:
      bintoascii w2, @bptrinc, @bptrinc, @bptrinc, @bptrinc, @bptrinc
I get a string of zeros by comparison to using the variables

some of your suggested changes have already been made besqueut

this works as I had hoped so far.
Code:
DisplayTime:
'Time still displayed in sertxd so that output on display can be checked
'current testing using serial OLED
	bintoascii s, n5,n4,n3,n2,n1
	let pointer = 21
	let l_num = 4
	gosub msg0
	gosub msg
	bintoascii ms, n5,n4,n3,n2,n1
	let pointer = 23
	let l_num = 2
	gosub msg0
	bintoascii us, n5,n4,n3,n2,n1
	let pointer = 23
	let l_num = 2
	gosub msg0
	bintoascii ns, n5,n4,n3,n2,n1
	let pointer = 23
	let l_num = 2
	gosub msg0
	do
		if pinc.6 = 0 and pinc.7 = 0 then exit	;check for input removed
	loop
	high c.4:pause 1000:low c.4 				;reset SR latches
	
	'now return to begining of line 1
	low rs
	let pinsb = 128
	pulsout enable,1
	high rs
	return
msg0:
	bptr = pointer

	for loopy = 0 to l_num
		let pinsb = @bptrinc
		pulsout enable,1
	next loopy
	return
msg:
	let pinsB = "."    	; output the data
	pulsout enable,1  	; pulse the enable pin to send data.
	return
 

BESQUEUT

Senior Member
Partial code :
bintoascii w2, @bptrinc, @bptrinc, @bptrinc, @bptrinc, @bptrinc
Did you initialize bptr to something clever ?

This is of interest only if you want to place these variables beyond b55.
For example, you can have :
Symbol Start_Address=60

w2=ms : l_num=4 : gosub msg0
w2=us : l_num=2 : gosub msg0
w2=ns : l_num=2 : gosub msg0
...
Return

Msg0:
bptr =Start_Adress
bintoascii w2, @bptrinc, @bptrinc, @bptrinc, @bptrinc, @bptrinc
bptr = End_Adress - l_num ' Or Start_Address+4-l_num
for loopy = 1 to l_num
...
Return


Pointer variable is of no need :
Symbol End_Adress= 24 '( for example)
bptr = End_Adress - l_num


Why are you starting the loop from zero ?
This way l_num is "number of char" -1

I known : "Pourquoi faire simple quand on sait faire compliqué ? *" but ...

* why make it simple when we can make it complicated ?
 
Last edited:

oracacle

Senior Member
initialise bptr as 20 (which should now be 21 due to variable changes that have been made since) along to reflect to current variable use, maybe not clever just what it should have been.

as for zero, OCD kicked in and had to be zero for what ever reason. the end bptr address (in variable pointer) will always be 25.
 

oracacle

Senior Member
bit of bigger update, now displays the previous time on the second line of the display and the most recent reading on the first line.

Code:
[color=Black]DisplayTime:[/color]
[color=Green]'time displayed on OLED parralles display
'first update old time
      [/color][color=Black]s0 [/color][color=DarkCyan]= [/color][color=Black]s1
      ms0 [/color][color=DarkCyan]= [/color][color=Black]ms1
      us0 [/color][color=DarkCyan]= [/color][color=Black]us1
      ns0 [/color][color=DarkCyan]= [/color][color=Black]ns1
      [/color][color=Green]'go to begining of second line
      [/color][color=Blue]low [/color][color=Black]rs
      [/color][color=Blue]let [/color][color=Purple]pinsb [/color][color=DarkCyan]= [/color][color=Navy]192
      [/color][color=Blue]pulsout [/color][color=Black]enable,[/color][color=Navy]1
      [/color][color=Blue]high [/color][color=Black]rs
      [/color][color=Blue]gosub [/color][color=Black]bintoasci[/color]

[color=Green]'now update new time
      [/color][color=Black]s0 [/color][color=DarkCyan]= [/color][color=Black]s
      ms0 [/color][color=DarkCyan]= [/color][color=Black]ms
      us0 [/color][color=DarkCyan]= [/color][color=Black]us
      ns0 [/color][color=DarkCyan]= [/color][color=Black]ns
      [/color][color=Green]'now return to begining of line 1
      [/color][color=Blue]low [/color][color=Black]rs
      [/color][color=Blue]let [/color][color=Purple]pinsb [/color][color=DarkCyan]= [/color][color=Navy]128
      [/color][color=Blue]pulsout [/color][color=Black]enable,[/color][color=Navy]1
      [/color][color=Blue]high [/color][color=Black]rs
      [/color][color=Blue]gosub [/color][color=Black]bintoasci
      [/color][color=Green]'now copy new to time to old in preperation for next reading
      [/color][color=Black]s1 [/color][color=DarkCyan]= [/color][color=Black]s
      ms1 [/color][color=DarkCyan]= [/color][color=Black]ms
      us1 [/color][color=DarkCyan]= [/color][color=Black]us
      ns1 [/color][color=DarkCyan]= [/color][color=Black]ns
      [/color][color=Blue]do
            if [/color][color=Purple]pinc.6 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=DarkCyan]and [/color][color=Purple]pinc.7 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]then exit    [/color][color=Green];check for input removed
      [/color][color=Blue]loop
      high c.4[/color][color=Black]:[/color][color=Blue]pause [/color][color=Navy]1000[/color][color=Black]:[/color][color=Blue]low c.4                     [/color][color=Green];reset SR latches
      
      
      [/color][color=Blue]return[/color]

[color=Black]bintoasci:
      [/color][color=Blue]bintoascii [/color][color=Black]s0, n5,n4,n3,n2,n1
      [/color][color=Blue]let [/color][color=Black]l_num [/color][color=DarkCyan]= [/color][color=Navy]4
      [/color][color=Blue]gosub [/color][color=Black]msg0
      [/color][color=Blue]gosub [/color][color=Black]msg
      [/color][color=Blue]bintoascii [/color][color=Black]ms0, n5,n4,n3,n2,n1
      [/color][color=Blue]let [/color][color=Black]l_num [/color][color=DarkCyan]= [/color][color=Navy]2
      [/color][color=Blue]gosub [/color][color=Black]msg0
      [/color][color=Blue]bintoascii [/color][color=Black]us0, n5,n4,n3,n2,n1
      [/color][color=Blue]let [/color][color=Black]l_num [/color][color=DarkCyan]= [/color][color=Navy]2
      [/color][color=Blue]gosub [/color][color=Black]msg0
      [/color][color=Blue]bintoascii [/color][color=Black]ns0, n5,n4,n3,n2,n1
      [/color][color=Blue]let [/color][color=Black]l_num [/color][color=DarkCyan]= [/color][color=Navy]2
      [/color][color=Blue]gosub [/color][color=Black]msg0
      [/color][color=Blue]return[/color]
[color=Black]msg0:
      [/color][color=Purple]bptr [/color][color=DarkCyan]= [/color][color=Navy]25 [/color][color=DarkCyan]- [/color][color=Black]l_num
      [/color][color=Blue]for [/color][color=Black]loopy [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Black]l_num
            [/color][color=Blue]let [/color][color=Purple]pinsb [/color][color=DarkCyan]= [/color][color=Purple]@bptrinc                [/color][color=Green];update display
            [/color][color=Blue]pulsout [/color][color=Black]enable,[/color][color=Navy]1                    [/color][color=Green]'show data
      [/color][color=Blue]next [/color][color=Black]loopy
      [/color][color=Blue]return[/color]
[color=Black]msg:
      [/color][color=Blue]let [/color][color=Purple]pinsB [/color][color=DarkCyan]= [/color][color=Red]"."         [/color][color=Green]; output the data
      [/color][color=Blue]pulsout [/color][color=Black]enable,[/color][color=Navy]1        [/color][color=Green]; pulse the enable pin to send data.
      [/color][color=Blue]return[/color]
I really appreciate you help guys. I will post up in the finished project section when I get it finished. but feel free to suggest any changes and will see if I can them in and if the work
 

techElder

Well-known member
Don't lose track of the fact that @bptrinc changes the value of bptr AFTER it is used.

initialise bptr as 20 (which should now be 21 due to variable changes that have been made since) along to reflect to current variable use, maybe not clever just what it should have been. .... as for zero, OCD kicked in and had to be zero for what ever reason. the end bptr address (in variable pointer) will always be 25.
 

BESQUEUT

Senior Member
When #13 code will be clear, you may want to use the #macro directive :
#MACRO SendMsg Value, Length)
w2 = Value
L_num=Length
Gosub msg0
#ENDMACRO

SendMsg (ms,4)
SendMsg (ns,2)
SendMsg (us,2)
 

BESQUEUT

Senior Member
as for zero, OCD kicked in and had to be zero for what ever reason. the end bptr address (in variable pointer) will always be 25.
With that code
for loopy = 0 to l_num
you are sending l_num + 1 characters...
The last one is brobably zero, so you cannot see it... But who know ?
Loopy as nothing to do with bptr. It only count how many characters you are sending.
 

oracacle

Senior Member
yes I am aware, 0-4 is 5 characters, 0-2 is 3 characters. this is why I have set l_num (loop number) to 4 and 2 for each set of number to be displayed, I could have set as you appear to be suggesting 1-5 which in the terms of human understanding is most likely easier. I am quite aware the loopy as nothing to do with pbtr, they are separate comments.

also code from 13 (which has been edited from what it was originally) doesn't resolve the string of 0s issue.

tex I haven't forgotten, measures where and still are in place to ensure than the bptr starts in the correct place, as it currently stand bptr 21 through bptr 26
 

BESQUEUT

Senior Member
Please, can you publish the whole non working code with :
bintoascii w2, @bptrinc, @bptrinc, @bptrinc, @bptrinc, @bptrinc

As I did not mention to also define the End_Adress symbol, it may be lacking.
You can also write :
bptr = Start_Address+4-l_num
but it is some bytes more...
 

oracacle

Senior Member
that code no longer exists.
I am running short on time for today, so will try and have a look at it tomorrow morning when I get home from work.
I have attached a txt of the entire code that successfully runs as anticipated.
there is also a circuit diagram.
 

Attachments

BESQUEUT

Senior Member
Maybe I am wrong but I thing that the s1, ms1, us1 and ns1 are not needed
because s0, ms0, us0 and ns0 did not change since last call to DisplayTime.
Simply rewrite the s0, ms0, ... to the "old time " line.
 

oracacle

Senior Member
I was thinking about at work last night, providing the new time is always displayed second it should be fine.
@64mhz you can't tell which order the things are being displayed in which is good - I was shocked at how quickly the data printed at that clock speed.
 

oracacle

Senior Member
OK beaqueut I have been fiddling with the code a little more (finally got time between work today)

this works perfectly fine now, not sure why I was getting 0s. I may have typed bptr 21 instead of bptr = 21

Code:
[color=Black]DisplayTime:[/color]
[color=Green]'time displayed on OLED parralles display
'first update old time
      'go to begining of second line and print old time still held in display variables
      [/color][color=Blue]low [/color][color=Black]rs                        [/color][color=Green];enter command mode
      [/color][color=Blue]let [/color][color=Purple]pinsb [/color][color=DarkCyan]= [/color][color=Navy]192
      [/color][color=Blue]pulsout [/color][color=Black]enable,[/color][color=Navy]1
      [/color][color=Blue]high [/color][color=Black]rs                       [/color][color=Green];exit command mode
      [/color][color=Blue]gosub [/color][color=Black]bintoasci               [/color][color=Green];convert variables to ascii and display them

'now update new time
      [/color][color=Black]s0 [/color][color=DarkCyan]= [/color][color=Black]s
      ms0 [/color][color=DarkCyan]= [/color][color=Black]ms
      us0 [/color][color=DarkCyan]= [/color][color=Black]us
      ns0 [/color][color=DarkCyan]= [/color][color=Black]ns
      [/color][color=Green]'now return to begining of line 1
      [/color][color=Blue]low [/color][color=Black]rs                        [/color][color=Green];enter command mode
      [/color][color=Blue]let [/color][color=Purple]pinsb [/color][color=DarkCyan]= [/color][color=Navy]128
      [/color][color=Blue]pulsout [/color][color=Black]enable,[/color][color=Navy]1
      [/color][color=Blue]high [/color][color=Black]rs                       [/color][color=Green];exit command mode
      [/color][color=Blue]gosub [/color][color=Black]bintoasci               [/color][color=Green];convert variables to ascii and display them
      [/color][color=Blue]do
            if [/color][color=Purple]pinc.6 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=DarkCyan]and [/color][color=Purple]pinc.7 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]then exit    [/color][color=Green];check for input removed
      [/color][color=Blue]loop
      high c.4[/color][color=Black]:[/color][color=Blue]pause [/color][color=Navy]1000[/color][color=Black]:[/color][color=Blue]low c.4                     [/color][color=Green];reset SR latches
      
      
      [/color][color=Blue]return[/color]

[color=Black]bintoasci:
      [/color][color=Purple]bptr [/color][color=DarkCyan]= [/color][color=Navy]21                     [/color][color=Green];set initial address
      [/color][color=Blue]bintoascii [/color][color=Black]s0, [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc
      [/color][color=Blue]let [/color][color=Black]l_num [/color][color=DarkCyan]= [/color][color=Navy]4
      [/color][color=Blue]gosub [/color][color=Black]msg0
      [/color][color=Blue]gosub [/color][color=Black]msg
      [/color][color=Blue]bintoascii [/color][color=Black]ms0, [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc
      [/color][color=Blue]let [/color][color=Black]l_num [/color][color=DarkCyan]= [/color][color=Navy]2
      [/color][color=Blue]gosub [/color][color=Black]msg0
      [/color][color=Blue]bintoascii [/color][color=Black]us0, [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc
      [/color][color=Blue]let [/color][color=Black]l_num [/color][color=DarkCyan]= [/color][color=Navy]2
      [/color][color=Blue]gosub [/color][color=Black]msg0
      [/color][color=Blue]bintoascii [/color][color=Black]ns0, [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc

      [/color][color=Blue]let [/color][color=Black]l_num [/color][color=DarkCyan]= [/color][color=Navy]2
      [/color][color=Blue]gosub [/color][color=Black]msg0
      [/color][color=Blue]return[/color]
[color=Black]msg0:
      [/color][color=Purple]bptr [/color][color=DarkCyan]= [/color][color=Navy]25 [/color][color=DarkCyan]- [/color][color=Black]l_num
      [/color][color=Blue]for [/color][color=Black]loopy [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Black]l_num
            [/color][color=Blue]let [/color][color=Purple]pinsb [/color][color=DarkCyan]= [/color][color=Purple]@bptrinc                [/color][color=Green];update display
            [/color][color=Blue]pulsout [/color][color=Black]enable,[/color][color=Navy]1                    [/color][color=Green]'show data
      [/color][color=Blue]next [/color][color=Black]loopy
      [color=Purple]bptr [/color][color=DarkCyan]= [/color][color=Purple]bptr [/color][color=DarkCyan]- [/color][color=Black]loopy[/color]

      [/color][color=Blue]return[/color]
[color=Black]msg:
      [/color][color=Blue]let [/color][color=Purple]pinsB [/color][color=DarkCyan]= [/color][color=Red]"."         [/color][color=Green]; output the data
      [/color][color=Blue]pulsout [/color][color=Black]enable,[/color][color=Navy]1        [/color][color=Green]; pulse the enable pin to send data.
      [/color][color=Blue]return[/color]
 

BESQUEUT

Senior Member
OK beaqueut I have been fiddling with the code a little more (finally got time between work today)

this works perfectly fine now, not sure why I was getting 0s. I may have typed bptr 21 instead of bptr = 21

Code:
[color=Black]DisplayTime:[/color]
[color=Green]'time displayed on OLED parralles display
'first update old time
      'go to begining of second line and print old time still held in display variables
      [/color][color=Blue]low [/color][color=Black]rs                        [/color][color=Green];enter command mode
      [/color][color=Blue]let [/color][color=Purple]pinsb [/color][color=DarkCyan]= [/color][color=Navy]192
      [/color][color=Blue]pulsout [/color][color=Black]enable,[/color][color=Navy]1
      [/color][color=Blue]high [/color][color=Black]rs                       [/color][color=Green];exit command mode
      [/color][color=Blue]gosub [/color][color=Black]bintoasci               [/color][color=Green];convert variables to ascii and display them

'now update new time
      [/color][color=Black]s0 [/color][color=DarkCyan]= [/color][color=Black]s
      ms0 [/color][color=DarkCyan]= [/color][color=Black]ms
      us0 [/color][color=DarkCyan]= [/color][color=Black]us
      ns0 [/color][color=DarkCyan]= [/color][color=Black]ns
      [/color][color=Green]'now return to begining of line 1
      [/color][color=Blue]low [/color][color=Black]rs                        [/color][color=Green];enter command mode
      [/color][color=Blue]let [/color][color=Purple]pinsb [/color][color=DarkCyan]= [/color][color=Navy]128
      [/color][color=Blue]pulsout [/color][color=Black]enable,[/color][color=Navy]1
      [/color][color=Blue]high [/color][color=Black]rs                       [/color][color=Green];exit command mode
      [/color][color=Blue]gosub [/color][color=Black]bintoasci               [/color][color=Green];convert variables to ascii and display them
      [/color][color=Blue]do
            if [/color][color=Purple]pinc.6 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=DarkCyan]and [/color][color=Purple]pinc.7 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]then exit    [/color][color=Green];check for input removed
      [/color][color=Blue]loop
      high c.4[/color][color=Black]:[/color][color=Blue]pause [/color][color=Navy]1000[/color][color=Black]:[/color][color=Blue]low c.4                     [/color][color=Green];reset SR latches
      
      
      [/color][color=Blue]return[/color]

[color=Black]bintoasci:
      [/color][color=Purple]bptr [/color][color=DarkCyan]= [/color][color=Navy]21                     [/color][color=Green];set initial address
      [/color][color=Blue]bintoascii [/color][color=Black]s0, [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc
      [/color][color=Blue]let [/color][color=Black]l_num [/color][color=DarkCyan]= [/color][color=Navy]4
      [/color][color=Blue]gosub [/color][color=Black]msg0
      [/color][color=Blue]gosub [/color][color=Black]msg
      [/color][color=Blue]bintoascii [/color][color=Black]ms0, [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc
      [/color][color=Blue]let [/color][color=Black]l_num [/color][color=DarkCyan]= [/color][color=Navy]2
      [/color][color=Blue]gosub [/color][color=Black]msg0
      [/color][color=Blue]bintoascii [/color][color=Black]us0, [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc
      [/color][color=Blue]let [/color][color=Black]l_num [/color][color=DarkCyan]= [/color][color=Navy]2
      [/color][color=Blue]gosub [/color][color=Black]msg0
      [/color][color=Blue]bintoascii [/color][color=Black]ns0, [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc

      [/color][color=Blue]let [/color][color=Black]l_num [/color][color=DarkCyan]= [/color][color=Navy]2
      [/color][color=Blue]gosub [/color][color=Black]msg0
      [/color][color=Blue]return[/color]
[color=Black]msg0:
      [/color][color=Purple]bptr [/color][color=DarkCyan]= [/color][color=Navy]25 [/color][color=DarkCyan]- [/color][color=Black]l_num
      [/color][color=Blue]for [/color][color=Black]loopy [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Black]l_num
            [/color][color=Blue]let [/color][color=Purple]pinsb [/color][color=DarkCyan]= [/color][color=Purple]@bptrinc                [/color][color=Green];update display
            [/color][color=Blue]pulsout [/color][color=Black]enable,[/color][color=Navy]1                    [/color][color=Green]'show data
      [/color][color=Blue]next [/color][color=Black]loopy
      [color=Purple]bptr [/color][color=DarkCyan]= [/color][color=Purple]bptr [/color][color=DarkCyan]- [/color][color=Black]loopy[/color]

      [/color][color=Blue]return[/color]
[color=Black]msg:
      [/color][color=Blue]let [/color][color=Purple]pinsB [/color][color=DarkCyan]= [/color][color=Red]"."         [/color][color=Green]; output the data
      [/color][color=Blue]pulsout [/color][color=Black]enable,[/color][color=Navy]1        [/color][color=Green]; pulse the enable pin to send data.
      [/color][color=Blue]return[/color]
Note that bptr in initialized only one time. So you are using 15 memories. So b21 to b36 are unusable. You may prefer to start with bptr=60, so bx variables are unaffected.

Now that you have plenty of unused variables, maybe you can use two to create a temporary word variable to pass the value to be output (or use existing one).
This way, the bintoascii command can be in the msg0 subprogram (#13), and maybe also the bptr=...

At this point, main program will be simple :
Symbol Start_Address=60

wTemp=ms : l_num=4 : gosub msg0
wTemp=us : l_num=2 : gosub msg0
wTemp=ns : l_num=2 : gosub msg0


Finally, you can create a MACRO to have a very clear code (#17) :

#MACRO SendMsg (Value, Length)
wTemp = Value
L_num=Length
Gosub msg0
#ENDMACRO



' And the main program become :
SendMsg (ms,4)
SendMsg (ns,2)
SendMsg (us,2)


Note that you will not get any byte with the MACRO directive. It's only for readability.
 
Last edited:

oracacle

Senior Member
bptr is re-initialised at the end of msg0 sub procedure.
macro feel exceptionally lazy way to programme, saves no space and make the code harder to read, specially for those of use with dyslexia.

also code has evolved some what. I have actually been running tests with this.
Code:
[color=Black]DisplayTime:[/color]
[color=Green]'time displayed on OLED parralles display
'first update old time
      'go to begining of second line and print old time still held in display variables
      [/color][color=Blue]low [/color][color=Black]rs                        [/color][color=Green];enter command mode
      [/color][color=Blue]let [/color][color=Purple]pinsb [/color][color=DarkCyan]= [/color][color=Navy]192
      [/color][color=Blue]pulsout [/color][color=Black]enable,[/color][color=Navy]1
      [/color][color=Blue]high [/color][color=Black]rs                       [/color][color=Green];exit command mode
      [/color][color=Blue]gosub [/color][color=Black]bintoasci               [/color][color=Green];convert variables to ascii and display them

'now update new time
      [/color][color=Black]s0 [/color][color=DarkCyan]= [/color][color=Black]s
      ms0 [/color][color=DarkCyan]= [/color][color=Black]ms
      us0 [/color][color=DarkCyan]= [/color][color=Black]us
      ns0 [/color][color=DarkCyan]= [/color][color=Black]ns
      [/color][color=Green]'now return to begining of line 1
      [/color][color=Blue]low [/color][color=Black]rs                        [/color][color=Green];enter command mode
      [/color][color=Blue]let [/color][color=Purple]pinsb [/color][color=DarkCyan]= [/color][color=Navy]128
      [/color][color=Blue]pulsout [/color][color=Black]enable,[/color][color=Navy]1
      [/color][color=Blue]high [/color][color=Black]rs                       [/color][color=Green];exit command mode
      [/color][color=Blue]gosub [/color][color=Black]bintoasci               [/color][color=Green];convert variables to ascii and display them
      [/color][color=Blue]do
            if [/color][color=Purple]pinc.6 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=DarkCyan]and [/color][color=Purple]pinc.7 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]then exit    [/color][color=Green];check for input removed
      [/color][color=Blue]loop
      high c.4[/color][color=Black]:[/color][color=Blue]pause [/color][color=Navy]1000[/color][color=Black]:[/color][color=Blue]low c.4                     [/color][color=Green];reset SR latches
      
      
      [/color][color=Blue]return[/color]

[color=Black]bintoasci:
      [/color][color=Purple]bptr [/color][color=DarkCyan]= [/color][color=Black]start_address                      [/color][color=Green];set initial address
      [/color][color=Blue]let [/color][color=Black]tempword [/color][color=DarkCyan]= [/color][color=Black]s0
      [/color][color=Blue]let [/color][color=Black]l_num [/color][color=DarkCyan]= [/color][color=Navy]4
      [/color][color=Blue]gosub [/color][color=Black]msg0                                [/color][color=Green];display seconds
      [/color][color=Blue]gosub [/color][color=Black]msg                                 [/color][color=Green]'display decimal
      [/color][color=Blue]let [/color][color=Black]tempword [/color][color=DarkCyan]= [/color][color=Black]ms0
      [/color][color=Blue]let [/color][color=Black]l_num [/color][color=DarkCyan]= [/color][color=Navy]2
      [/color][color=Blue]gosub [/color][color=Black]msg0                                [/color][color=Green];display ms (milli seconds)
      [/color][color=Blue]let [/color][color=Black]tempword [/color][color=DarkCyan]= [/color][color=Black]us0
      [/color][color=Blue]let [/color][color=Black]l_num [/color][color=DarkCyan]= [/color][color=Navy]2
      [/color][color=Blue]gosub [/color][color=Black]msg0                                [/color][color=Green];display us (micro seconds)
      [/color][color=Blue]let [/color][color=Black]tempword [/color][color=DarkCyan]= [/color][color=Black]ns0
      [/color][color=Blue]let [/color][color=Black]l_num [/color][color=DarkCyan]= [/color][color=Navy]2
      [/color][color=Blue]gosub [/color][color=Black]msg0                                [/color][color=Green];display ns (nano seconds)
      [/color][color=Blue]return[/color]
[color=Black]msg0:
      [/color][color=Blue]bintoascii [/color][color=Black]tempword, [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc[/color][color=Black], [/color][color=Purple]@bptrinc
      bptr [/color][color=DarkCyan]= [/color][color=Black]end_address [/color][color=DarkCyan]- [/color][color=Black]l_num
      [/color][color=Blue]for [/color][color=Black]loopy [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Black]l_num
            [/color][color=Blue]let [/color][color=Purple]pinsb [/color][color=DarkCyan]= [/color][color=Purple]@bptrinc                [/color][color=Green];update display
            [/color][color=Blue]pulsout [/color][color=Black]enable,[/color][color=Navy]1                    [/color][color=Green]'show data
      [/color][color=Blue]next [/color][color=Black]loopy
      [/color][color=Purple]bptr [/color][color=DarkCyan]= [/color][color=Black]start_address
      [/color][color=Blue]return[/color]
[color=Black]msg:
      [/color][color=Blue]let [/color][color=Purple]pinsB [/color][color=DarkCyan]= [/color][color=Red]"."         [/color][color=Green]; output the data
      [/color][color=Blue]pulsout [/color][color=Black]enable,[/color][color=Navy]1        [/color][color=Green]; pulse the enable pin to send data.
      [/color][color=Blue]return[/color]
the number of variable wasn't an issue, never was going to be, the idea of using bptr as to make it easier to cycle through and display the information on the OLED. I could have ran through each of the variable displaying each one. but u thought it would have made more sense to have a small loop that can cycle through each one, saving programme space (not that was an issue either)
 

BESQUEUT

Senior Member
bptr is re-initialised at the end of msg0 sub procedure.
I did not saw that...
bptr = bptr - loopy
In that case loopy is l_num +1
so bptr is nothing witch make sense...
(OK with last version in #26...)

Why not simply write
bptr = start_address
just before the bintoascii command ?

The idea with Start_Address=60 is to make a fully independant subroutine : no risk of "side-effect" with bx variables...

You are now ready to use a MACRO !
 
Last edited:

oracacle

Senior Member
I had not read anything that said using bptr above the variable values, there is also not affect on any of the varaibles beyond storing the information that would have been stored any way.

also check the updated code, its already says bptr = start_address, doing it the other way cause garbage to be printed for some reason, I was unable to find out why, I tried a few variations.

the system work as anticipated.
saving a single line of code not to much of a concern, although it has been noted for the next iteration of software, if another iteration comes along.
also I understand macro, I have been ready for them for a long, even tried using them, its how I know that I struggle to read them.
call it old school but if the code is there, write it, copy and paste it, its easier to read when its there by comparison to when exists only in imagination (well until the programme is compiled, but then you still don't get to see it)
 

BESQUEUT

Senior Member
also check the updated code, its already says bptr = start_address, doing it the other way cause garbage to be printed for some reason, I was unable to find out why, I tried a few variations.
YES I saw that and updated #27 striking some words.
I was saying that bptr = start_address can be in the msg0 subroutine, just before bintoascii, and only one time.

The system work as anticipated. saving a single line of code not to much of a concern
OK for that : if code fit in memory , it fit and no need for anything more.
My posts where just for the beauty of the gesture.
 
Top