Order this document by EB285/D Motorola Semiconductor Engineering Bulletin EB285 C Macro Definitions for the MC68HC(7)11E20 By John Bodnar

Similar documents
EB287. Motorola Semiconductor Engineering Bulletin. C Macro Definitions for the MC68HC(7)11E9/E8/E1/E0. Freescale Semiconductor, I.

EB289. Motorola Semiconductor Engineering Bulletin. C Macro Definitions for the MC68HC11F1 By John Bodnar Austin, Texas. Freescale Semiconductor, I

Freescale Semiconductor, I

Freescale Semiconductor, I. How to Write to the 64-Cycle Time-Protected Registers on M68HC11 Development Tools

Freescale Semiconductor, I. Example Using the Queued Serial Peripheral Interface on Modular MCUs

Freescale Semiconductor, I. How to Use the Table Lookup and Interpolate Instruction on the CPU32

Freescale Semiconductor, I

EB301. Motorola Semiconductor Engineering Bulletin. Programming EEPROM on the MC68HC811E2 during Program Execution. Freescale Semiconductor, I

Advance Information 24-BIT GENERAL PURPOSE DIGITAL SIGNAL PROCESSOR

However, if an event comes in when the new value is being written to the pulse accumulator counter, that event could be missed. One solution to this p

DSP5630x FSRAM Module Interfacing

SRAM SRAM SRAM SCLK khz

Technical support for MCUez development tools is available through your regional. For More Information On This Product, Go to:

SRAM SRAM SRAM. Data Bus EXTAL ESSI KHz MHz. In Headphone CS MHz. Figure 1 DSP56302EVM Functional Block Diagram

2005: 0.5 PQ-MDS-PCIEXP

Suite56 Command Converter Server User s Guide

EB180. Motorola Semiconductor Engineering Bulletin. Differences between the MC68HC705B16 and the MC68HC705B16N. Freescale Semiconductor, I

EB193. Motorola Semiconductor Engineering Bulletin. Replacing 68HC11A Series MCUs with 68HC11E Series MCUs. Freescale Semiconductor, I.

Mask Set Errata. Introduction. MCU Device Mask Set Identification. MCU Device Date Codes. MCU Device Part Number Prefixes MSE08AZ32_0J66D 12/2002

Upgrade the Solution With No Changes 2 Upgrade the Solution With No Changes If a Codebase does not contain updates to its properties, it is possible t

Engineering Bulletin. Introduction and Background. Definition of Early TOF EB389/D 11/2001

15 x 15 mm PBGA Daisy-Chain Application Report

Easy development software from the company that knows MCU hardware best

Freescale Semiconductor, I

Electrode Graphing Tool IIC Driver Errata Microcontroller Division

Performance Factors nc. 2 Performance Factors The following sections discuss performance factors. 2.1 MPX vs. 60x Bus Mode One of the main factors tha

PCB Layout Guidelines for the MC1321x

AN1818. Motorola Semiconductor Application Note

XGATE Library: Using the Freescale XGATE Software Library Steve McAslan MCD Applications, East Kilbride

Using the PowerQUICC II Auto-Load Feature

EB380. Migrating from the MC68HC811E2 to the MC68HC711E9. Freescale Semiconductor, I. Introduction. Migrating to the MC68HC711E9

Freescale Semiconductor, I

Figure 1. Power Barrel Connector Requirements

ColdFire Convert 1.0 Users Manual by: Ernest Holloway

1.3 General Parameters

EB366. In-Circuit Programming of FLASH Memory Using the Monitor Mode for the MC68HC908GP32. Introduction

etpu General Function Set (Set 1) David Paterson MCD Applications Engineer

MTIM Driver for the MC9S08GW64

MPC8349E-mITX-GP Board Errata

PQ-MDS-QOC3 Module. HW Getting Started Guide. Contents. About This Document. Required Reading. Definitions, Acronyms, and Abbreviations

AND8386/D. Bootloading BelaSigna 250 Using the I 2 C Interface APPLICATION NOTE

