FlexScan Introduction - Lesson 4

by Oliver Scholz

A tiny Class 2 scanner...

This lesson will show how simple a tiny class 2 scanner can be. For this purpose, we will use message filtering to view only the functional messages from module $60. As before, the code will be broken into sections and discussed in detail. First we need to set up the handler and set the filtering options. We set our module ID to $F0, but this is not necessary for filtering functional messages, because those only contain a source ID, not a target ID. For physical messages we would be able to discriminate the target ID also.

	ORG	050H
buffer: DS	16

MAIN:	LCALL	CLS		;clear the screen

	MOV	DPTR,#buffer	;as before, pass the buffer and length to the OS
	MOV	A,#16
	LCALL	DLC_INIT	;and init the handler

	MOV	DPTR,#0F060H	;Set our module ID to $F0, and the peer module ID to $60
	MOV	A,#0C1H		;discard all physical messages, as well as functional messages not from peer
	LCALL	DLC_FILTER

Waiting for a message...

Now that things are set up, we are ready to wait for a message. A message is displayed with the length byte first, then a dash, and then the message itself in hex digits.

MSG_LOOP:
	LCALL	DLC_RX_READY	;check if new message is ready
	JNB	ACC.0,MSG_LOOP	;wait if no message
	PUSH	ACC		;save the result temporarily

	LCALL	CRLF		;print a newline and scroll up previous messages

	MOV	A,#buffer	;get buffer start adress
	MOV	R0,A
	MOV	A,@R0		;get length byte from buffer
	MOV	R7,A		;store length byte
	LCALL	LCDHEX		;print out length in hex

	MOV	A,#'-'
	LCALL	CHROUT		;print separator character

Displaying the message

Displaying the message contents is pretty straightforward and the code comments say it all...

	MOV	A,#buffer	;get buffer start
	MOV	R0,A
	INC	R0		;skip length byte
	CJNE	R7,#0,MSGOUT	;print a byte until end of message
	SJMP	MSGEND		;goto end of message handling

MSGOUT: MOV	A,R0
	PUSH	ACC		;save pointer

	MOV	A,@R0		;get byte from buffer
	LCALL	LCDHEX		;and print it in hex

	POP	ACC
	MOV	R0,A		;get pointer back
	INC	R0		;advance pointer
	DJNZ	R7,MSGOUT	;continue for rest of message

Cleanup work...

Now that the bulk work is done, there are only a few details left to do:

MSGEND:	POP	ACC		;get back status of buffer
	JB	ACC.1,MSG_OVF	;check if there was a buffer overflow

	MOV	A,#'.'		;no, append a period to the message text
	SJMP	NO_OVL

MSG_OVF:
	MOV	A,#'!'		;if overflow, append an exclamation mark
NO_OVL:
	LCALL	CHROUT

	LCALL	DLC_UNLOAD_MSG	;remove message from buffer and prepare for next message
	LJMP	MSG_LOOP

That's it! That wasn't so bad, was it? Now we can see all functional messages from module $60 (at least the first few bytes, depending on the LCD screen length). Since the length is evident and the source ID is not important, the next step could be not to print the length byte and source ID (because those are not important), but to instead print more of the message. This would be a nice exercise...

Here is the complete source file from this lesson (with the exception of all filtering being turned off), as well as the hex-file of this example.


Back to lesson 3 Click here to go to lesson 5

There have been visitors to this site since May 31, 2000.