Keil C51's 18th keyword extension of C language: using

Publisher:MysticMoonLatest update time:2018-06-21 Source: eefocusKeywords:Keil  C51  using Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In the 8051 series microcontrollers, the first 32 bytes of the internal RAM are divided into 4 groups, each with 8 registers. The names of the 8 registers in each group are R0-R7. By setting two bits in the PSW register, you can choose which of the 4 groups of registers to use.

Register sets are very useful when handling interrupts or using real-time operating systems. You can use different register sets when entering an interrupt or switching tasks, without saving the contents of the 8 registers to the stack. When exiting an interrupt or returning to the original task, you only need to switch back to the original register set.

Specify the register bank to be used by a function:


void rb_function (void) using 3
  {
  .
  .
  .
  }

Using is followed by a number 0-3. Symbolic expressions are not allowed to replace the numeric constant. The using keyword can only be used when defining a function. It is not allowed when declaring a function prototype.


A function declared using has the following characteristics:

1) At the function entry, the currently used register set is saved to the stack;

2) The specified register group is set;

3) Before the function exits, the original register set is restored;

The following shows the usage of using. Please pay attention to the codes at the function entry and exit in the generated assembly program:


C program:

   1
   2 external bit alarm;
   3         int alarm_count;
   4         extern void alfunc (bit b0);
   5
   6         void falarm (void) using 3  {
   7   1           alarm_count++;
   8   1           alfunc (alarm = 1);
   9   1         }


Generated assembler:
0000 C0D0 PUSH PSW /* At the function entry, save the original register group to the stack */
0002 75D018 MOV PSW,#018H /* Switch to new register bank */
0005 0500   R   INC   alarm_count+01H
0007 E500   R   MOV   A,alarm_count+01H
0009 7002       JNZ   ?C0002
000B 0500   R   INC   alarm_count
000D ?C0002:
000D D3 SETB C
000E 9200   E   MOV   alarm,C
0010 9200   E   MOV   ?alfunc?BIT,C
0012 120000 E   LCALL alfunc
0015 D0D0 POP PSW /* Before exiting the function, switch to the original register group */
0017 22 COURT

Functions whose return values ​​are stored in registers cannot use using.


Even if the same register set is used, a using function cannot return a bit type value.

Using is usually used when defining interrupt service functions. We can specify different register groups for different interrupt service functions, which can reduce stack operations and improve program running efficiency.


Keywords:Keil  C51  using Reference address:Keil C51's 18th keyword extension of C language: using

Previous article:Keil C51 LST file
Next article:Keil C51's Seventeenth Keyword Extension to C Language: sbit

Recommended ReadingLatest update time:2024-11-16 21:24

Build 51 environment on keil5 (MDK5)
Prerequisite: The computer has installed the keil5 environment (MDK-Arm) first step Go to the Keil official website https://www.keil.com/download/product/ to download C51 Step 2 Just double-click the downloaded Note: It will automatically scan your keil5 environment and then install it directly into the keil5 in
[Microcontroller]
Build 51 environment on keil5 (MDK5)
Solution to the problem that Keil debugging cannot set breakpoints
The reason is actually very simple, the optimization level set by Keil by default is too high! You just need to change it  After changing it to 0, you can set a breakpoint anywhere By the way, don't forget to compile after the change, it will take effect after it is completed
[Microcontroller]
Solution to the problem that Keil debugging cannot set breakpoints
C51 MCU, 128*64 serial port LCD driver
CA12864K Serial C51 Demo Program //CA12864K test program (serial port)  //*************************************************************************** //Connection table: CPU=89C52 SystemClock=12Mhz * //CS=P3.0            SCLK=P3.1          SID=P3.2       Reset=RC in Board    * //***************************************
[Microcontroller]
C51 program for single chip decoding universal infrared remote control
How to use: Open the serial port debugging assistant and set it to 9600 bps. The microcontroller uses a 11.0592MHz crystal oscillator. Use sm0038 or other types of infrared receivers to connect according to the following circuit, where out is directly connected to the p3.2 pin of the microcontroller. Press the r
[Microcontroller]
C51 program for single chip decoding universal infrared remote control
The growth path of single-chip microcomputers (51 basics) - 008 C51 identifiers and keywords
The standard C language defines 32 keywords, as shown in the following table (32 keywords of ANSI C):   C51 has expanded the functions of the microcontroller on this basis. For details, see the following table (C51 compiler expanded keywords): C 51 Data Types The memory types of the C language used by the 51 mic
[Microcontroller]
The growth path of single-chip microcomputers (51 basics) - 008 C51 identifiers and keywords
The Making and Using of Keil Monitor-51 Simulation Board
MCS-51 single-chip microcomputer is the most widely used and enduring one in my country. In the past, single-chip microcomputer applications were mainly written in assembly language. Since the readability and portability of assembly language programs are poor, the use of assembly language to write single-chip microc
[Microcontroller]
C51/C52 Interrupt (EXTI)
1. Digital tube display principle: The digital tube is actually composed of 8 LEDs, divided into a, b, c, d, e, f, g, dp, and the digital tube is divided into common cathode (left, high level lights up) and common anode (right, low level lights up). Lighting up the corresponding LED can display the corresponding num
[Microcontroller]
C51/C52 Interrupt (EXTI)
About the use of single chip microcomputer
The format of C51 interrupt function is: void FuncIr(void) interrupt x The following is some analysis of sleepwalking:       1. The interrupt function is a special function with no parameters and no return value; but is it allowed to use return in the program? The answer is yes, but only "return;" can be used, not "
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号