EchoRemote Evaluation Software for Windows

USB Bootloader GUI User s Guide

Mechanical Differences Between the 196-pin MAP-BGA and 196-pin PBGA Packages

Updating the Firmware on USB SPI Boards (KITUSBSPIEVME, KITUSBSPIDGLEVME)

MC33696MODxxx Kit. 1 Overview. Freescale Semiconductor Quick Start Guide. Document Number: MC33696MODUG Rev. 0, 05/2007

PAS08QF80 User s Manual

Pad Configuration and GPIO Driver for MPC5500 Martin Kaspar, EMEAGTM, Roznov Daniel McKenna, MSG Applications, East Kilbride

Freescale Semiconductor, I

PAS08QF5264 User s Manual

Using IIC to Read ADC Values on MC9S08QG8

56F8300 BLDC Motor Control Application

SEMICONDUCTOR AN267 MATCHING NETWORK DESIGNS WITH COMPUTER SOLUTIONS MOTOROLA APPLICATION NOTE INTRODUCTION NETWORK SOLUTIONS COMPONENT CONSIDERATIONS

AN-HK-33. Motorola Semiconductor Application Note. In-Circuit Programming of FLASH Memory in the MC68HC908JL3. PART 1 Introduction

Using the Serial Peripheral Interface (SPI) Module on 68HC(9)08 Microcontrollers

Mask Set Errata. Introduction. MCU Device Mask Set Identification. MCU Device Date Codes. MCU Device Part Number Prefixes

IIC Driver for the MC9S08GW64

XGATE Library: ATD Average Calculating a rolling average from ATD results

Using the Project Board LCD Display at 3.3 volts

Migrating from the MPC852T to the MPC875

Device Errata MPC860ADS Application Development System Board Versions ENG, PILOT, REV A

CodeWarrior Development Studio

AN2093. Motorola Semiconductor Application Note. Creating Efficient C Code for the MC68HC08. Freescale Semiconductor, I.

Using the Multi-Axis g-select Evaluation Boards

Component Development Environment Installation Guide

PQ-MDS-PIB. HW Getting Started Guide 12,13. January 2006: Rev Check kit contents

Programming and Evaluation Tool for Serial EEPROMs

PDB Driver for the MC9S08GW64

56F805. BLDC Motor Control Application with Quadrature Encoder using Processor Expert TM Targeting Document. 56F bit Digital Signal Controllers

Interfacing HCS12 Microcontrollers to the MFR4200 FlexRay Controller

AND9032. How to Read Temperature Through I 2 C Bus for NCT75-based Thermostat APPLICATION NOTE

Managing Failure Detections and Using Required Components to Meet ISO7637 pulse 1 on MC33903/4/5 Common Mode Choke Implementation

Symphony SoundBite: Quick Start with Symphony Studio. Installation and Configuration

M68HC705E24PGMR PROGRAMMER USER'S MANUAL

MC56F825x/MC56F824x (2M53V) Chip Errata

SGTL5000 I 2 S DSP Mode

Controller Continuum. for Microcontrollers V6.3. Quick Start

M68HC705E6PGMR PROGRAMMER USER'S MANUAL

MCF5445x Configuration and Boot Options Michael Norman Microcontroller Division

Interfacing MPC5xx Microcontrollers to the MFR4310 FlexRay Controller David Paterson MCD Applications, East Kilbride

Installing Service Pack Updater Archive for CodeWarrior Tools (Windows and Linux) Quick Start

Using the Asynchronous DMA features of the Kinetis L Series

Freescale BeeStack Documentation Overview Document Number: BSDO Rev /2008

for ColdFire Architectures V7.2 Quick Start

HC912D60A / HC912Dx128A 0.5µ Microcontrollers Mask sets 2K38K, 1L02H/2L02H/3L02H & K91D, 0L05H/1L05H/2L05H

Freescale Semiconductor, I

