18M2 and simulator disagree

jusmee

Member
This simple little serial menu program works correctly in the simulator, but when the 18M2 runs it, the select case always defaults to "Not Valid"

Code:
main:
	sertxd("1. test1",cr,lf)
	sertxd("2. test2",cr,lf)
	sertxd("3. test3",cr,lf)
	sertxd(cr,lf,"Choose...",cr,lf)
get_in:	
	serrxd b1

	select b1
	case 1
	sertxd("You chose 1",cr,lf)
	case 2
	sertxd("You chose 2",cr,lf)
	case 3
	sertxd("You chose 3",cr,lf)
	else
	sertxd("Not Valid",cr,lf)
	endselect
	
	
	goto main
 

inglewoodpete

Senior Member
Actually, the PICAXE is behaving correctly, according to you code. But the code is probably wrong for what you are intending.

If you want the PICAXE code as shown to work correctly, you should type Ctrl-A for value 1, Ctrl-B for value 2 and Ctrl-C for value 3.

If you want the PICAXE to accept the ASCII characters "1", "2" and "3", then change the case statements as follows:

Case "1"
Case "2"
Case "3"

I don't use the simulator much, so can't comment on its behaviour.
 

jusmee

Member
Actually, the PICAXE is behaving correctly, according to you code. But the code is probably wrong for what you are intending.

If you want the PICAXE code as shown to work correctly, you should type Ctrl-A for value 1, Ctrl-B for value 2 and Ctrl-C for value 3.

If you want the PICAXE to accept the ASCII characters "1", "2" and "3", then change the case statements as follows:

Case "1"
Case "2"
Case "3"

I don't use the simulator much, so can't comment on its behaviour.

Ah, thank you. If the simulator hadn't misled me, I might have realised I wasn't comparing ascii values like I needed to.

Looks like the simulator is doing an ascii to binary conversion on the input, because now, the simulator is failing, but the change you suggested works properly on the 18M2.
 

hippy

Ex-Staff (retired)
The simulator and 18M2 behave exactly the same but what changes is that the simulator has to ask for what it is you want to receive and interpret what that means whereas an 18M2 in a real circuit will simply receive whatever byte value you throw at it. For example -

#Picaxe 18M2
SerRxd b0
Do : Loop

If you send the chip 'ASCII character 1' then b0 will hold 'ASCII charcter 1', value 49, $31. If you send it binary value 1 then b0 will hold binary value 1, $01.

When the simulator runs and you are asked for input, entering 1 will be passed as value 1, entering "1" with quotes will be passed as 'ASCII character 1', value 49, $31.

The simulator isn't 'failing' as such, just that what you want to send isn't being entered in the correct format.

A simple solution for handling single digits 0 to 9 as either binary or ASCII is to mask the received value ...

SerRxd b0
b0 = b0 & $0F
Select Case b0
Case 0: ...
Case 1: ...
:
Case 9: ...
Else: ...
End Select
 

jusmee

Member
I see. I was treating the simulator input dialog as equivalent to the terminal, and it's not. Thanks.
 
Top