EEE8087 IO Programming Notes

EEE8087 2W Rev. 1.0
Wordlength
Real Time Embedded Systems Worksheet 2. I/O Programming
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.l $2004,d1 add.l d0,d1
;move 32 bits from locations 2000H .. 2003H to D0 ;move 32 bits from locations 2004H .. 2007H to 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.
Code Help
EEE8087 2W Rev. 1.0
Practical Work
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.
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 ;7-seg display patterns
dc.b $3f
dc.b $06
dc.b $5b
dc.b $4f
dc.b $66
dc.b $6d
dc.b $7d
dc.b $07
dc.b $7f
dc.b $67
dc.b $77
dc.b $7c
dc.b $39
dc.b $5e
dc.b $79
dc.b $71
dc.b $80
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
浙大学霸代写 加微信 cstutorcs
EEE8087 2W Rev. 1.0
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.
*———————————————————– * Title : Single-task loop
* Written by : JNC
* Description: Toggles LED0 when pushbutton SW0 is pressed *———————————————————–
led equ sw equ
start: move
;led ;switch
;set led off
; wait until switch pressed
d0,ledstat
move.b d0,led
l0: move.b sw,d0
and #1,d0
move ledstat,d0 ; invert led
eor #$01,d0
move d0,ledstat
move.b d0,led
l1: move.b sw,d0
and #1,d0
beq l1 bra l0
; wait until switch released
;led state
ledstat ds
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?

EEE8087 2W Rev. 1.0
*———————————————————– * Title : Single-task loop
* Written by : JNC
* Description: Increments digit when pushbutton SW0 is pressed *———————————————————–
sevseg equ
sw equ
; the abbreviation ‘^’ means ‘holds the address of’ or ‘points to’
start: move.l #0,d1
move.l #kseg,a0
move.b (a0),d0
move.b d0,sevseg
add.l #1,d1
l1: move.b sw,d0
and.l #$1,d0
move.l #kseg,a0
add.l d1,a0
move.b (a0),d0
move.b d0,sevseg
l2: move.b sw,d0
and.l #1,d0
beq l2
add.l #1,d1
cmp.l #$10,d1
bne l9
move.l #0,d1
l9: bra l1
;set count in d1 = 0
;a0 ^ segment pattern table
;set display = count
;increment count
; wait until switch pressed
; set display
; wait until switch released
; increment count
; if count = 10
; count = 0
;7-seg display patterns
dc.b $3f
dc.b $06
dc.b $5b
dc.b $4f
dc.b $66
dc.b $6d
dc.b $7c
dc.b $07
dc.b $7f
dc.b $67
dc.b $77
dc.b $7c
dc.b $39
dc.b $5e
dc.b $79
dc.b $71
dc.b $80
$e0000e ;led
$e00014 ;switch
Code Help, Add WeChat: cstutorcs