MC74F620 MC74F623 OCTAL BUS TRANSCEIVER WITH 3-STATE OUTPUTS (INVERTING AND NONINVERTING)

Utilizing Extra FC Credits for PCI Express Inbound Posted Memory Write Transactions in PowerQUICC III Devices

MPR121 Proximity Detection

AND8335/D. Design Examples of Module-to-Module Dual Supply Voltage Logic Translators. SIM Cards SDIO Cards Display Modules HDMI 1-Wire Sensor Bus

NOVPEK NetLeap User Guide

MPC8260 IDMA Timing Diagrams

for Freescale MPC55xx/MPC56xx Microcontrollers V2.10 Quick Start

MPR083 Proximity Evaluation Kit User s Guide

Using an I 2 C EEPROM During MSC8157 Initialization

Power Cycling Algorithm using the MMA73x0L 3-Axis Linear Accelerometer

Introduction to LIN 2.0 Connectivity Using Volcano LTP

Clock Mode Selection for MSC8122 Mask Set K98M

56F805. Digital Power Factor Correction using Processor Expert TM Targeting Document. 56F bit Digital Signal Controllers. freescale.

Integrating FreeMASTER-Time Debugging Tool with CodeWarrior for Microcontrollers v10.x Project

Transcription:

nc. Order this document by /D Motorola Semiconductor C Macro Definitions for the MC68HC(7)11E20 By John Bodnar Austin, Texas Introduction Conventions With more microcontroller users moving to high level languages like C, macro definition files like the one outlined in this document can speed software development efforts. The file reproduced in the following pages is available on the Freeware Data System. Download and unzip the hc11e20h.zip file from the MCU11 directory. The hc11e20h.zip file includes an ASCII text copy of this documentation and the actual hc11e20.h text file. The hc11e20.h file, and others like it, use Motorola's designated register and bit names for each device described. Any user already familiar with MC68HC11 assembly language and architecture (a requirement even for those who think they will only program in C), will readily be able to make use of this file. The contents of the actual file will be designated with the Courier typeface while commentary will appear in the Helvetica typeface used in this paragraph. Motorola, Inc., 1998

nc. Thus these lines appear in the hc11e20.h file: /* MOTOROLA INC. * * FILENAME: hc11e20.h * * DESCRIPTION: Register and bit macro definitions for the * MC68HC11E20 and MC68HC711E20 microcontrollers. * * CREATED: 11/20/93 * * NOTE: Your comments, suggestions, and corrections are requested * and greatly appreciated. Concepts, Development and Usage */ First references to key terms appear in bold type, and C keywords and expressions appear in italics. In C, we can make just about anything an lvalue, that is, something that appears to the left of the equal sign in an assignment expression. We can even use a number as an lvalue. In particular, we would like to use register addresses as lvalues. To do this, we must cast the value as a pointer to a particular data type. For example (unsigned char *) 0x1000 2 MOTOROLA

nc. Concepts, Development and Usage would be an lvalue that points to an unsigned character (an 8 bit unsigned value) at memory location 0x1000 ($1000 for those used to assembly language). In this particular form, however, we cannot yet assign a value to the memory location. To do this, we must dereference the pointer. Dereferencing a pointer specifies the value that is pointed to and not the pointer itself. So, to assign the value 0xFF to memory location 0x1000, we would use the following C assignment expression: *(unsigned char *) 0x1000 = 0xFF Likewise, to assign the contents of memory location 0x1000 to the variable A, use the following assignment: A = *(unsigned char *) 0x1000 This is all that is really necessary to manipulate the memory mapped registers of the MC68HC11. Unfortunately, *(unsigned char *) 0x1000 is not particularly indicative of the function memory location 0x1000 performs (PORT A on most MC68HC11 devices). The extra typing required to use this memory location can also be a source of minor, but unnecessary compilation errors. A better idea is to use the following line (remember, lines appearing in the hc11e20.h file appear in the Courier typeface): #define REGISTER unsigned char Thus to access memory location 0x1000, we can now type: A = *(REGISTER *) 0x1000 This is an improvement, but it would be even better if we could define a register as PORTA or DDRC as we do when programming in assembly. Thus the following line #define SOMEDEVICE *(REGISTER *)0x1000 will allow us to address 0x1000 in a very convenient fashion. For example, we can now type SOMEDEVICE = 0xFF MOTOROLA 3

