You are on page 1of 2

;

;
;
;

This program marches a train across an electronic signboard.


It is superior to Train1.txt because the image data has been
isolated from the program logic. This makes it easy to reuse
this 8051 code to walk any image across the signboard.
LJMP Start

; Jump over the DB statements included from


; the "TrainData.txt" file since DB statements
; hold data rather than executable instructions.

INCLUDE "TrainData.txt"
Start:
;
;
;
;
;
;

The key to this program is the "MOVC A,@A+DPTR" instruction.


Remember that the MOV instruction has the general form:
MOV destination,source
where both "destination" and "source" refer either to
addresses in data memory or one of the special function
registers.

;
;
;
;
;

The MOVC instruction is a special flavor of MOV instruction


where the source is some byte in program memory rather than
in data memory. Hence the MOVC instruction allows us to
transfer bytes that we have buried in program memory (probably
using the DB assembler directive) into data memory.

;
;
;
;
;
;
;
;

The flavor of MOVC instruction that we will employ is


"MOVC A,@A+DPTR" which adds together the current value of
the accumulator (A) and the "data pointer" (DPTR, a 16 bit
special function register) and uses the result for the
source address in program memory. As an example, if
the ACC holds the value 5 and the DPTR register holds
the number 0x00F0 then the MOVC A,@A+DPTR will load the
ACC with the contents of program memory address 0x00F5.

; We start by initializing the DPTR to point into program


; memory at the start of the train image data.
MOV DPTR,#StartOfImageData ; this label is found in TrainData.txt
;
;
;
;
;
;
;

If at this point we performed:


MOV A,0
MOVC A,@A+DPTR
then the ACC would be loaded with that program memory byte that
is the first column of the train image data. Hence, by first
initializing the ACC with the correct value, we can use the
MOVC instruction to access any byte (column) of train image data.

;
;
;
;
;

We need a variable to control how many times we iterate


through the upcoming loop. We choose to use data memory
location 0 for this purpose. We use the EQU assembler
directive to assign the label "LoopCounter" to this address
so we don't have to refer to it as "address 0".

LoopCounter

EQU

; We use the CJNE instruction to exit from the loop once our
; LoopCounter reaches the value of 64 since there are only 64
; columns of train data in the TrainData.txt file.

Loop:

MOV LoopCounter,#0

; initialize the loop counter

MOV A,LoopCounter

;
;
;
;
;
;
;
;
;
;
;

MOVC A,@A+DPTR
MOV P0,A
INC LoopCounter
MOV A,LoopCounter
CJNE A,#64,Loop
Done:

SJMP Done

initialize ACC with a byte offset


into program memory BEYOND where
the DPTR points
this instruction copies a byte
from program memory into the ACC
output the new column to the
electric signboard
increment our loop counter
prepare to test the loop counter
keep looping until we have output
64 columns of train data

You might also like