Top Banner
Programming Book for 6802 Microprocessor Kit Wichit Sirichote Rev 1.2 Nov 6, 2015 1
44

Programming Book for 6802 Microprocessor Kit

Jan 07, 2022

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Programming Book for 6802 Microprocessor Kit

Programming Book for 6802 Microprocessor Kit

Wichit Sirichote

Rev 1.2 Nov 6, 2015

1

Page 2: Programming Book for 6802 Microprocessor Kit

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

Page 3: Programming Book for 6802 Microprocessor Kit

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, HexHex, 7-segment pattern6802 Programming Registers6802 Microprocesssor kitMemory allocation

3

Page 4: Programming Book for 6802 Microprocessor Kit

Program 1 Load and Store instructions

How to store 8-bit data to memory?

Line ADDR hex code Instruction comment0001 0200 .ORG 200H0002 0200 0003 0200 86 9F LDAA #$9F ; load Accumulator A with 9F0004 0202 97 00 STAA $00 ; store it to location 000005 0204 0006 0204 .ENDtasm: Number of errors = 0This 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 suchdata is called Immediate addressing mode.

The 2nd instruction is STAA $00. The Accumulator contents will be stored toMEMORY 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

Page 5: Programming Book for 6802 Microprocessor Kit

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.

_______ 006. 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 200H0002 0200 0003 0200 CE 12 34 LDX #$12340004 0203 DF 00 STX $000005 0205 0006 0205 .ENDtasm: Number of errors = 0

5

Page 6: Programming Book for 6802 Microprocessor Kit

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 200H0002 0200 0003 0200 CE 12 34 LDX #$12340004 0203 FF 01 00 STX $0100

6

Page 7: Programming Book for 6802 Microprocessor Kit

0005 0206 0006 0206 .ENDtasm: Number of errors = 0

We see that STX $0100 has three byte hex code FF, 01 and 00. The 6802 callsEXTENDED 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

Page 8: Programming Book for 6802 Microprocessor Kit

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 = 12EDNUM2 = 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 200H0002 0200 ; ADD LOW BYTE0003 0200 96 01 LDAA $010004 0202 9B 03 ADDA $030005 0204 97 01 STAA $010006 0206 ; ADD HIGH BYTE WITH CARRY0007 0206 96 00 LDAA $000008 0208 99 02 ADCA $02

8

Page 9: Programming Book for 6802 Microprocessor Kit

0009 020A 97 00 STAA $000010 020C 0011 020C 3F SWI0012 020D 0013 020D .ENDtasm: 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

Page 10: Programming Book for 6802 Microprocessor Kit

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

Page 11: Programming Book for 6802 Microprocessor Kit

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

Page 12: Programming Book for 6802 Microprocessor Kit

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

NUM1 = 2894NUM2 = 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 200H0002 0200 ; ADD LOW BYTE0003 0200 96 01 LDAA $010004 0202 9B 03 ADDA $030005 0204 19 DAA ; inserted after ADDA←0006 0205 97 01 STAA $010007 0207 ; ADD HIGH BYTE WITH CARRY0008 0207 96 00 LDAA $000009 0209 99 02 ADCA $020010 020B 19 DAA ; inserted after ADCA←0011 020C 97 00 STAA $000012 020E 0013 020E 3F SWI0014 020F 0015 020F .ENDtasm: 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

Page 13: Programming Book for 6802 Microprocessor Kit

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

Page 14: Programming Book for 6802 Microprocessor Kit

Program 4 Logical instructions

The 6802 performs logical operation with 8-bit data. Let us see the programthat 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 200H0002 0200 0003 0200 86 1E LDAA #$1E0004 0202 84 89 ANDA #$890005 0204 B7 80 00 STAA $80000006 0207 3F SWI0007 0208 0008 0208 .ENDtasm: 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

Page 15: Programming Book for 6802 Microprocessor Kit

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 200H0002 0200 0003 0200 86 9B LDAA #$9B0004 0202 8A 40 ORAA #$400005 0204 B7 80 00 STAA $80000006 0207 3F SWI0007 0208 0008 0208 .ENDtasm: 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

Page 16: Programming Book for 6802 Microprocessor Kit

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 200H0002 0200 0003 0200 86 00 LDAA #$000004 0202 88 80 EORA #$800005 0204 B7 80 00 STAA $80000006 0207 3F SWI0007 0208 0008 0208 .ENDtasm: 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

Page 17: Programming Book for 6802 Microprocessor Kit

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, Multiplexershttp://www.chem.uoa.gr/applets/appletgates/appl_gates2.html

17

Page 18: Programming Book for 6802 Microprocessor Kit

Program 5 Bit rotation

