⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c511.txt

📁 dsp&c51的编程,从小百合上down的
💻 TXT
字号:
发信人: reflection (似水流年), 信区: EEtechnology 

标  题: C51 Primer (0) 

发信站: 南京大学小百合站 (Wed Nov 24 09:43:26 1999), 转信 

  

C51 Primer 

by Mike Beach, Hitex (UK) Ltd. 

---------------------------------------------------------------------------- 

---- 

About The C51 Primer 

If you've flicked through this publication, you may be left thinking that it 

 is necessary to be an expert to produce workable programs with C51. Nothing 

 could be further from the truth. It is perfectly possible to write real com 

mercial programs with nothing more than a reasonable knowledge of the ANSI C 

 language. 

However, to get the maximum performance from the 8051, knowing a few tricks 

is very useful. This is particularly true if you are working on a very cost- 

sensitive project where needing a bigger RAM or EPROM can result in an unacc 

eptable on-cost. After all, if cost was not a consideration, we would all be 

 using 80C166s and 68000s! 

Whilst the C51 Primer is really aimed at users of the Keil C51 Compiler, it 

is applicable in part to compilers such as IAR and Tasking. However, as thes 

e compilers do not allow such low-level access and have fewer 8051-specific 

extensions, they are le ss likely to be used on projects where getting maxim 

um performance is essential. 

The C51 Primer Will Help You 

Find your way around the basic 8051 architecture. 

Make a sensible choice of memory model and special things to watch out for. 

Locate things at specific addresses. 

Make best use of structures. 

Use bit-addressable memory. 

Think in terms of chars rather than ints. 

Get the best out of the various pointer types. 

Get a modular structure into programs. 

Access on and off-chip ports and peripherals. 

Deal with interrupts. 

Use registerbanks. 

Deal with the stack. 

Understand RAM overlaying. 

Interface to assembler code. 

Use special versions like the 80C517 and 87C751. 

Use assembler tricks in C. 

Help the optimiser to produce the smallest, fastest code. 

The C51 Primer Will Not Help You 

Program in ANSI C - get a good reference like Kernighan & Ritchie. 

Write portable code - simply use the compiler without using any extensions. 

Set-up each and every on-chip peripheral on all of the 90 different 8051 var 

iants! Some are, however, covered in the appendices. 

This guide should be read in association with a good C reference such as Ker 

nighan and Ritchie and is not meant to be a definitive work on the C languag 

e. It covers all the 8051-specific language extensions and those areas where 

 the CPU architecture h as an impact on coding approach. 

---------------------------------------------------------------------------- 

---- 

Contents 

About The C51 Primer 

1 Introduction 

2 Keil C51 Compiler Basics - The 8051 Architecture 

2.1 8051 Memory Configurations 

2.1.1 Physical Location Of The Memory Spaces 

2.1.2 Possible Memory Models 

2.1.3 Choosing The Best Memory Configuration/Model 

2.1.4 Setting The Memory Model - #Pragma Usage 

2.2 Local Memory Model Specification 

2.2.1 Overview 

2.2.2 A Point To Watch In Multi-Model Programs 

3 Declaring Variables And Constants 

3.1 Constants 

3.2 Variables 

3.2.1 Uninitialised Variables 

3.2.2 Initialised Variables 

3.3 Watchdogs With Large Amounts Of Initialised Data 

3.4 C51 Variables 

3.4.1 Variable Types 

3.4.2 Special Function Bits 

3.4.3 Converting Between Types 

3.4.4 A Non-ANSI Approach To Checking Data Type 

4 Program Structure And Layout 

4.1 Modular Programming In C51 

4.2 Accessibility Of Variables In Modular Programs 

4.3 Building A Real Modular Program - 

4.3.1 The Problem 

4.3.2 Maintainable Inter-Module Links 

4.4 Task Scheduling 

4.4.1 8051 Applications Overview 

4.4.2 Simple 8051 Systems 

4.4.3 Simple Scheduling - A Partial Solution 

4.4.4 A Pragmatic Approach 

5 C Language Extensions For 8051 

5.1 Accessing 8051 On-Chip Peripherals 

5.2 Interrupts 

5.2.1 The Interrupt Function Type 

5.2.2 Using C51 With Target Monitor Debuggers 

5.2.3 Coping Interrupt Spacings Other Than 8 

5.2.4 The Using Control 

