Sei sulla pagina 1di 44

Programming Book for

6802 Microprocessor Kit

Wichit Sirichote

Rev 1.2 Nov 6, 2015

1
Preface

This programming book is designed for self-study how to program the 6802
microprocessor with machine language. The 6802 is software compatible
with the Motorola 6800 microprocessor from 1976. All most more than 40
Yrs ago. No manufacturing now. In the modern day with high complicated
microcontroller why we learn this chip? There will be many answers. For me,
the 6802 CPU has very nice addressing modes, instruction set and memory
organization.

The lab book provides 10 programs with source code in Assembly language
and instruction hex code. Students can test and do the experiments by
entering the hex code and run it easily.

For hex code modification with 6802 instruction, please get the 6802
datasheet from internet. The datasheet will show the instruction table for
converting the instruction into hex code. For hardware programming, you
can get details from the 6802 Kit User's Manual.

Programming the classic CPU is fun and is good to learn for young people.

2
Contents

Program 1 Load and Store instructions.............................................4

Program 2 Binary addition..........................................................................8

Program 3 BCD addition.............................................................................11

Program 4 Logical instructions................................................................14

Program 5 Bit rotation...............................................................................18

Program 6 Tone generation....................................................................21

Program 7 Reading key status.............................................................25

Program 8 Interrupt with IRQ................................................................29

Program 9 Using 10ms tick......................................................................32

Program 10 Digital timer............................................................................35

Decimal, 4-bit binray, Hex


Hex, 7-segment pattern
6802 Programming Registers
6802 Microprocesssor kit
Memory allocation

3
Program 1 Load and Store instructions
How to store 8-bit data to memory?

Line ADDR hex code Instruction comment


0001 0200 .ORG 200H
0002 0200
0003 0200 86 9F LDAA #$9F ; load Accumulator A with 9F
0004 0202 97 00 STAA $00 ; store it to location 00
0005 0204
0006 0204 .END
tasm: Number of errors = 0
This small program has only two instructions.

The 1st instruction is LDAA #$9F. $ or H symbol indicates HEX number.

9F is the 8-bit data to be loaded to the Accumulator A.

# symbol makes the 8-bit data to be constant. The method of getting such
data is called Immediate addressing mode.

The 2nd instruction is STAA $00. The Accumulator contents will be stored to
MEMORY at location 00 in page zero. The addressing mode is Direct mode.

Procedure
1. Enter the hex code from location 200 to 203.

2. Press REG, ACCA, write down the contents of Accumulator A.

ACCA ____
4
3. Press PC to set current display to 200.

4. Press STEP key. Press REG, ACCA again. Write down the ACCA.

ACCA ____
5. Press REG, 6 to see the contents of memory location 00.

_______ 00
6. Press PC, then STEP. Press REG, 6

_______ 00

We see that the contents of memory location 00 will be replaced with 9F.

Now if we want to load and store 16-bit data, we can use IX register.

Let us see load/store for 16-bit data.

0001 0200 .ORG 200H


0002 0200
0003 0200 CE 12 34 LDX #$1234
0004 0203 DF 00 STX $00
0005 0205
0006 0205 .END
tasm: Number of errors = 0

5
Index register, IX can be used to load 16-bit data. Above code will load 1234
to IX register.

STX $00 instruction will store IX to page zero location at 00 for high byte
and 01 for low byte.

Procedure
1. Enter the hex code from location 200 to 204.

2. Press PC to set current display to 200.

3. Press STEP to execute LDX #$1234 instruction.

4. Press STEP to execute STX $00 instruction.

5. Press REG, $00, write down the contents of location $00.

_______ 00

We see that the 2nd instruction will store $1234 to location 00 (high byte)
and 01(low byte). But the machine code is only two bytes, DF 00.

If the location to be stored is not page zero. Let us see another sample
code.

0001 0200 .ORG 200H


0002 0200
0003 0200 CE 12 34 LDX #$1234
0004 0203 FF 01 00 STX $0100

6
0005 0206
0006 0206 .END
tasm: Number of errors = 0

We see that STX $0100 has three byte hex code FF, 01 and 00. The 6802 calls
EXTENDED addressing (16-bit address) mode.

Procedure
1. Enter the hex code from location 200 to 205.

2. Write down the contents of location 100 and 101 before and after code
execution.

Location(before) Location(after)
0100 0101 0100 0101

Summary

For 8-bit data handling with LOAD/STORE instructions, we can use


Accumulator A or B. For 16-bit we can use IX register. Accessing the page
zero memory can be done with Direct addressing mode. The address in the
2nd byte can be only 8-bit. For 16-bit address, we will use Extended
addressing mode. The 2nd and 3rd byte will be 16-bit memory address.

7
Program 2 Binary Addition
Suppose we have two 16-bit binary numbers.

Num1 and Num2. We want to add it. We can use two locations in page zero.

Num1 = Num1 + Num2

NUM1 = 12ED
NUM2 = 35EE

We can place two numbers in memory and use ADDA and ADCA instruction
to add them.

Let us see the contents for NUM1 and NUM2.

NUM1 NUM2
00 (MS) 01(LS) 02(MS) 03(LS)
12 ED 35 EE

We can enter Num1 and Num2 to memory with ADDR and DATA key using
HEX number.

Here is the program.

0001 0200 .ORG 200H


0002 0200 ; ADD LOW BYTE
0003 0200 96 01 LDAA $01
0004 0202 9B 03 ADDA $03
0005 0204 97 01 STAA $01
0006 0206 ; ADD HIGH BYTE WITH CARRY
0007 0206 96 00 LDAA $00
0008 0208 99 02 ADCA $02

8
0009 020A 97 00 STAA $00
0010 020C
0011 020C 3F SWI
0012 020D
0013 020D .END
tasm: Number of errors = 0

We will add the LS byte with ADDA instruction then followed with MS byte
by ADCA instruction. We put the SWI, (Software Interrupt) instruction at
the end of our program. It will make CPU to jump back to monitor program
with key GO.

Procedure
1. Enter the code from location 200 to 20C.

2. Enter Num1 and Num2 to memory.

3. Add two numbers by hand calculation using binary number for both
numbers.

12ED + 35EE =?

4. Check the result with 6802 running with key GO. What is the result that
stored at location 00 and 01.? We can use key REG, $00 to see the memory
contents at 00 and 01.

9
Practice
Try changing both numbers and check result with hand calculation. The
example above can be applied to multiple bytes addition easily.

Summary
For multiple bytes addition, we must use ADCA, Add accumulator with
carry flag. If there is carry from lower significant byte.

10
Program 3 BCD Addition
BCD is the format that represents decimal number by using 4-bit binary
number. The 6802 addition instruction is for binary adding. If we use such
BCD to add it, the 6802 CPU has DAA instruction to provide automatic
adjustment of the binary addition result. The DAA must follow the ADDA or
ADCA instruction.

Decimal digit BCD


0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001

For example the clock display, 12:59:59 in BCD number. We may have three
bytes to store such display values.

Location Time BCD


00 12 0001 0010
01 59 0101 1001
02 59 0101 1001

11
Let us see the example of program that adds two BCD numbers.

NUM1 = 2894
NUM2 = 6547

The program will be similar to Program 2 Binary Addition. Only DAA


instruction will be inserted after ADDA and ADCA instructions.

0001 0200 .ORG 200H


0002 0200 ; ADD LOW BYTE
0003 0200 96 01 LDAA $01
0004 0202 9B 03 ADDA $03
0005 0204 19 DAA ; ← inserted after ADDA
0006 0205 97 01 STAA $01
0007 0207 ; ADD HIGH BYTE WITH CARRY
0008 0207 96 00 LDAA $00
0009 0209 99 02 ADCA $02
0010 020B 19 DAA ; ← inserted after ADCA
0011 020C 97 00 STAA $00
0012 020E
0013 020E 3F SWI
0014 020F
0015 020F .END
tasm: Number of errors = 0

Procedure
1. Enter the code from location 200 to 20D.

2. Enter two BCD numbers at NUM1 and NUM2 location.


NUM1 NUM2
00 (MS) 01(LS) 02(MS) 03(LS)
28 94 65 47

12
3. Add two numbers by hand calculation.

2894 + 6547 =?

4. Run the program with key PC then GO. Check the result with 6802
running at location of NUM1 (use key REG=$00).

Practice
Try changing both numbers and check result with hand calculation.
Remember, both numbers must be entered in BCD only 0-9.

Summary
DAA is used together with binary add instruction to adjust the result of
addition to be BCD number.

13
Program 4 Logical instructions
The 6802 performs logical operation with 8-bit data. Let us see the program
that produces the result of logical AND instruction.

We have two new instructions STAA $8000 and SWI.

The STAA $8000 will store the accumulator A to location $8000. This
memory address is used as the 8-bit output port. Each bit has the LED. We
can see the data result using LED ON/OFF.

At the end of program, we place instruction SWI, Software Interrupt. This


instruction will make CPU to return to monitor program.

We can now use key GO to jump from monitor program to our program
easily.

0001 0200 .ORG 200H


0002 0200
0003 0200 86 1E LDAA #$1E
0004 0202 84 89 ANDA #$89
0005 0204 B7 80 00 STAA $8000
0006 0207 3F SWI
0007 0208
0008 0208 .END
tasm: Number of errors = 0

Procedure
1. Enter the code from location 200 to 207.

2. Let make the result of logical AND with hand computing again.

14
1E AND 89 =____________________________________________

3. Check the result on GPIO1 LED with key PC, then GO.

4. Write down the result in binary and HEX.

We see that the result of logical AND will be '1' if both bits are '1'.

Now let us play with Logical OR.

0001 0200 .ORG 200H


0002 0200
0003 0200 86 9B LDAA #$9B
0004 0202 8A 40 ORAA #$40
0005 0204 B7 80 00 STAA $8000
0006 0207 3F SWI
0007 0208
0008 0208 .END
tasm: Number of errors = 0

Procedure
1. Enter the code from location 200 to 207.

2. Let make the result of logical OR with hand computing again.

9B OR 40 =____________________________________________

3. Check the result on GPIO1 LED with key PC, then GO.

4. Write down the result in binary and HEX.

15
We see that the result of logical OR will be '0' if both bits are '0'.

Another one is Exclusive OR, EOR.

0001 0200 .ORG 200H


0002 0200
0003 0200 86 00 LDAA #$00
0004 0202 88 80 EORA #$80
0005 0204 B7 80 00 STAA $8000
0006 0207 3F SWI
0007 0208
0008 0208 .END
tasm: Number of errors = 0

Procedure
1. Enter the code from location 200 to 207.

2. Let make the result of logical EOR with hand computing again.

00 EOR 80 =____________________________________________

3. Check the result on GPIO1 LED with key PC, then GO.

4. Write down the result in binary and HEX.

We see that the result of logical EOR will be '0' if both bits are the same.

16
Summary
The figure below shows the truth table for digital logic gates. Such logical
operation can be programmed by using the 6802 logical instructions as well.

More details on digital Gates can get from this web page.

Digital Electronics: Gates, Decoders, Multiplexers


http://www.chem.uoa.gr/applets/appletgates/appl_gates2.html

17
Program 5 Bit rotation
We will use GPIO1 LED to make LED running with bit rotation instruction.

0001 0000
0002 0000 GPIO1 .EQU 8000H
0003 0000
0004 0200 .ORG 200H
0005 0200
0006 0200 86 01 MAIN LDAA #1
0007 0202
0008 0202 B7 80 00 LOOP STAA GPIO1
0009 0205 8D 03 BSR DELAY
0010 0207 49 ROLA
0011 0208 20 F8 BRA LOOP
0012 020A
0013 020A
0014 020A CE 10 00 DELAY LDX #1000H
0015 020D 09 DELAY1 DEX
0016 020E 26 FD BNE DELAY1
0017 0210 39 RTS
0018 0211
0019 0211 .END
tasm: Number of errors = 0

At line 0002 the symbol GPIO1 is set to 8000H using .EQU directive.

Now we see that the main program is repeat loop forever using instruction
BRA LOOP, Branch Always to LOOP.

Register A is loaded with 1 at the initialization.

Loop body is at line 0008-0010. Register A contents will be stored to GPIO1


LED. Then make a delay by calling to subroutine DELAY.

18
The delay subroutine is just counting the IX register using DEX instruction
which will decrement the IX contents. BNE will jump back to DEX if IX is not
equal to zero by testing zero flag bit. If IX is zero, then return back to main
program.

The ROLA will rotate register A one bit to the left.

Then jump to the loop location to store the contents of register A to the
GPIO1 LED again.

Procedure

1. Enter the code from location 200 to 210.

2.. Check the code if correct then press PC then GO.

3. Did you see the LED running? Can you make the running speed lower?
How?

4. Can you change the program to make the running in right-hand direction?
How?

Summary
Bit rotation program demonstrates loop program by using Branch
instruction. The delay subroutine shows the method of slow down LED
running. The 6802 has 16-bit register, IX. We can use it with 16-bit load value
and use conditional branch instruction BNE that checks the ZERO flag.

The GPIO1 LED is very useful and simple to use for displaying many
programs running. We will see it in many programs there after.

19
Program 6 Tone generation
We will see another sample program that uses delay method to produce
TONE signal.

TONE signal is a single frequency with 50% duty cycle. For our kit we can
produce tone signal in square waveform.

We can test it by using the on-board speaker.

Let us see the circuit that drives the speaker.

LS1 is small speaker. The driver circuit is BC337 PNP transistor, Q1. The signal
that drives Q1 is SPEAKER signal.

Logic '0' at SPEAKER signal will make Q1 turn on, and logic '1' for turn off.

20
Since we need only one bit to drive the speaker, the signal is shared with
TXD signal and it is located at bit 7 of PORT1.

Bit 6 of PORT1 is very important signal. It is used by system to break the


program running. This bit must be logic '0' for normal running.

So to make SPEAKER bit clear to turn on Q1, we can write

LDAA #$3F ; 0011 1111


STAA PORT1

And to make this bit set to turn off Q1. (Bit 6 must be '0' for normal running)

LDAA #$BF ; 1011 1111


STAA PORT1

21
Let us see the program that produces TONE signal.

0001 0000 PORT1 .EQU 8002H


0002 0000
0003 0200 .ORG 200H
0004 0200
0005 0200 86 3F MAIN LDAA #$3F ; SPEAKER = 0
0006 0202 B7 80 02 STAA PORT1
0007 0205 8D 09 BSR DELAY
0008 0207 86 BF LDAA #$BF ; SPEAKER = 1
0009 0209 B7 80 02 STAA PORT1
0010 020C 8D 02 BSR DELAY
0011 020E
0012 020E 20 F0 BRA MAIN ; jump back to MAIN
0013 0210
0014 0210 CE 00 50 DELAY LDX #$50
0015 0213 09 DELAY1 DEX
0016 0214 26 FD BNE DELAY1
0017 0216 39 RTS
0018 0217
0019 0217 .END
tasm: Number of errors = 0

Again main program is forever loop running. The body of main program has
two portions. The first portion is to make SPEAKER signal CLEAR. And the
second portion is to turn off by making it SET.

The delay subroutine is the same as Program 5, but now the load value is
only 50H.

The signal waveform will be like this.

22
Procedure

1. Enter the code from location 200 to 216.

2.. Check the code if correct then press PC then GO.

3. Did you hear the tone signal?

4. Can you change the frequency of the tone signal? How?

Summary
A simple delay subroutine can be used to make the period of logic '1' and '0'
or square wave signal. To make higher frequency, the delay will be shorter
and lower frequency, longer delay.

23
Program 7 Reading key status
Reading key status will make the program get the logic status high or low.
We will test with REP key.

Let us see the hardware of REP key.

REP key is S19, when we press it, the logic at PA6 will be LOW, and will be
HIGH when it has been released.

U13 is 8-bit memory location. It was used as the input port, PORT0. The
location of PORT0 is $8001.

How can we see the logic in realtime?

24
Let us read it and write it to GPIO1 LED.

0001 0000
0002 0000 GPIO1 .EQU 8000H
0003 0000 PORT0 .EQU 8001H
0004 0000
0005 0200 .ORG 200H
0006 0200
0007 0200 B6 80 01 MAIN LDAA PORT0 ; load A with PORT0
0008 0203 B7 80 00 STAA GPIO1 ; store A to GPIO1
0009 0206 20 F8 BRA MAIN ; jump back to MAIN
0010 0208
0011 0208 .END
tasm: Number of errors = 0

The main program is forever loop reading PORT0 and write it to GPIO1 LED.

Procedure
1. Enter the code from location 200 to 207.

2.. Press PC then GO.

3. What is logic that shows on the GPIO1 LED?

4. Press key REP, what is happening at bit 6?

25
Another sample program that reads key status of REP key then make the
binary counting at GPIO1 LED when it was pressed.

0001 0000 GPIO1 .EQU 8000H


0002 0000 PORT0 .EQU 8001H
0003 0000
0004 0200 .ORG 200H
0005 0200
0006 0200 C6 00 MAIN LDAB #0 ; load B with 0
0007 0202
0008 0202 B6 80 01 KEY_PRESS LDAA PORT0
0009 0205 84 40 ANDA #%01000000 ; test bit 6
0010 0207 27 F9 BEQ KEY_PRESS ; jump if key pressed
0011 0209
0012 0209 8D 0F BSR DEBOUNCE ; call debounce
0013 020B
0014 020B B6 80 01 NOT_PRESS LDAA PORT0
0015 020E 84 40 ANDA #%01000000
0016 0210 26 F9 BNE NOT_PRESS ; jump if not pressed
0017 0212
0018 0212 8D 06 BSR DEBOUNCE ; call debounce
0019 0214
0020 0214 5C INCB ; increment B
0021 0215 F7 80 00 STAB GPIO1 ; store B to GPIO1
0022 0218
0023 0218 20 E8 BRA KEY_PRESS ; repeat again
0024 021A
0025 021A CE 00 64 DEBOUNCE LDX #100
0026 021D 09 delay1 DEX
0027 021E 26 FD BNE delay1
0028 0220 39 RTS
0029 0221
0030 0221 .END
tasm: Number of errors = 0

26
Procedure
1. Enter the code from location 200 to 220.

2.. Press PC the GO.

3. What is happening when we press key REP?

4. If we press REP key, still push it why counting is stop?

5. If we change the load value of IX register to smaller value or larger,


observe the result and discuss.

Summary
The CPU speed is rather high compare to the mechanical contact like key
switch. The bounce of contact will make unstable logic at the input bit.
Debounce with delay subroutine will help reading key status correctly.

27
Program 8 Interrupt with IRQ
Refer to the kit user manual, the table below shows the vector address for
interrupts.

We see that for IRQ, the location that put vector address is located at
FFF8 (MS) and FFF9 (LS)

Vector Description
MS LS
$FFF8 $FFF9 IRQ
$FFFA $FFFB Software Interrupt
$FFFC $FFFD NMI
$FFFE $FFFF RESET

We can check at the ROM location by pressing key ADDR then FFF8 and
FFF9. We found 00F8 in the zero page of RAM.

User now can test the interrupt by placing the code to be serviced at
location 00F8 in RAM.

IRQ is the maskable interrupt. To enable it, we must clear the I flag.

When IRQ pin is active LOW, the CPU registers will be saved to STACK
memory. The program counter will be loaded with vector that stored at
location FFF8 (MS byte) and FFF9 (LS byte). The kit puts RAM vector at
00F8.

Software interrupt is triggered by SWI instruction. We can use it for making


breaking point in the code. NMI is used for single step running.

28
Let us see a very simple code that responses IRQ signal.

0001 0000 GPIO1 .EQU $8000


0002 0000
0003 00F8 .ORG $00F8
0004 00F8
0005 00F8 BD 02 03 JSR SERV_IRQ
0006 00FB 3B RTI
0007 00FC
0008 0200 .ORG 200H
0009 0200
0010 0200 0E MAIN CLI
0011 0201 20 FE HERE BRA HERE
0012 0203
0013 0203 7C 00 00 SERV_IRQ INC 0
0014 0206 96 00 LDAA 0
0015 0208 B7 80 00 STAA GPIO1
0016 020B 39 RTS
0017 020C
0018 020C .END
tasm: Number of errors = 0

We see that at the location 00F8, we place the JSR SERV_IRQ followed with
RTI, return from interrupt. The interrupt service subroutine must be
returned with RTI instruction!

In the main code, CLI will clear I flag, to enable IRQ then repeat jumping at
HERE.

The service subroutine for IRQ is located at 203. It will increment the
contents of location 0 then write it to GPIO1 LED.

29
Procedure
1. Enter the code from location 00F8 to 00FB.

2.. Enter the code from location 200 to 20B.

3. Change SW1 position to IRQ

4. Press PC the GO.

5. Press key IRQ, what is happening?

6. If we change SW1 position to 10ms, what is happening?