We will use GPIO1 LED to make LED running with bit rotation instruction.

0001 0000 0002 0000 GPIO1 .EQU 8000H0003 0000 0004 0200 .ORG 200H0005 0200 0006 0200 86 01 MAIN LDAA #10007 0202 0008 0202 B7 80 00 LOOP STAA GPIO10009 0205 8D 03 BSR DELAY0010 0207 49 ROLA0011 0208 20 F8 BRA LOOP0012 020A 0013 020A 0014 020A CE 10 00 DELAY LDX #1000H0015 020D 09 DELAY1 DEX0016 020E 26 FD BNE DELAY10017 0210 39 RTS0018 0211 0019 0211 .ENDtasm: 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

Page 19: Programming Book for 6802 Microprocessor Kit

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 notequal 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

Page 20: Programming Book for 6802 Microprocessor Kit

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 signalthat drives Q1 is SPEAKER signal.

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

20

Page 21: Programming Book for 6802 Microprocessor Kit

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 1111STAA PORT1

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

LDAA #$BF ; 1011 1111STAA PORT1

21

Page 22: Programming Book for 6802 Microprocessor Kit

Let us see the program that produces TONE signal.

0001 0000 PORT1 .EQU 8002H0002 0000 0003 0200 .ORG 200H0004 0200 0005 0200 86 3F MAIN LDAA #$3F ; SPEAKER = 00006 0202 B7 80 02 STAA PORT10007 0205 8D 09 BSR DELAY0008 0207 86 BF LDAA #$BF ; SPEAKER = 10009 0209 B7 80 02 STAA PORT10010 020C 8D 02 BSR DELAY 0011 020E 0012 020E 20 F0 BRA MAIN ; jump back to MAIN0013 0210 0014 0210 CE 00 50 DELAY LDX #$500015 0213 09 DELAY1 DEX0016 0214 26 FD BNE DELAY10017 0216 39 RTS0018 0217 0019 0217 .ENDtasm: 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

Page 23: Programming Book for 6802 Microprocessor Kit

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

Page 24: Programming Book for 6802 Microprocessor Kit

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

Page 25: Programming Book for 6802 Microprocessor Kit

Let us read it and write it to GPIO1 LED.

0001 0000 0002 0000 GPIO1 .EQU 8000H0003 0000 PORT0 .EQU 8001H0004 0000 0005 0200 .ORG 200H0006 0200 0007 0200 B6 80 01 MAIN LDAA PORT0 ; load A with PORT00008 0203 B7 80 00 STAA GPIO1 ; store A to GPIO10009 0206 20 F8 BRA MAIN ; jump back to MAIN0010 0208 0011 0208 .ENDtasm: 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

Page 26: Programming Book for 6802 Microprocessor Kit

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 8000H0002 0000 PORT0 .EQU 8001H0003 0000 0004 0200 .ORG 200H0005 0200 0006 0200 C6 00 MAIN LDAB #0 ; load B with 00007 0202 0008 0202 B6 80 01 KEY_PRESS LDAA PORT00009 0205 84 40 ANDA #%01000000 ; test bit 60010 0207 27 F9 BEQ KEY_PRESS ; jump if key pressed0011 0209 0012 0209 8D 0F BSR DEBOUNCE ; call debounce0013 020B 0014 020B B6 80 01 NOT_PRESS LDAA PORT00015 020E 84 40 ANDA #%010000000016 0210 26 F9 BNE NOT_PRESS ; jump if not pressed0017 0212 0018 0212 8D 06 BSR DEBOUNCE ; call debounce0019 0214 0020 0214 5C INCB ; increment B0021 0215 F7 80 00 STAB GPIO1 ; store B to GPIO10022 0218 0023 0218 20 E8 BRA KEY_PRESS ; repeat again0024 021A 0025 021A CE 00 64 DEBOUNCE LDX #1000026 021D 09 delay1 DEX0027 021E 26 FD BNE delay10028 0220 39 RTS0029 0221 0030 0221 .ENDtasm: Number of errors = 0

26

Page 27: Programming Book for 6802 Microprocessor Kit

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

Page 28: Programming Book for 6802 Microprocessor Kit

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

Page 29: Programming Book for 6802 Microprocessor Kit

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

0001 0000 GPIO1 .EQU $80000002 0000 0003 00F8 .ORG $00F80004 00F8 0005 00F8 BD 02 03 JSR SERV_IRQ0006 00FB 3B RTI0007 00FC 0008 0200 .ORG 200H0009 0200 0010 0200 0E MAIN CLI0011 0201 20 FE HERE BRA HERE0012 0203 0013 0203 7C 00 00 SERV_IRQ INC 00014 0206 96 00 LDAA 00015 0208 B7 80 00 STAA GPIO10016 020B 39 RTS0017 020C 0018 020C .ENDtasm: Number of errors = 0