nc. to assign 0xFF to memory location 0x1000, and we can also type A = SOMEDEVICE to assign the contents of 0x1000 to the variable A. NOTE: The MC68HC11 has an INIT register which is used to remap internal RAM and registers to the beginning of any 4-K page of memory. Some applications may require register remapping, so it would be convenient if we could make a simple change to the macro definition file toaccount for this. The following line (part of hc11e20.h) allows us to do this: #define REG_BASE 0x1000 We can thus use the following macro definition to handle register relocation: #define SOMEDEVICE *(REGISTER *)(REG_BASE + 0x00) If we leave REG_BASE as 0x1000, then pointers to the MC68HC11's peripheral registers will be addressed at 0x1000 in our source code. If we decide to remap the registers to 0x4000, we can simply replace 0x1000 in the #define REG_BASE macro with 0x4000. This does not actually modify the MC68HC11's INIT register. This must be done by modifying your C compiler's run-time start up code. Refer to your compiler's documentation before making any such changes. Before proceeding with the rest of the hc11e20.h file, we need to understand the use of C's volatile keyword. By specifying a variable as volatile, we tell the C compiler not to optimize expressions using that variable. #define PORT *(REGISTER *)(REG_BASE + 0xA0) void main() { PORT = 0x00; etc... /* PORT is not used until while(port) */ } while (PORT) { etc... } 4 MOTOROLA

nc. Concepts, Development and Usage In this program fragment, we immediately initialize PORT to 0x00, but we will not reference it again until the while (PORT) expression. Unless PORT were to somehow change, while (PORT) would be false, and code in the braces immediately following would not execute. Some C compilers may view this as unnecessary if PORT never changes, and it is possible these lines could be optimized out of the resulting object code. On the MC68HC11, PORT may point to a bi-directional I/O port whose inputs may change during the course of program execution, thus the while (PORT) expression could actually be true when it is executed. As a precaution, we can designate the PORT pointer as volatile so that the optimizer will not attempt to remove any questionable references to it. We would thus change the #define macro to be #define PORT *(volatile REGISTER *)(REG_BASE + 0xA0) By doing this, references to PORT will not be optimized. Several registers on the MC68HC11 can change without the intervention of user code. These register include port data registers (PORTC), peripheral status registers (SPSR), peripheral data registers (SCDR, ADR1), flag registers (TFLG1), and timer registers (TCNT, TIC3). We could use the volatile keyword with every register macro definition to simplify matters, but this runs counter to good code documentation. By specifying only those registers which require it as volatile, the resulting code will be better documented. Only registers which can receive data externally or be changed by the processor without user intervention will be declared volatile. Write-only registers will be easily recognized because they will lack the volatile declaration. These macro definitions are used for the registers on the MC68HC11E20 and MC68HC711E20 devices: #define PORTA (*(volatile REGISTER *)(REG_BASE + 0x00)) #define PIOC (*(volatile REGISTER *)(REG_BASE + 0x02)) #define PORTC (*(volatile REGISTER *)(REG_BASE + 0x03)) #define PORTB (*(REGISTER *)(REG_BASE + 0x04)) #define PORTCL (*(volatile REGISTER *)(REG_BASE + 0x05)) #define DDRC (*(REGISTER *)(REG_BASE + 0x07)) MOTOROLA 5