5.3 Interrupts, USING, Registerbanks, NOAREGS In C51 

5.3.1 The Basic Interrupt Service Function Attribute 

5.3.2 The absolute register addressing trick in detail 

5.3.3 The USING Control 

5.3.4 Notes on C51's "Stack Frame" 

5.3.5 When To Use USING 

5.3.6 The NOAREGS pragma 

5.3.7 The REGISTERBANK Control Alternative To NOAREGS 

5.3.8 Summary Of USING And REGISTERBANK 

5.3.9 Reentrancy In C51 - The Final Solution 

5.3.10 Summary Of Controls For Interrupt Functions 

5.3.11 Reentrancy And Library Functions 

6 Pointers In C51 

6.1 Using Pointers And Arrays In C51 

6.1.1 Pointers In Assembler 

6.1.2 Pointers In C51 

6.2 Pointers To Absolute Addresses 

6.3 Arrays And Pointers - Two Sides Of The Same Coin? 

6.3.1 Uninitialised Arrays 

6.3.2 Initialised Arrays 

6.3.3 Using Arrays 

6.3.4 Summary Of Arrays And Pointers 

6.4 Structures 

6.4.1 Why Use Structures? 

6.4.2 Arrays Of Structures 

6.4.3 Initialised Structures 

6.4.4 Placing Structures At Absolute Addresses 

6.4.5 Pointers To Structures 

6.4.6 Passing Structure Pointers To Functions 

6.4.7 Structure Pointers To Absolute Addresses 

6.5 Unions 

6.6 Generic Pointers 

6.7 Spaced Pointers In C51 

7 Accessing External Memory Mapped 

7.1 The XBYTE And XWORD Macros 

7.2 Initialised XDATA Pointers 

7.3 Run Time xdata Pointers 

7.4 The volatile Storage Class 

7.5 Placing Variables At Specific Locations - 

7.6 Excluding External Data Ranges From Specific 

8 Linking Issues And Stack Placement 

8.1 Basic Use Of L51 Linker 

8.2 Stack Placement 

8.3 Using The Top 128 Bytes of the 8052 RAM 

8.4 L51 Linker Data RAM Overlaying 

8.4.1 Overlaying Principles 

8.4.2 Impact Of Overlaying On Program Construction 

8.4.2.1 Indirect Function Calls With Function Pointers 

8.4.2.2 Indirectly called functions solution 

8.4.2.3 Function Jump Table Warning (Non-hazardous) 

8.4.2.4 Function Jump Table Warning Solution 

8.4.2.5 Multiple Call To Segment Warning (Hazardous) 

8.4.2.6 Multiple Call To Segment Solution 

8.4.3 Overlaying Public Variables 

9 Other C51 Extensions 

9.1 Special Function Bits 

9.2 Support For 80C517/537 32-bit Maths Unit 

9.2.1 The MDU - How To Use It 

9.2.2 The 8 Datapointers 

9.2.3 80C517 - Things To Be Aware Of 

9.3 87C751 Support 

9.3.1 87C751 - Steps To Take 

9.3.2 Integer Promotion 

10 Miscellaneous Points 

10.1 Tying The C Program To The Restart Vector 

10.2 Intrinsic Functions 

10.3 EA Bit Control #pragma 

10.4 16 Bit sfr Support 

10.5 Function Level Optimisation 

10.6 In-Line Functions In C51 

11 Some C51 Programming Tricks 

11.1 Accessing R0 etc. directly from C51 

11.2 Making Use Of Unused Interrupt Sources 

11.3 Code Memory Device Switching 

11.4 Simulating A Software Reset 

11.5 The Compiler Preprocessor - #define 

12 C51 Library Functions 

12.1 Library Function Calling 

12.2 Memory-Model Specific Libraries 

13 Outputs From C51 

13.1 Object Files 

13.2 HEX Files For EPROM Blowing 



13.3 Assembler Output 

14 Assembler Interfacing To C Programs 

14.1 Assembler Function Example 

14.2 Parameter Passing To Assembler Functions 

14.3 Parameter Passing In Registers 

15 General Things To Be Aware Of 

15.1 

15.2 

15.3 

15.4 

15.5 

15.6 

15.7 Floating Point Numbers 

16 Conclusion 

---------------------------------------------------------------------------- 

---- 

  

-- 

Ours is essentially a tragic age, so we refuse to take it tragically. 

  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -