throbber
ST7
`8-BIT MCU FAMILY
`
`USER GUIDE
`
`July 2002
`
`0001
`
`1
`
`AMD EX1017
`U.S. Patent No. 6,895,519
`
`

`

`USE IN LIFE SUPPORT DEVICES OR SYSTEMS MUST BE EXPRESSLY AUTHORIZED.
`STMicroelectronics PRODUCTS ARE NOT AUTHORIZED FOR USE AS CRITICAL COMPONENTS IN
`LIFE SUPPORT DEVICES OR SYSTEMS WITHOUT THE EXPRESS WRITTEN APPROVAL OF
`STMicroelectronics. As used herein:
`
`1. Life support devices or systems are those
`which (a) are intended for surgical implant into
`the body, or (b) support or sustain life, and
`whose failure to perform, when properly used in
`accordance with instructions for use provided
`with the product, can be reasonably expected
`to result in significant injury to the user.
`
`1
`
`2. A critical component is any component of a life
`support device or system whose failure to
`perform can reasonably be expected to cause
`the failure of the life support device or system,
`or to affect its safety or effectiveness.
`
`0002
`
`

`

`Table of Contents
`
`1 INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
`
`1.1 WHO IS THIS BOOK WRITTEN FOR? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
`
`1.2 ABOUT THE AUTHORS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
`
`1.3 HOW IS THIS BOOK ORGANIZED? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
`
`1.4 WHY A MICROCONTROLLER? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
`1.4.1 Electronic circuitry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15
`1.4.2 Choice of microcontroller model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
`1.4.3 Choice of development tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
`
`2 HOW DOES A TYPICAL MICROCONTROLLER WORK? . . . . . . . . . . . . . . . . . . . . . . . 19
`
`2.1 THE CENTRAL PROCESSING UNIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
`
`2.2 HOW THE CPU AND ITS PERIPHERALS MAKE UP A SYSTEM . . . . . . . . . . . . 21
`2.2.1 CPU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21
`2.2.2 Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21
`2.2.3 Input-Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .23
`2.2.4 Interrupt Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24
`2.2.5 Bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25
`2.2.6 Clock Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25
`2.2.7 Reset Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25
`
`2.3 CORE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
`2.3.1 Arithmetic and Logic Unit (ALU) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25
`2.3.2 Program Counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .26
`2.3.3 Instruction Decoder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .26
`2.3.4 Stack Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .26
`
`2.4 PERIPHERALS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
`2.4.1 Parallel Input-Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .27
`2.4.2 Analog to Digital Converter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .28
`2.4.3 Programmable Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .28
`2.4.4 Serial Peripheral Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .28
`2.4.5 Watchdog Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .28
`
`2.5 THE INTERRUPT MECHANISM AND HOW TO USE IT . . . . . . . . . . . . . . . . . . . . 29
`2.5.1 Interrupt handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29
`2.5.1.1 Hardware mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31
`2.5.1.2 Hardware sources of interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31
`2.5.1.3 Global interrupt enable bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32
`
`3/315
`1
`
`0003
`
`

`

`Table of Contents
`
`2.5.1.4 Software interrupt instruction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32
`2.5.1.5 Saving the state of the interrupted program . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32
`2.5.1.6 Interrupt vectorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32
`2.5.1.7 Interrupt service routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .34
`2.5.1.8 Interrupt Return instruction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .34
`2.5.2 Software precautions related to interrupt service routines . . . . . . . . . . . . . . . . . . . . . . .34
`2.5.2.1 Saving the Y register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .34
`2.5.2.2 Managing the stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35
`2.5.2.3 Resetting the hardware interrupt request flags . . . . . . . . . . . . . . . . . . . . . . . . . . .35
`2.5.2.4 Making an interrupt service routine interruptible . . . . . . . . . . . . . . . . . . . . . . . . . .35
`2.5.2.5 Data desynchronization and atomicity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .36
`2.5.3 Conclusion: the benefits of interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .38
`
`2.6 AN APPLICATION USING INTERRUPTS: A MULTITASKING KERNEL . . . . . . . 39
`2.6.1 Pre-emptive multitasking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .39
`2.6.2 Cooperative multitasking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41
`2.6.3 Multitasking kernels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42
`2.6.3.1 Advantages of programming with a multitasking kernel . . . . . . . . . . . . . . . . . . . .42
`2.6.3.2 The task declaration and allocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42
`2.6.3.3 Task sleeping and waking-up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42
`2.6.3.4 Multitasking kernel overhead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .43
`
`3 PROGRAMMING A MICROCONTROLLER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
`
`3.1 ASSEMBLY LANGUAGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
`3.1.1 When to use assembly language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .45
`3.1.2 Development process in assembly language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46
`3.1.2.1 Assembly language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .47
`3.1.2.2 Assembler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .48
`3.1.2.3 Linker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .49
`3.1.2.4 The project builder/make utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .51
`3.1.2.5 EPROM burners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .52
`3.1.2.6 Simulators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .53
`3.1.2.7 In-circuit emulators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .54
`
`3.2 C LANGUAGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
`3.2.1 Why use C? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .55
`3.2.2 Tools used with C language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .57
`3.2.3 Debugging in C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .58
`
`3.3 DEVELOPMENT CHAIN SUMMARY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
`
`3.4 APPLICATION BUILDERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
`315
`3.5 FUZZY-LOGIC COMPILERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
`
`4/315
`1
`
`0004
`
`

