Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

EEE8087 2W Rev. 1.0

Real Time Embedded Systems

Worksheet 2. I/O Programming

Wordlength

Questions in the previous worksheet assumed that you were working with 16-bit values, which are the default for this processor. During I/O operations, however, it is usually necessary to transfer 8 bit (1-byte) values. Instructions can be made to act on 8 bits, instead of 16, by suffixing the instruction mnemonic with '.B' (byte).

For example, if the LED has been mapped to address 2000H, then the following sequence will set it to logic- 1.


move.b   #$01,d0   ;moves 8 bits with the value 01H to the RH 8 bits in D0

move.b   d0,$2000   ;moves RH 8 bits of D0 to location 2000H


Note that a '.B' instruction will act only on the RH byte of the register. For example, if D0 contains the following value

89

ab

cd

ef

then the instruction

move.b           $3000,d0

will move the byte from memory location 3000H to the RH byte of the register, leaving the other three bytes unchanged.

89

ab

cd

01


3000

01

3001

06

3002

73

3003

a2

3004

45

There will be other occasions when you need to work with values that are too large to be represented by 16 bits. The registers are, in fact, 32 bits (4 bytes) long. 32-bit operations may be specified by suffixing the instruction with '.L' (longword).

move.l   $2000,d0   ;move 32 bits from locations 2000H .. 2003H to D0

move.l   $2004,d1   ;move 32 bits from locations 2004H .. 2007H to D1

add.l   d0,d1   ;adds all 32 bits in D0 to D1

You need to exercise extreme care when, as is often necessary, you are using byte and longword operations within the same code sequence. Think carefully about what will happen when the unchanged upper 3 bytes following a .B instruction are subsequently used as an input to a .L instruction. Try some examples on the simulator, and single-step through the programme if in any case you are unsure.

Practical Work

1.

The simulator has 8 push-button switches, mapped to address E00014H and wired so that each switch returns a logic-0 when pressed and logic- 1 when released. It also has 8 LEDs, mapped to address E00010H. Programme the system so that the RH LED changes state each time the RH switch is pressed, and demonstrate it on the simulator.

2.

The simulator also contains 8 7-segment displays. From left to right, the digits are mapped to     addresses E00000, E00002, E00004 .. E0000E. Programme the simulator so that the right-hand digit displays zero, and increments in hexadecimal up to F each time the RH push-button is        pressed. After the display reaches F, it resets to zero.

Each segment is set by one of the bits in the output byte. The following patterns correspond to each displayed value.

kseg

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

$3f

$06

$5b

$4f

$66

$6d

$7d

$07

$7f

$67

$77

$7c

$39

$5e

$79

$71

$80

;7-seg display patterns

;0

;1

;2

;3

;4

;5

;6

;7

;8

;9

;A

;b

;C

;d

;E

;F

;.

Nowadays, memory is so large and cheap that there is little to be gained from using 16-bit values, and recent versions of this processor therefore perform all operations except moves at 32 bits.       Therefore, all instructions except move should be suffixed '.L', and will relate to 4-byte values.        Move operations may optionally still work at 8 bits, in order to deal with character data or to allow   data transfers to 8-bit peripheral devices, so a move instruction may be suffixed either '.L' or '.B'.    Although the simulator is designed to accommodate older devices that did use 16-bit values (no     suffix), it would be a good idea from now on to work with 32-bit values consistently, except in some move instructions for which it is essential to use 8-bits. Answers to this and all subsequent             questions have been programmed accordingly.

3. Assessment question

Work in pairs on this question, and keep a copy of your answer, together with a note of the input you used to test it.

The 8 push button switches each correspond to one bit in the byte at E00014H. The left hand     switch corresponds to bit 7, and the right hand one to bit 0. Programme the simulator so that the user may press any of these switches, one at a time, in a sequence of any length. The user then indicates that the sequence is complete by pressing the RH permanent switch which is similarly mapped to bit 0 at address E00012H. At this point, the system plays the sequence back by lighting the LEDs that correspond to each of the input values, in the order in which they were entered.

The sequence will probably play back very quickly. Therefore you should insert a short delay before changing from one LED to the next, so that the playback sequence is clearly visible. A delay can be programmed by setting a register to a large value, then executing a loop that repeatedly                  decrements it until it reaches zero. The large number of instructions executed as a result will hold    the simulator up for a noticeable period of time, but since the simulator will run at different speeds   on different computers, you will need to do some experimentation to find a value that works well on yours.

Answers

1.

*-----------------------------------------------------------

* Title      : Single-task loop

* Written by : JNC

* Date       :

* Description: Toggles LED0 when pushbutton SW0 is pressed

*-----------------------------------------------------------

led

sw

start:

equ

equ

org

move

move

move.b

$e00010

$e00014

$1000

#0,d0

d0,ledstat

d0,led

;led

;switch

;set led off

;repeat

move.b

and

bne

move

eor

move

move.b

move.b

and

beq

bra

ledstat ds

sw,d0

#1,d0

l0

ledstat,d0

#$01,d0

d0,ledstat

d0,led

sw,d0

#1,d0

l1

l0

1

;  wait until switch pressed

;********

;  invert led

;  wait until switch released

;led state

end    start

Try moving the three lines of code at l1 to the point marked with a row of asterisks. What effect does this have on the behaviour of the programme?

2.

*-----------------------------------------------------------

* Title      : Single-task loop

* Written by : JNC

* Date       :

* Description: Increments digit when pushbutton SW0 is pressed

*-----------------------------------------------------------

sevseg

sw

equ

equ

org

$e0000e

$e00014

$1000

;led

;switch

; the abbreviation '^' means 'holds the address of' or 'points to'

start:  move.l

#0,d1

;set count in d1 = 0

move.l

#kseg,a0

;a0 ^ segment pattern table

move.b

(a0),d0

;set display = count

move.b

d0,sevseg

 

add.l

#1,d1

;increment count

;repeat

l1:

move.b

and.l

bne

sw,d0

#$1,d0

l1

;  wait until switch pressed

 

move.l

add.l

move.b

move.b

#kseg,a0

d1,a0

(a0),d0

d0,sevseg

;  set display

l2:

move.b

and.l

beq

sw,d0

#1,d0

l2

;  wait until switch released

 

add.l

cmp.l

bne

#1,d1

#$10,d1

l9

;  increment count

;  if count = 10

 

move.l

#0,d1

;    count = 0

l9:

bra

l1

 

kseg

 

 

;7-seg display patterns

 

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

dc.b

$3f

$06

$5b

$4f

$66

$6d

$7c

$07

$7f

$67

$77

$7c

$39

$5e

$79

$71

$80

;0

;1

;2

;3

;4

;5

;6

;7

;8

;9

;A

;b

;C

;d

;E

;F

;.

end    start