nc. #define PORTD (*(volatile REGISTER *)(REG_BASE + 0x08)) #define DDRD (*(REGISTER *)(REG_BASE + 0x09)) #define PORTE (*(volatile REGISTER *)(REG_BASE + 0x0A)) #define CFORC (*(REGISTER *)(REG_BASE + 0x0B)) #define OC1M (*(REGISTER *)(REG_BASE + 0x0C)) #define OC1D (*(REGISTER *)(REG_BASE + 0x0D)) These registers (TCNT, TICx, and TOCx) are declared as unsigned integers because they are 16 bit registers and should be accessed as such. It is much simpler and clearer to change, for example, the output compare 4 register by using TOC4 = 0x4000, TOC4 = TCNT + 0x20FF, or TOC4 += 0x3200. #define TCNT (*(volatile unsigned int *)(REG_BASE + 0x0E)) #define TIC1 (*(volatile unsigned int *)(REG_BASE + 0x10)) #define TIC2 (*(volatile unsigned int *)(REG_BASE + 0x12)) #define TIC3 (*(volatile unsigned int *)(REG_BASE + 0x14)) #define TOC1 (*(unsigned int *)(REG_BASE + 0x16)) #define TOC2 (*(unsigned int *)(REG_BASE + 0x18)) #define TOC3 (*(unsigned int *)(REG_BASE + 0x1A)) #define TOC4 (*(unsigned int *)(REG_BASE + 0x1C)) #define TI4O5 (*(volatile unsigned int *)(REG_BASE + 0x1E)) #define TCTL1 (*(REGISTER *)(REG_BASE + 0x20)) #define TCTL2 (*(REGISTER *)(REG_BASE + 0x21)) #define TMSK1 (*(REGISTER *)(REG_BASE + 0x22)) #define TFLG1 (*(volatile REGISTER *)(REG_BASE + 0x23)) #define TMSK2 (*(REGISTER *)(REG_BASE + 0x24)) #define TFLG2 (*(volatile REGISTER *)(REG_BASE + 0x25)) #define PACTL (*(REGISTER *)(REG_BASE + 0x26)) #define PACNT (*(volatile REGISTER *)(REG_BASE + 0x27)) #define SPCR (*(REGISTER *)(REG_BASE + 0x28)) #define SPSR (*(volatile REGISTER *)(REG_BASE + 0x29)) #define SPDR (*(volatile REGISTER *)(REG_BASE + 0x2A)) #define BAUD (*(REGISTER *)(REG_BASE + 0x2B)) SCCR1 is declared volatile because it has the R8 bit, the ninth data bit received when SCI mode 1 is used. The remaining bits in this register are write only. #define SCCR1 (*(volatile REGISTER *)(REG_BASE + 0x2C)) #define SCCR2 (*(REGISTER *)(REG_BASE + 0x2D)) #define SCSR (*(volatile REGISTER *)(REG_BASE + 0x2E)) #define SCDR (*(volatile REGISTER *)(REG_BASE + 0x2F)) 6 MOTOROLA

nc. Concepts, Development and Usage ADCTL is declared volatile because bit 7, the conversion complete flag (CCF), is changed without user intervention. The remaining bits in this register are write only. #define ADCTL (*(volatile REGISTER *)(REG_BASE + 0x30)) #define ADR1 (*(volatile REGISTER *)(REG_BASE + 0x31)) #define ADR2 (*(volatile REGISTER *)(REG_BASE + 0x32)) #define ADR3 (*(volatile REGISTER *)(REG_BASE + 0x33)) #define ADR4 (*(volatile REGISTER *)(REG_BASE + 0x34)) #define BPROT (*(REGISTER *)(REG_BASE + 0x35)) #define EPROG (*(REGISTER *)(REG_BASE + 0x36)) #define OPTION (*(REGISTER *)(REG_BASE + 0x39)) #define COPRST (*(REGISTER *)(REG_BASE + 0x3A)) #define PPROG (*(REGISTER *)(REG_BASE + 0x3B)) #define HPRIO (*(REGISTER *)(REG_BASE + 0x3C)) #define INIT (*(REGISTER *)(REG_BASE + 0x3D)) #define TEST1 (*(REGISTER *)(REG_BASE + 0x3E)) #define CONFIG (*(REGISTER *)(REG_BASE + 0x3F)) C also allows us to declare individual bit fields as constants. This allows us to make simple register bit assignments and comparisons. For instance, while (!(SPSR & SPIF)) can be used to halt program execution until the SPI status register SPIF bit has set. Likewise, we can use SPCR = SPIE + SPE + MSTR + CPHA + SPR0 to configure the SPI for master operation with interrupts using clock phase 1 and a baud rate of E clock divided by 4. We can also use these constants to clear individual bit fields in the timer flag registers. TFLG1 &= OC3F This clears output compare flag 3 without affecting the other bits in the TFLG1 register. A partial list of the macro definitions that are used for the register bit fields on the MC68HC11E20 and MC68HC711E20 devices follows. For a complete list, see the hc11e20h.zip file on the Freeware Data System MOTOROLA 7

