Word variable into bintoascii for parallel interface?

bfgstew

Senior Member
Good morning all.

I have been making inroads into using the parallel OLED interface kindly submitted by Nick12ab, I have it up and running and is as sweet as a nut, rapidly fast and am very impressed with its performance.
BUT, and with all things, there is a trade off, parallel is code hungry, very hungry compared to serial. It is also, for us newbees, fairly complicated to code compared to serial, and this is my hurdle to get over. Now Nick has given a great tutorial on how to impliment the OLED and have read it and understand most of it, and am very greatful to Nick for taking his time to show it. However, I am attemting to write a word variable to give a time as each key is pressed I would like the screen updated to show the value in w?. I have it sort of working but the values are, it seems, a digit over what I want, if I put in 2222, I get 22222 back, 0022 I get 002222. To put a word variable into bintoascii you need 5 byte variables, as I only need to go up to 9999, therefore only need 4 byte variables, is this the problem

The keypad is a 4x3 matrix that is proven to work and is working perfectly.
OLED is driven, parallel, via 40X2 off pinsB and C.7 and C.6. as per documentation and works.

This is how I used to get a value into a word variable with serial interface.
Code:
		For b55 = 1 to 4				
  			Gosub GKP 
  			if key_value = 12 then return
  			endif
  			pause 30	
  			w1 = w1 * 10 + b1
  			serout B.7,N2400,(254,203,"D1-",254,206,#w1,"ms")
  			pause 30
  			next b55
 		Return
Keypad scan routine is the same for both.

Code:
GKP:
 	 Do
    		Gosub GTKP			' Wait until no key pressed
  			Loop Until key_value = 0
 	 Do
   		 Gosub GTKP			' Wait until key pressed
  			Loop Until key_value <> 0
  			If key_value = 11 Then
    			key_value = 0
  		End If
  	Return		
GTKP:	;Keypad scan coding
		key_pos = 0
		key_value = 0
	 	High ROW1 : gosub ScanCol : low ROW1
	 	High ROW2 : gosub ScanCol : low ROW2
	 	High ROW3 : gosub ScanCol : low ROW3 
	 	High ROW4 : gosub ScanCol : low ROW4
	 	Return	 	
	 	ScanCol:
	 		if COL1 = 1 then : key_value = key_pos + 1 : endif
	 		if COL2 = 1 then : key_value = key_pos + 2 : endif
	 		if COL3 = 1 then : key_value = key_pos + 3 : endif
	 		key_pos = key_pos + 3   
   		return
This is what I am running at the moment on the parallel interface to input into w?
Code:
drop1:
	dirsB = 255								
	low rs							
	output enable
	lcddata = %00111011 : pulsout enable,16		
	lcddata = %00000001 : pulsout enable,608			
	lcddata = %00001100 : pulsout enable,608		
	lcddata = %00000110 : pulsout enable,16			  
				low rs
		lcddata = 128 : pulsout enable,1
			high rs
		for loopcounter = 0 to 20
			lookup loopcounter,("  DROP ONE: ____ms  "), lcddata
		pulsout enable,1
	next loopcounter 
	For b21 = 0 to 3
	           low rs
	           lcddata = 139 : pulsout enable,1
	           high rs				
  			Gosub GKP 
  			if key_value = 10 then goto initd1 
  			if key_value = 12 then return
  			endif
  			w2 = w2 * 10 + b1
  			for loopcounter = 0 to 4
  			BinToAscii w2,b50,b51,b52,b53,b54
			lookup loopcounter,(" ",b51,b52,b53,b54), lcddata
		pulsout enable,1
	next loopcounter
	next b21
  			pause 2000
 		Return
Any pointers would be greatfully received, many thanks .

Stewart
 

hippy

Ex-Staff (retired)
After your "w2 = w2 * 10 + b1" add a temporary "w2 = 12345".

If the display doesn't show "12345" then there is possibly something wrong within the loop containing BINTOASCII.

You can add SERTXD commands to show program flow and variable values which will help check it is doing what you expect or not.
 

bfgstew

Senior Member
Thanks Hippy, will give it a shot shortly as I have some more mundane tasks to complete first....................:(
 

srnet

Senior Member
Any pointers would be greatfully received, many thanks .
What about some pointers as to what the code is doing ?

Comments in the code will help you also, in a few months time you will forget how it works.

So guessing only;

"0022 I get 002222"

Are you clearing the display from the previous count ?
 

bfgstew

Senior Member
Hi folks, panic over. I managed to sort the problem out. I had inadvertantly put an extra variable in the bintoascii loop, teach me for using copy and paste.

@srnet, sorry, my biggest fault is not putting comments on code................:rolleyes:
 

srnet

Senior Member
@srnet, sorry, my biggest fault is not putting comments on code................:rolleyes:
I can't manage from one day to the next without comments in my code.

It would also be an idea to add comments for the benefit of those trying to help you who dont have a clue what your code is supposed to be doing.
 
Top