Notes for January 19, 2001
68HC12 Address Space
- 68HC12 has 16 address lines
- 68HC12 can address 216 distinct locations
- For 68HC12, each location holds one byte (eight bits)
- 68HC12 can address 216 bytes
- 216 = 65536
- 216 = 26 x 210 = 64 x 1024 = 64 KB
- 1 K = 210 = 1024
- 68HC12 can address 64 KB
68HC12 Address Space
- Lowest address:
- Highest address:
MEMORY TYPES
RAM: |
Random Access Memory (can read and write) |
ROM: |
Read Only Memory (programmed at factory) |
PROM: |
Programmable Read Only Memory |
|
(Program once at site) |
EPROM: |
Erasable Programmable Read Only Memory |
|
(Program at site, can erase using UV light and reprogram) |
EEPROM: |
Electrically Erasable Programmable Read Only Memory |
|
(Program and erase using voltage rather than UV light) |
68HC12 has: |
1 K RAM |
|
768 bytes EEPROM |
|
Can erase and reprogram any byte using normal 5V power
supply |
|
32 KB Flash EEPROM |
|
Can erase using external 12V power supply |
68HC12 Address Space
68HC12 ALU
- Arithmetic Logic Unit (ALU) is where instructions are executed.
- Examples of instructions are arithmetic (add, subtract), logical
(bitwise AND, bitwise OR), and comparison.
- 68HC12 has two 8-bit registers for executing instructions. These
registers are called A and B.
- For example, the HC12 can add the 8-bit number stored in B
to the eight-bit number stored in A using the instruction ABA
(add B to A):
When the control unit sees the sixteen-bit number 0x1806, it tells
the ALU to add B to A, and store the result into A.
68HC12 Programming Model
- A Programming Model details the registers in the ALU and control unit
which a programmer needs to know about to program a microprocessor.
- Registers A and B are part of the programming model.
Some instructions treat A and B as a sixteen-bit register
called D for such things as adding two sixteen-bit numbers. Note that D
is the same as A and B.
- The HC12 can work with 8-bit numbers (bytes) and 16-bit numbers (words).
- The size of the number the HC12 uses depends on the instruction. For example,
the instruction LDAA (Load Accumulator A) puts a byte into A, and LDD
(Load Double Accumulator) puts a word into D.
68HC12 Programming Model
- The 68HC12 has a sixteen-bit register which tells the control unit
which instruction to execute. This is called the Program Counter
(PC). The number in PC is the address of the next
instruction the HC12 will execute.
- The 69HC12 has an eight-bit register which tells the HC12 about
the state of the ALU. This register is called the Condition Code
Register (CCR). For example, one bit (C) tells the HC12 whether the
last instruction executed generated a carry. Another bit (Z) tells the
HC12 whether the result last instruction was zero. The N bit tells
whether the last instruction executed generated a negative result.
- There are three other 16-bit registers - X, Y, SP - which we
will discuss later.
Some HC12 Instructions Needed for Lab 1
LDAA address |
Put the byte contained in memory at address into
A |
STAA address |
Put the byte contained in A into memory at
address |
CLRA |
Clear A (0 -> A) |
INCA |
Add 1 to A ((A) + 1 -> A) |
ABA |
Add B to A, store the result in A |
ASRA |
Shift A right by one bit (keep the MSB the same) |
|
This divides a signed number by 2 |
LSRA |
Shift A right by one bit (put 0 into MSB) |
|
This divides an unsigned number by 2 |
NEGA |
Negate A (-(A) -> A) |
TAB |
Transfer A to B ((A) -> B) |
SWI |
Software Interrupt (Used to end all our HC12
programs) |
A Simple HC12 Program
A Simple Assembly Language Program.
Assembling an Assembly Language Program
- A computer program called an assembler can convert an assembly
language program into machine code.
- The assembler we use in class is from a company called Cosmic.
- To assemble the above program using the Cosmic assembler, we must
first create a file called test.lkf which tells the assembler
where to put things in memory. Our test.lkf file would look like
this:
# Link file for test program
+seg .text -b 0x0800 -n .text # program start address
+seg .data -b 0x0800 -n .data # data start address
test.o # application program
- To assemble the program, use the following commands:
ca6812 -a -l -xx -pl test.s
clnk -o test.h12 -m test.map test.lkf
chex -o test.s19 test.h12
- This will produce a file called test.s19 which we can load
into the 68HC12.
Bill Rison
2001-01-18