nc. N O N - D I S C L O S U R E A G R E E M E N T R E Q U I R E D /* Bit names for general use */ #define bit7 0x80 #define bit6 0x40 #define bit5 0x20 #define bit4 0x10 #define bit3 0x08 #define bit2 0x04 #define bit1 0x02 #define bit0 0x01 /* PORTA bit definitions 0x00 */ #define PA7 bit7 #define PA6 bit6 #define PA5 bit5 #define PA4 bit4 #define PA3 bit3 #define PA2 bit2 #define PA1 bit1 #define PA0 bit0... /* PORTC bit definitions 0x03 */ #define PC7 bit7 #define PC6 bit6 #define PC5 bit5 #define PC4 bit4 #define PC3 bit3 #define PC2 bit2 Motorola reserves the right to make changes without further notice to any products herein. Motorola makes no warranty, representation or guarantee regarding the suitability of its products for any particular purpose, nor does Motorola assume any liability arising out of the application or use of any product or circuit, and specifically disclaims any and all liability, including without limitation consequential or incidental damages. "Typical" parameters which may be provided in Motorola data sheets and/or specifications can and do vary in different applications and actual performance may vary over time. All operating parameters, including "Typicals" must be validated for each customer application by customer's technical experts. Motorola does not convey any license under its patent rights nor the rights of others. Motorola products are not designed, intended, or authorized for use as components in systems intended for surgical implant into the body, or other applications intended to support or sustain life, or for any other application in which the failure of the Motorola product could create a situation where personal injury or death may occur. Should Buyer purchase or use Motorola products for any such unintended or unauthorized application, Buyer shall indemnify and hold Motorola and its officers, employees, subsidiaries, affiliates, and distributors harmless against all claims, costs, damages, and expenses, and reasonable attorney fees arising out of, directly or indirectly, any claim of personal injury or death associated with such unintended or unauthorized use, even if such claim alleges that Motorola was negligent regarding the design or manufacture of the part. Motorola and are registered trademarks of Motorola, Inc. Motorola, Inc. is an Equal Opportunity/Affirmative Action Employer. How to reach us: USA/EUROPE/Locations Not Listed: Motorola Literature Distribution, P.O. Box 5405, Denver, Colorado 80217, 1-800-441-2447 or 1-303-675-2140. Customer Focus Center, 1-800-521-6274 JAPAN: Nippon Motorola Ltd.: SPD, Strategic Planning Office, 141, 4-32-1 Nishi-Gotanda, Shinigawa-Ku, Tokyo, Japan. 03-5487-8488 ASIA/PACIFIC: Motorola Semiconductors H.K. Ltd., 8B Tai Ping Industrial Park, 51 Ting Kok Road, Tai Po, N.T., Hong Kong. 852-26629298 Mfax, Motorola Fax Back System: RMFAX0@email.sps.mot.com; http://sps.motorola.com/mfax/; TOUCHTONE, 1-602-244-6609; US and Canada ONLY, 1-800-774-1848 HOME PAGE: http://motorola.com/sps/ Mfax is a trademark of Motorola, Inc. Motorola, Inc., 1998 /D