FlexScan Introduction - Lesson 1

by Oliver Scholz

Getting started

Before we start you need some basic knowledge and tools I won't give you here. You need an 8032 assembler (there are many on the net), and you need to be able to program and erase a 27C256 EPROM. Of course you need to have some experience with the 8032/8052 series CPUs or at least some other assembly knowledge. If you have built your scantool board and see the "no application" message, you're ready to get started...

First you need to know how the ScanOS finds and starts an application program. ScanOS looks at the first 32 bytes of the external EPROM at address $8000. If the first two bytes contain values other than $A5, $02 the EPROM will not be recognized as a valid application program. The header contains your "reset vector" so to speak, everything has already been initialized, and you're ready to go, even the "screen" has been cleared. We will not worry about CRC calculation for now, so that has been disabled in this example.

Here's what a simple "Hello world" application would look like:

;
;	simple "Hello World" program for ScanOS
;
STROUT	EQU	0106H		;vector of the string output routine

	ORG	08000H		;The external EPROM starts at address $8000

;Application program header structure
	DB	0A5H		;"Magic" value, must be $A5
	LJMP	MAIN		;this is the starting address of your sample code
	DB	0,018H		;program length, only used for CRC calculation and loading
	DB	06EH,044H	;CRC, $6E44
	DB	1		;flag byte 1, set to 0 to disable CRC calculation
	DB	0		;decompression mode: reserved
	DB	001H,05EH	;30-10-00
	DB	0,0		;no more files present
	DB	0,0		;2 reserved bytes
	DB	'1st program',0 ;up to 15 character program name plus nullbyte

	ORG	08020H
MAIN:	MOV	DPTR,#STRING	;get the address of the string
	LCALL	STROUT		;and print it out
LOOP:	SJMP	LOOP		;wait here forever...

STRING:	DB	'Hello World!',13,10,0
Click here to download the hex file for this example

Note: All future examples will no longer list the header structure, but instead will begin directly with the main entry point. Note that the sample code pieces presented on this and the following pages are only fragments and require the proper application program header and equates to run.

A simple "boot selector"

That wasn't so hard, was it? Now, let's get more serious and choose one of three different applications at startup. We'll present the user with a choice of three entries and branch to different areas of our ROM. For simplicity, I'll leave out the equates for the ScanOS function calls, they should be included in your source along with something similar to what you saw in the previous example. Let's just start at the "MAIN" label...

MAIN:	MOV	DPTR,#BOOT_SELECT ;pass the address of the menu structure
	LCALL	SEL_MENU	;let the user make a choice	

	CJNE	A,#0FFH,VALID	;Did the user abort?
	SJMP	MAIN		;yes: start over again!

VALID:	CJNE	A,#0,SEL1	;Did the user select entry #0 ?
	LJMP	HELLO_WORLD	;Yes: branch to Hello World program

SEL1:	CJNE	A,#1,SEL2	;Or entry #1 ?
	LJMP	PACMAN		;Yes: this is an exercise for the reader...

SEL:	LJMP	SCANTOOL	;Well, nothing else left, let's do some scanning..

BOOT_SELECT:
	DB	3		;Three entries total
	DB	0		;Separator
	DB	'Hello World',0	;Entry #0
	DB	'PacMan',0	;Entry #1
	DB	'ScanTool',0	;Entry #2

A Message Box

The last example for now is what we know from desktop computers as "Message boxes". This is a small message for the user that is usually just acknowledged or offers a simple selection between yes and no, or ok and cancel.

Prompting the user for such choices is really simple. The following code fragment displays a short message that the user can acknowledge or cancel. If the message does not fit the display, this function will try to format the message into multiple lines, and the user can scroll through the text before making a choice with the "*" (Cancel/No) or "#" (Ok/Yes/Enter) key.

ENTER		EQU	13
LCDWIDTH	EQU	16

MAIN:	MOV	DPTR,#MSG_TEXT	;This is a pointer to the message text
	MOV	A,#LCDWIDTH	;This is the default length of the LCD display
	LCALL	MESSAGE		;Display the message box and wait for user input.
	CJNE	A,#13,GO_CANCEL	;Branch if the user did not answer "ok"

	...

MSG_TEXT:
	DB	'Do you wish to continue? | No=*   Yes=#',0


Click here to go to lesson 2

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