`

`Table of Contents
`
`4 ARCHITECTURE OF THE ST7 CORE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
`
`4.1 POSITION OF THE ST7 WITHIN THE ST MCU FAMILY . . . . . . . . . . . . . . . . . . . . 62
`
`4.2 ST7 CORE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
`4.2.1 Addressing space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .65
`4.2.2 Internal registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .65
`4.2.2.1 Accumulator (A) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .65
`4.2.2.2 Condition Code register (CC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .65
`4.2.2.3 Index registers (X and Y) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .67
`4.2.2.4 Program Counter (PC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .68
`4.2.2.5 Stack Pointer (SP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .68
`
`4.3 INSTRUCTION SET AND ADDRESSING MODES . . . . . . . . . . . . . . . . . . . . . . . . 70
`4.3.1 A word about mnemonic language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .70
`4.3.2 Addressing modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .72
`4.3.3 Instruction set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .73
`4.3.4 Coding of the instructions and the address . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .74
`4.3.4.1 Prefix byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .74
`4.3.4.2 Opcode byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .75
`4.3.4.3 The addressing modes in detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .77
`
`4.4 ADVANTAGES OF THE ST7 INSTRUCTION SET AND ADDRESSING MODES 82
`
`5 PERIPHERALS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
`
`5.1 CLOCK GENERATOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
`5.1.1 ST72251 Miscellaneous Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .84
`5.1.2 ST72311 Miscellaneous Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .85
`
`5.2 INTERRUPT PROCESSING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
`5.2.1 Interrupt sources and interrupt vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .86
`5.2.1.1 Interrupts sources for the ST72251 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .87
`5.2.1.2 Interrupt sources for the ST72311 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .88
`5.2.2 Interrupt vectorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .89
`5.2.3 Global interrupt enable bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .90
`5.2.4 TRAP instruction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .91
`5.2.5 Interrupt mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .91
`5.2.5.1 Saving the interrupted program state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .91
`5.2.5.2 Interrupt service routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .91
`5.2.5.3 Restoring the interrupted program state: The IRET instruction . . . . . . . . . . . . . . .92
`5.2.6 Nesting the interrupt services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .92
`
`5.3 PARALLEL INPUT-OUTPUT PORTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
`
`5/315
`1
`
`0005
`
`

`

`Table of Contents
`
`5.3.1 ST72251 I/O Ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .94
`5.3.2 ST72311 I/O Ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .96
`
`5.4 WATCHDOG TIMER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
`5.4.1 Aim of the watchdog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .99
`5.4.2 Watchdog Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .100
`5.4.3 Using the Watchdog to protect an application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .103
`
`5.5 16-BIT TIMER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
`5.5.1 Timer clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .104
`5.5.2 Free running counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .105
`5.5.2.1 Reading the free running counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .105
`5.5.2.2 Resetting the free running counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .106
`5.5.2.3 The TOF flag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .107
`5.5.3 Input capture operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .108
`5.5.4 Output compare operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .110
`5.5.5 One-pulse mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .113
`5.5.6 Pulse-Width Modulation mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .115
`
`5.6 ANALOG TO DIGITAL CONVERTER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
`5.6.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .117
`5.6.2 Using the Analog to Digital Converter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .118
`5.6.3 The problem of the converter’s accuracy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .119
`5.6.4 Using the ADC to convert positive and negative voltages; increasing its resolution . .120
`5.6.4.1 Measuring negative and positive voltages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .120
`5.6.4.2 Increasing the resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .121
`5.6.4.3 Application Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .124
`
`5.7 SERIAL PERIPHERAL INTERFACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
`
`5.8 SERIAL COMMUNICATION INTERFACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
`5.8.1 Bit rate generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .128
`5.8.2 Send and receive mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .129
`5.8.3 Status register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .132
`5.8.4 Control Register 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .132
`5.8.5 Using the Wake-Up feature in a multiprocessor system . . . . . . . . . . . . . . . . . . . . . . . .133
`5.8.6 Handling the interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .133
`
`6 STMICROELECTRONICS PROGRAMMING TOOLS . . . . . . . . . . . . . . . . . . . . . . . . . . 135
`
`6.1 ASSEMBLER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
`315
`6.1.1 An overview of the assembler function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .135
`6.1.2 Instruction coding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .137
`
`6/315
`1
`
`0006
`
`

`

`Table of Contents
`
`6.1.3 Declaring variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .138
`6.1.4 Declaring constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .140
`6.1.4.1 Constant data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .140
`6.1.4.2 Symbol definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .141
`6.1.5 Relocation commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .142
`6.1.5.1 What is relocation? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .142
`6.1.5.2 Segment definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .143
`6.1.5.3 Using the Segment directive in the source file . . . . . . . . . . . . . . . . . . . . . . . . . . .145
`6.1.5.4 Segment allocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .146
`6.1.5.5 Initialization of variables at power-on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .148
`6.1.5.6 Referencing symbols and labels between modules . . . . . . . . . . . . . . . . . . . . . . .151
`6.1.6 Conditional assembly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .154
`6.1.7 Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .156
`6.1.7.1 Replaceable parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .157
`6.1.7.2 Local symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .158
`6.1.7.3 Conditional statements in macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .160
`6.1.8 Some miscellaneous features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .162
`6.1.8.1 EQU and CEQU pseudo-ops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .162
`6.1.8.2 #DEFINE pseudo-op . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .162
`6.1.8.3 Numbering syntax directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .163
`6.1.9 Object and listing files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .163
`6.1.9.1 Object files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .163
`6.1.9.2 Listing files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .164
`
`6.2 LINKER AND ASCII-HEX CONVERTER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
`6.2.1 The linking process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .165
`6.2.2 Hex file translator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .167
`6.2.3 The back-annotation pass of the assembler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .168
`
`6.3 INSTALLING WINEDIT AND THE SOFTWARE TOOLS . . . . . . . . . . . . . . . . . . . 168
`6.3.1 WinEdit text editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .168
`6.3.1.1 Installing WinEdit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .168
`6.3.1.2 Configuring WinEdit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .169
`6.3.2 Installing the STMicroelectronics Software Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . .169
`
`6.4 BUILDING A DEMONSTRATION PROGRAM . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
`6.4.1 Purpose of the demonstration program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .170
`6.4.2 Inventory of the program files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .170
`6.4.3 Description of the program files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .171
`6.4.3.1 The PROJECT.WPJ file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .171
`6.4.3.2 The main source file, MAIN.ASM and the timer source file, TIMER500.ASM . . .
`
`173
`
`6.4.3.3 The REG72251.ASM file and the REGISTER.INC file . . . . . . . . . . . . . . . . .176
`6.4.3.4 The MAP72251.ASM file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .178
`
`7/315
`1
`
`0007
`
`

`

`Table of Contents
`
`6.4.3.5 The CATERPIL.BAT file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .179
`6.4.4 Using WinEdit to change and compile the files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .180
`
`7 DEBUGGER AND PROM PROGRAMMER TUTORIAL FOR ST72251 . . . . . . . . . . . . 183
`
`7.1 STMICROELECTRONICS HARDWARE TOOLS . . . . . . . . . . . . . . . . . . . . . . . . . 183
`7.1.1 EPROM Programming Boards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .183
`7.1.2 Starter Kits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .184
`7.1.3 Development Kits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .184
`7.1.4 Emulators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .184
`
`7.2 EPROM PROGRAMMER BOARDS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
`7.2.1 EPROM programmer Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .185
`7.2.2 Using the EPROMER software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .185
`
`7.3 EMULATOR AND DEBUGGER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
`7.3.1 Introducing the emulator and the debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .189
`7.3.2 Installing the emulator and the debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .189
`7.3.3 Using the debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .191
`7.3.3.1 Loading the application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .191
`7.3.3.2 Running the application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .193
`7.3.3.3 Watching the registers and variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .193
`7.3.3.4 Using Inspect and Watch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .195
`7.3.3.5 Using breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .197
`7.3.3.6 Watching the contents of the stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .198
`7.3.3.7 Watching the execution trace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .199
`7.3.3.8 More features to come later . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .200
`
`7.4 PURPOSE OF THE TUTORIAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
`
`7.5 SCHEMATIC DRAWING OF THE PRINTED CIRCUIT BOARD . . . . . . . . . . . . . 202
`
`7.6 DEVELOPING THE PROGRAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
`7.6.1 Peripherals used to implement the solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .202
`7.6.2 The algorithm of each task . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .203
`7.6.3 A simple multitasking kernel for the ST7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .204
`7.6.3.1 StartTasks routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .204
`7.6.3.2 The Yield routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .206
`7.6.4 The source code of the application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .209
`7.6.4.1 Main file (Multitsk.asm) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .210
`7.6.4.2 ADC source file(Acana.asm) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .214
`7.6.4.3 Kernel source file (Littlk.asm) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
`315
`7.7 RUNNING THE APPLICATION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
`
`8/315
`1
`
`0008
`
`

`

`Table of Contents
`
`7.8 SUMMARY REMARKS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
`
`8 C LANGUAGE AND THE C COMPILER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
`
`8.1 C LANGUAGE EXTENSIONS FOR MICROCONTROLLERS . . . . . . . . . . . . . . . 219
`
`8.2 DESCRIPTION AND INSTALLATION OF THE HICROSS TOOL CHAIN . . . . . . 220
`
`8.3 USING THE C COMPILER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
`8.3.1 Memory allocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .224
`8.3.1.1 Read-only constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .225
`8.3.1.2 EEPROM non-volatile storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .226
`8.3.1.3 Page Zero variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .227
`8.3.1.4 Far and near pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .227
`8.3.2 Initialization of variables and constant variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .228
`8.3.3 Inputs and outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .228
`8.3.3.1 First method: using macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .229
`8.3.3.2 Second method: defining variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .229
`8.3.4 Interrupt handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .230
`8.3.5 Limitations put on the full implementation of C language . . . . . . . . . . . . . . . . . . . . . . .230
`
`8.4 USING THE ASSEMBLER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
`8.4.1 Using In-line assembler statements within a C source text . . . . . . . . . . . . . . . . . . . . .231
`8.4.1.1 Single-statement assembler block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .231
`8.4.1.2 Multiple-statement assembler block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .232
`8.4.2 Using the Hiware assembler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .233
`
`8.5 USING THE LINKER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
`
`8.6 USING THE EPROM BURNER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
`
`8.7 PROJECT DIRECTORY STRUCTURE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
`8.7.1 Config directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .237
`8.7.2 Object directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .239
`8.7.3 Sources directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .239
`
`8.8 HINTS ON C WRITING STYLE FOR THE ST7 . . . . . . . . . . . . . . . . . . . . . . . . . . 241
`8.8.1 Accessing individual bits in registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .241
`8.8.2 Setting configuration registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .243
`8.8.3 Using macros to define external devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .243
`8.8.4 Optimizing resource usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .245
`8.8.4.1 Define a function when a group of statements is repeated several times . . . . . .245
`8.8.4.2 Use shifts instead of multiplication and division . . . . . . . . . . . . . . . . . . . . . . . . . .245
`8.8.4.3 Limit the size of variables to the very minimum . . . . . . . . . . . . . . . . . . . . . . . . . .246
`
`9/315
`
`0009
`
`

`

`Table of Contents
`
`8.9 CONCLUSION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
`
`9 A CARRIER-CURRENT SYSTEM FOR DOMESTIC REMOTE CONTROL . . . . . . . . . 247
`
`9.1 CARRIER CURRENT CONTROL AND THE X-10 STANDARD . . . . . . . . . . . . . 248
`
`9.2 TRANSMITTER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
`9.2.1 Instructions for use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .253
`9.2.2 Description of the electronic circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .253
`9.2.3 Description of the software . . . . . . . . . . . . . . . . . . . . . . . .

This document is available on Docket Alarm but you must sign up to view it.


Or .

Accessing this document will incur an additional charge of $.

After purchase, you can access this document again without charge.

Accept $ Charge
throbber

Still Working On It

This document is taking longer than usual to download. This can happen if we need to contact the court directly to obtain the document and their servers are running slowly.

Give it another minute or two to complete, and then try the refresh button.

throbber

A few More Minutes ... Still Working

It can take up to 5 minutes for us to download a document if the court servers are running slowly.

Thank you for your continued patience.

This document could not be displayed.

We could not find this document within its docket. Please go back to the docket page and check the link. If that does not work, go back to the docket and refresh it to pull the newest information.

Your account does not support viewing this document.

You need a Paid Account to view this document. Click here to change your account type.

Your account does not support viewing this document.

Set your membership status to view this document.

With a Docket Alarm membership, you'll get a whole lot more, including:

  • Up-to-date information for this case.
  • Email alerts whenever there is an update.
  • Full text search for other cases.
  • Get email alerts whenever a new case matches your search.

Become a Member

One Moment Please

The filing “” is large (MB) and is being downloaded.

Please refresh this page in a few minutes to see if the filing has been downloaded. The filing will also be emailed to you when the download completes.

Your document is on its way!

If you do not receive the document in five minutes, contact support at support@docketalarm.com.

Sealed Document

We are unable to display this document, it may be under a court ordered seal.

If you have proper credentials to access the file, you may proceed directly to the court's system using your government issued username and password.


Access Government Site

We are redirecting you
to a mobile optimized page.





Document Unreadable or Corrupt

Refresh this Document
Go to the Docket

We are unable to display this document.

Refresh this Document
Go to the Docket