Summary
IRQ is the hardware interrupt. It is the maskable interrupt. We enable it by
Clearing I flag. The real vector of IRQ is located in high address ROM. The
6802 kit provides RAM vector for user testing at location 00F8.

When we select SW1 to 10ms tick, the negative pulse that active low every
10ms will make the IRQ to be activated at 100Hz rate. We can see the
counting at GPIO1 LED at 100Hz rate.

30
Program 9 Using 10ms tick
We can use 10ms tick signal to trigger the IRQ interrupt pin. From 10ms or
100Hz interrupt, for example we can make a simple digital timer using 10ms
time base easily.

This program will show the counting of BCD number on the GPIO1 LED every
one second.

0001 0000 GPIO1 .EQU $8000


0002 0000
0003 0000 .ORG $00
0004 0000 SEC100 .BLOCK 1
0005 0001 SEC .BLOCK 1
0006 0002
0007 00F8 .ORG $00F8
0008 00F8
0009 00F8 BD 02 06 JSR SERV_IRQ
0010 00FB 3B RTI
0011 00FC
0012 0200 .ORG 200H
0013 0200
0014 0200 0E MAIN CLI
0015 0201 7F 00 01 CLR SEC
0016 0204
0017 0204 20 FE HERE BRA HERE
0018 0206
0019 0206 7C 00 00 SERV_IRQ INC SEC100
0020 0209 96 00 LDAA SEC100
0021 020B 81 64 CMPA #100
0022 020D 26 0D BNE SKIP
0023 020F 7F 00 00 CLR SEC100
0024 0212
0025 0212 96 01 LDAA SEC

31
0026 0214 8B 01 ADDA #1
0027 0216 19 DAA
0028 0217 97 01 STAA SEC
0029 0219 B7 80 00 STAA GPIO1
0030 021C
0031 021C 39 SKIP RTS
0032 021D
0033 021D .END
tasm: Number of errors = 0

We have two bytes for storing two variables i.e. , SEC100 and SEC.

The service routine for 10ms tick is now updating the SEC100 variable, check
it if it is equal to 100 ticks, or one second, it will update the SEC variable.

We use CMPA, compare instruction to check the variable SEC100. The value
in the source code is 100 ticks, the hex number of 100 is 64 (see line 21).

For SEC variable, we will use BCD number, so we must have DAA to follow
the ADDA instruction.

We will see the BCD counting every one second now. It was done by timer
hardware that produces 10ms tick. For modern microcontroller, the
hardware timer is commonly available in the microcontroller chip. No need
separate chip. The 89C2051 microcontroller gives such 10ms tick signal. It
can reprogram for another tick rate for advance experiment.

Procedure
1. Enter the code for IRQ from location 00F8 to 00FB.

2.. Enter the code for main program from location 200 to 20B.

3. Change SW1 position to IRQ

32
4. Press PC the GO, what is happening?

Summary
We see that the function that needs second timebase can be made easily
by using a given variable that incremented with multiple of 10ms tick.

33
Program 10 Digital timer
In Program 9, the counting is running with BCD number on the GPIO1 LED. In
this program , we will show how to use monitor subroutine to display digital
number in 7-segment display. The monitor listing is shown in the Kit User's
Manual.

Time base is 10ms using IRQ interrupt the same as program 9.

0001 0000 GPIO1 .EQU $8000


0002 0000 DATA_DISPLAY .EQU $C1C3
0003 0000 SCAN1 .EQU $C8DA
0004 0000
0005 0000 .ORG $00
0006 0000 SEC100 .BLOCK 1
0007 0001 SEC .BLOCK 1
0008 0002
0009 00F8 .ORG $00F8
0010 00F8
0011 00F8 BD 02 12 JSR SERV_IRQ
0012 00FB 3B RTI
0013 00FC
0014 0200 .ORG 200H
0015 0200
0016 0200 0E MAIN CLI
0017 0201 7F 00 8E CLR $8E
0018 0204 7F 00 8F CLR $8F
0019 0207 7F 00 90 CLR $90
0020 020A 7F 00 91 CLR $91
0021 020D
0022 020D BD C8 DA LOOP JSR SCAN1
0023 0210 20 FB BRA LOOP
0024 0212
0025 0212 36 SERV_IRQ PSHA

