axe133y difficulties

Looks like i have run into another problem, i am attempting to display the results of keypad presses on the display but just get lots of garbage. My test is some code taken from Ron Hacketts book the evil genius for the keypad interface where i have made the circuit for using the keypad on the adc input and checking with a mm when keys are pressed appears to function ok how ever i cannot get the oled display to show the key presses to see what readaings i get for each key press. A copy of his code is here with my attempt to get it to show on the display, am i doing this wrong ? i have commented out the send to terminal.

Code:
' Program uses an ADC approach to decoding a 4X4 matrix keypad.
' It sends the keypress ADC key value to the terminal window.
	
' === Variables ===
symbol key  = w0		' used in adc10; word variable is required 
symbol junk = b2		' throwaway variable used for debouncing 	
	
' === Directives ===
#com 3							' specify serial port
#picaxe 08M2					' specify processor
#terminal 9600			' open terminal (8MHz produces 9600 BAUD)
	
' ==================== Begin Main Program =====================

setfreq m8
dirsC = %00010011
							' as fast as possible

do	
	wait_for_keypress:
  	readadc c.2, junk
		if junk < 5 then wait_for_keypress
		pause 100						' debounce keypress
		readadc10 c.2, key		'get ADC value
		
	wait_for_release:	
		readadc c.2, junk
		if junk > 5 then wait_for_release
		;sertxd ("key = ",#key,cr,lf)	' send ADC value to terminal
		serout 0, n2400, (254,1)
		pause 30
		serout 0, n2400, (w0,cr,lf)
		
loop
 

hippy

Ex-Staff (retired)
serout 0, n2400, (w0,cr,lf)
You need to use #w0 to display the contents of 'w0' as a readable value and do not need to send CR or LF ...

serout 0, n2400, ( #w0 )

You can also use BINTOASCII to format the variable value to be displayed.
 

Axel87

Senior Member
Maybe a dumb question-
Can anyone explain why #w0 is required instead?
Or provide reference material?

Thank you
 

Paix

Senior Member
serout 0, n2400, (w0,cr,lf)
Will return the ASCII value of the number held in w0, which if it happens to be 65 will actually return the character "A" followed by cr,lf . Not all characters are printing characters however.

serout 0, n2400, (#w0,cr,lf)
Will return the ASCII representation of the number. If the number is 65 it will return a two character response "65" followed by cr.lf
in the case of w0, if the stored value is 3276, then "3276" will be returned/sent.

Does this make sense?
 

Paix

Senior Member
http://www.picaxe.com/BASIC-Commands/Serial-RS232-Interfacing/serin/
Reading number values

When the #variable format is used received data will be taken and converted to a number.

All characters received are ignored until the first ASCII digit character is received. A number is then determined until a ASCII non-digit character is received. The value stored in the variable will be number represented by the digit characters received. Note that the #variable will not complete until the number has been terminated by a non-digit character being received.

http://www.picaxe.com/BASIC-Commands/Serial-RS232-Interfacing/serout/
The # symbol allows ASCII output. Therefore #b1, when b1 contains the data 126, will output the ascii characters "1" "2" "6" rather than the raw data 126. The # symbol can also be used with word, bit and input pin variables.

From the above, you can see that if # is used with data on the transmit side of things, then the variable transmitted will be the expanded numeric value.

If # is used on the receive side of things, then the number received will be expanded into the ASCII representation. This all takes time and so can impact upon the communication process.

I do hope that this is now clear.
 

srnet

Senior Member
Maybe a dumb question-
Can anyone explain why #w0 is required instead?
Or provide reference material?
The manuals explain most stuff quite well, so are a good first point of reference.

The 'serout' command on page 208 of the manual, describes the use of #
 

Axel87

Senior Member
Sorry for the delayed response guys, but thank you for your time and input!
Does help clear things up a little.
Hope others find this a little useful as well
 
Top