• Aucun résultat trouvé

Memory Maps

Dans le document APPLICATIONS GUIDE (Page 33-36)

2-12

Since there are several thousand memory locations in the MCU system, it is important to have a convenient way to track locations. A memory map is a pictorial representation of the total MCU memory space. Figure 2-4 is a typical memory map showing a subset of the memory resources in the SEE INSET ~ Port A Data Direction Register

Port B Data DirectionRegister Port C Data Direction Register

Unused Input Capture Register high) Input Capture Register (low) Output Compare Register (high) Output Compare Register (low) Timer Count Register high)

Timer Count Register (low) RESET Vector high byte) RESET Vector low byte)

$00

Port A Data Direction Register

I

~ 'DDRA7' DDRAS' DDRAS' DDRA41 DDRA3' DDRA21 DDRA1

I

DDRM'

Figure 2-4. Typical Memory Map

M68HC05 MICROCONTROLLER APPLICATIONS GUIDE MOTOROLA

MC68HC705C8. Some memory areas (reserved for Motorola use) were pur-posely left out of this figure to make it easier to understand. The complete version of this memory map can be found in the Figure 3-5.

The four-digit hexadecimal values along the left edge of Figure 2-4 are ad-dresses beginning with $0000 at the top and increasing to $1 FFF at the bot-tom. $0000 corresponds to the first memory location selected (when the CPU drives all address lines of the internal address bus to logic zero). $1 FFF corresponds to the last memory location selected (when the CPU drives all 13 address lines of the internal address bus to logic one). The labels within the vertical rectangle identify what kind of memory (RAM, PROM, liD reg-isters, etc.) resides in a particular area of memory.

Some areas, such as liD registers, need to be shown in more detail because it is important to know the names of each individual location. The vertical rectangle can be interpreted as a row of 8192 pigeon holes (memory loca-tions). Each of these 8192 memory locations contains eight bits of data as shown in the inset in Figure 2-4.

The first 256 memory locations ($OOOO-$OOFF) can be accessed with the direct addressing mode of many CPU instructions. In this addressing mode, the CPU assumes that the upper two hexadecimal digits of address are always zeros; thus, only the two low-order digits of the address need to be explicitly given in the instruction. All on-chip I/O registers and 176 bytes of RAM are located in the $OOOO-$OOFF area of memory. In the memory map (Figure 2-4), the expansion of the liD area of memory identifies each register location with the two low-order digits of its address rather than the full four-digit address. For example, the two-digit hexadecimal value $00 appears to the right of the port A data register, which is actually located at address $0000 in the memory map.

Now that we have some background knowledge of computer memory, we can continue with our discussion of the CPU.

2.4 TIMING

A high-frequency clock source (typically derived from a crystal connected to the MCU) is used to control the sequencing of CPU instructions. Typical MCUs divide the basic crystal frequency by two or more to arrive at a bus-rate clock.

Each memory read or write takes one bus-rate clock cycle. In the case of the MC68HC705C8 MCU, a 4-MHz (maximum) crystal oscillator clock is divided by two to arrive at a 2-MHz (maximum) internal processor clock. Each substep

MOTOROLA M68HC05 MICROCONTROLLER APPLICATIONS GUIDE 2-13

of an instruction takes one cycle of this internal processor dock (500 ns).

Most instructions take two to five of these substeps; thus, the CPU is capable of executing about 500,000 instructions every second.

2.5 PROGRAMMING

At this point, we will write a short program in mnemonic form, translate it into machine code, and discuss how the CPU would execute the program.

This exercise will provide insight into the internal operation of the CPU and computers in general. The instruction set explanations and the process of writing programs will be more understandable with this background.

Our program will read the state of a switch connected to an input pin. When the switch is closed, the program will cause an LED connected to an output pin to light for about one second and then go out. The LED will not light again until the switch has been released and closed again. The length of time the switch is held closed will not affect the length of time the LED is lighted.

Although this program is very simple, it demonstrates the most common elements of any MCU application program. First, it demonstrates how a program can sense input signals such as switch closures. Second, this is an example of a program controlling an output signal. Third, the LED on-time of about one second demonstrates one way a program can be used to meas-ure real time. Because the algorithm is sufficiently complicated, it cannot be accomplished in a trivial manner with discrete components (at minimum, a one-shot IC with external timing components would be required). This ex-ample demonstrates that an MCU and a user-defined program (software) can replace complex circuits.

2.5.1 Flowchart

2-14

Figure 2-5 is a flowchart of the example program. Flowcharts are often used as a planning tool for writing software programs because they show the function and flow of the program under development. The importance of notes, comments, and documentation for software cannot be overempha-sized. Just as you would not consider a circuit-board design complete until there is a schematic diagram, parts list, and assembly drawing, you should not consider a program complete until there is a commented listing and a comprehensive explanation of the program such as a flowchart.

M68HC05 MICROCONTROLLER APPLICATIONS GUIDE MOTOROLA

FLOWCHART

SET INITIAL CONDITIONS:

PORT C = ALL OUTPUTS DATA PATTERN 11100000 TO PORT C

Figure 2-5. Example Flowchart

Dans le document APPLICATIONS GUIDE (Page 33-36)