FlexScan Introduction - Lesson 5

by Oliver Scholz

A C3 ECM Scan example

Finally, you've made it. Now we will examine a sample program that displays a data stream from a mid-eighties C3 ECM.

First, we need to reserve some space for a receive buffer, and initialize ScanOS to look for a C3 data stream. The stream we're looking at will contain 25 bytes per frame, so that's the buffer size we'll reserve.

	ORG	048H
buffer: DS      25
;
MAIN:	LCALL	MODE_10K	;switch ECM into 10K mode to initiate diagnostic data stream.
;
	MOV	DPTR,#buffer	;pass buffer address
	MOV	A,#25		;and frame/buffer size
	LCALL	INIT_C3		;to ScanOS and initialize the receive handler
;
LOOP:	LCALL	C3_TESTLOCK	;check if ScanOS has locked on to the data stream
	CJNE	A,#0,START
	SJMP	LOOP		;wait until communication has been established

That's all there is to it! Now ScanOS will constantly read the frames it receives into the provided buffer.

Displaying some data

Now we want to display and update the battery voltage from the data stream. We will use the function Slot_DispItem to display the data "item" from the stream. This function monitors the buffer for a new frame, and if a new frame has been received, it clears the screen and outputs the new value. In this data stream, the battery voltage is in byte 17 of the buffer (counting from zero) and ranges from 0 to 25.5 volts.

The "item" description is passed via a pointer that refers to a structure describing how the display should be formatted. It sounds difficult, but it's not. All you need to define are which byte in RAM contains what you want to output, how to interpret the data and two strings; one to be printed before the item, and one after it. The strings may also contain CR and LF characters, so you can use the full 2x16 LCD screen to display your data in a meaningful way.

Slot_DispItem will return when the user presses a key.

START:	MOV	DPTR,#S_BAT	;Point to a structure describing the battery "item"
	LCALL	SLOT_DISPITEM	;display "item" on LCD until user presses a key
;
	LCALL	EXIT_C3		;we're done, clean up
S:	SJMP	S		;wait here forever
;
S_BAT:	DB	buffer+17	;memory location containing "item", in this case battery voltage
	DB	3		;display routine to use: 3 = byte * 0.1
	DB	'Battery: ',0	;string to display before data value
	DB	' V',0		;string to display after data value

You see, it can't be much simpler. Of course, this is a pretty "dumb" scantool application. It only watches one byte in the data stream. But with the Sel_Menu function you can easily have the user select one of several choices, and use the result to load one of several description pointers into Slot_Dispitem. And after the user presses a key, it's not very smart to "hang", but, again, this is just a demo code snippet. Use your imagination. Or take a look at the application program in the next and final lesson, and take it from there.

If you don't like Slot_Dispitem and want to display more than one value at the same time, you can still use Slot_Output to display just one byte from the buffer and have it formatted, but then you'll have to take care of when to refresh, waiting for the next frame, etc.

What about the P4

Well, I'm glad you asked. As far as ScanOS is concerned, you just use a different init function, and you also need to pass the module ID of the module you're interested in:

	MOV	DPTR,#buffer
	MOV	A,#67		;The buffer needs to be bigger for the P4
	MOV	R0,#0F0H	;This is the module ID we're expecting (usually F0 or F4)
	LCALL	UART_INIT	;Initialize the UART handler
;
;... display the contents of the buffer here as above
;
	LCALL	UART_EXIT	;Clean up
S:	SJMP	S		;"hang"

So you see, it's not much different. One noteworthy thing though: some ECMs don't spill out their guts if you just switch to 10K mode, instead they must be sent a command frame to initiate data transmission. ScanOS has the function UART_Tx_Msg to do just that, but I could not test that function since I don't have access to an ECM with that feature. This is something left for your experiments...


Back to lesson 4 Click here to go to lesson 6

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