We see that at the location 00F8, we place the JSR SERV_IRQ followed withRTI, 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

Page 30: Programming Book for 6802 Microprocessor Kit

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

Page 31: Programming Book for 6802 Microprocessor Kit

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 everyone second.

0001 0000 GPIO1 .EQU $80000002 0000 0003 0000 .ORG $000004 0000 SEC100 .BLOCK 10005 0001 SEC .BLOCK 10006 0002 0007 00F8 .ORG $00F80008 00F8 0009 00F8 BD 02 06 JSR SERV_IRQ0010 00FB 3B RTI0011 00FC 0012 0200 .ORG 200H0013 0200 0014 0200 0E MAIN CLI0015 0201 7F 00 01 CLR SEC0016 0204 0017 0204 20 FE HERE BRA HERE0018 0206 0019 0206 7C 00 00 SERV_IRQ INC SEC1000020 0209 96 00 LDAA SEC1000021 020B 81 64 CMPA #1000022 020D 26 0D BNE SKIP0023 020F 7F 00 00 CLR SEC1000024 0212 0025 0212 96 01 LDAA SEC

31

Page 32: Programming Book for 6802 Microprocessor Kit

0026 0214 8B 01 ADDA #10027 0216 19 DAA0028 0217 97 01 STAA SEC0029 0219 B7 80 00 STAA GPIO10030 021C 0031 021C 39 SKIP RTS0032 021D 0033 021D .ENDtasm: 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, checkit 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

Page 33: Programming Book for 6802 Microprocessor Kit

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

Page 34: Programming Book for 6802 Microprocessor Kit

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 digitalnumber 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 $80000002 0000 DATA_DISPLAY .EQU $C1C30003 0000 SCAN1 .EQU $C8DA0004 0000 0005 0000 .ORG $000006 0000 SEC100 .BLOCK 10007 0001 SEC .BLOCK 10008 0002 0009 00F8 .ORG $00F80010 00F8 0011 00F8 BD 02 12 JSR SERV_IRQ0012 00FB 3B RTI0013 00FC 0014 0200 .ORG 200H0015 0200 0016 0200 0E MAIN CLI0017 0201 7F 00 8E CLR $8E0018 0204 7F 00 8F CLR $8F0019 0207 7F 00 90 CLR $900020 020A 7F 00 91 CLR $910021 020D 0022 020D BD C8 DA LOOP JSR SCAN10023 0210 20 FB BRA LOOP 0024 0212 0025 0212 36 SERV_IRQ PSHA

34

Page 35: Programming Book for 6802 Microprocessor Kit

0026 0213 0027 0213 7C 00 00 INC SEC1000028 0216 96 00 LDAA SEC1000029 0218 81 64 CMPA #1000030 021A 26 10 BNE SKIP0031 021C 7F 00 00 CLR SEC1000032 021F 0033 021F 96 01 LDAA SEC0034 0221 8B 01 ADDA #10035 0223 19 DAA0036 0224 97 01 STAA SEC0037 0226 B7 80 00 STAA GPIO10038 0229 0039 0229 BD C1 C3 JSR DATA_DISPLAY0040 022C 0041 022C 0042 022C 32 SKIP PULA0043 022D 0044 022D 39 RTS0045 022E 0046 022E .ENDtasm: 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

Page 36: Programming Book for 6802 Microprocessor Kit

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-segmentDisplay 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.

_______ 35Procedure

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

Page 37: Programming Book for 6802 Microprocessor Kit

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 Arithmetichttps://cs.senecac.on.ca/~david.ward/ics124/notes/decimal_complements.html

2. The segment and bit relationship is shown below.

8.Byte format D7 D6 D5 D4 D3 D2 D1 D0Segment D DP C B A F G E

37

A

B

C

D

E

F G

DP

Page 38: Programming Book for 6802 Microprocessor Kit

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

Page 39: Programming Book for 6802 Microprocessor Kit

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

Page 40: Programming Book for 6802 Microprocessor Kit

6802 Programming registers

40

Page 41: Programming Book for 6802 Microprocessor Kit

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

41

Page 42: Programming Book for 6802 Microprocessor Kit

Memory Allocation

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

42

FFFF

00

FF0100

7FFF

7F00 USER STACK

80 PAGE ZEROSystem RAM

system STACK

USER RAM 32kB RAM

8000

BFFFC000

Input/OutputPort

MONITORROM

16kB ROM

16kB I/O ports

Page 43: Programming Book for 6802 Microprocessor Kit

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 canbe 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

Page 44: Programming Book for 6802 Microprocessor Kit

Note

44