34
0026 0213
0027 0213 7C 00 00 INC SEC100
0028 0216 96 00 LDAA SEC100
0029 0218 81 64 CMPA #100
0030 021A 26 10 BNE SKIP
0031 021C 7F 00 00 CLR SEC100
0032 021F
0033 021F 96 01 LDAA SEC
0034 0221 8B 01 ADDA #1
0035 0223 19 DAA
0036 0224 97 01 STAA SEC
0037 0226 B7 80 00 STAA GPIO1
0038 0229
0039 0229 BD C1 C3 JSR DATA_DISPLAY
0040 022C
0041 022C
0042 022C 32 SKIP PULA
0043 022D
0044 022D 39 RTS
0045 022E
0046 022E .END
tasm: Number of errors = 0

We will use two subroutines, 1) DATA_DISPLAY and 2) SCAN1.

The 1st subroutine DATA_DISPLAY will convert the contents of accumulator


A to 7-segment pattern and write to display buffer at DATA field.

The 2nd subroutine SCAN1 will scan the display using 6-byte buffer memory.

The SEC variable that incremented every one second will be sent to the
DATA_DISPLAY subroutine.

Main program is repeat scanning the display with JSR SCAN1 instruction.

35
Relationship between 7-segment code and kit's display is shown below.

Name BUFFER+5 BUFFER+4 BUFFER+3 BUFFER+2 BUFFER+1 BUFFER

Location $91 $90 $8F $8E $8D $8C


Contents 00 00 00 00 BA AE
7-segment
Display
3 5
The subroutine DATA_DISPLAY will convert contents of Accumulator A and
put to location $8D for high nibble and $8C for low nibble, shown A=35.

_______ 35
Procedure
1. Enter the code for IRQ from location 00F8 to 00FB.

2.. Enter the code for main program from location 200 to 22D.

3. Change SW1 position to IRQ

4. Press PC the GO, what is happening?

5. If we want the display to be counting down, how to do that? (use 10's


complement for -1)

36
Summary
Digital timer can be made using 10ms timebase. The example program
shows how to use the monitor calling for displaying the contents of
accumulator using kit's display.

Note

1. 10s Complement Arithmetic


https://cs.senecac.on.ca/~david.ward/ics124/notes/decimal_complements.html

2. The segment and bit relationship is shown below.

8.
A
F G B

E C
DP
D

Byte format D7 D6 D5 D4 D3 D2 D1 D0
Segment D DP C B A F G E

37
Decimal, 4-bit Binary and Hex

Decimal 4-bit Binary Hex


0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F

38
Hex and 7-segment pattern code

Hex Code Display


0 BD 0
1 30 1
2 9B 2
3 BA 3
4 36 4
5 AE 5
6 AF 6
7 38 7
8 BF 8
9 BE 9
A 3F A
B A7 B
C 8D C
D B3 D
E 8F E
F 0F F

39
6802 Programming registers

40
6802 Microprocessor Kit
The 6802 kit is a workable digital computer. We can enter the 6802
instructions using machine code to the memory and test it directly.

41
Memory Allocation
The 6802 has 64kB, or 65536 bytes memory space. Our kit allocates space
for RAM, Input/Output and ROM as shown below.

00
80 PAGE ZERO
FF System RAM
0100

USER RAM 32kB RAM

USER STACK
7F00
system STACK
7FFF
8000
Input/Output 16kB I/O ports
Port
BFFF
C000

MONITOR 16kB ROM


ROM

FFFF
42
Page Zero is RAM having address from 00 to FF. The monitor program uses
location from 80 to FF for system operation. We can use location from 00
to 7F to be variables for our code.

We can access page zero memory with only 8-bit address. This location can
be called DIRECT address

User RAM is located from 100 to 7FFF. Here we can put our code to this
spaces. At the top location of this space is allocated for user STACK and
system STACK.

Input/Output Port is located from 8000 to BFFF. The example of output


port is the GPIO1 debugging LED. It is located at address 8000.

Monitor ROM is located from C000 to FFFF. This memory is ROM. We put
the monitor program in ROM. Our kit use EPROM, 27C256 to store the
monitor program. The monitor program will not loss if we turn power off.
After power on reset, the 6802 will run this program. The monitor program
will scan display and keypad providing hex code entering and test code
running. Our program will put to user RAM.

43
Note

44

Potrebbero piacerti anche