Implementing C language nested assembly language in KEIL

Publisher:muhaoying2017Latest update time:2012-09-04 Source: 51heiKeywords:KEIL Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Background

In the process of learning MCU, it is very necessary to master some assembly language. As a low-level language, assembly language plays an irreplaceable role in MCU development. For example, each instruction can accurately determine the delay time, which is easy to understand and very suitable for hardware engineers to learn. However, to improve MCU skills, you must master C language programming, because C language has a powerful modular management concept. I think that in the process of learning, many people have learned both assembly language and C language, so a problem arises. If C language and assembly language are combined to achieve better programming effects, this explanation is based on this problem.

2. Operation steps

first step:

Create a new project and file in KEIL and copy the following program and save it as a C file:

/*

Function: Nesting assembly language in C language, which serves as a starting point for discussion

Author: Yang Rongguo of Sanwei Electronics

Date: 2010-5-16

*/

#include

delay()

{

int i,j;

for(i=0;i<1000;i++)

for(j=0;j<120;j++); //12M crystal oscillator delay 1MS

}

main()

{

P2=0x00; //Control 8 LEDs to light up

delay(); //delay 1S

#pragma ASM // assembly nesting starts

MOV P2,#0FFH //End of assembly nesting

#pragma ENDASM // assembly nesting starts

while(1); //C program ends

}

Step 2:

Select the C file in the Project window, such as CX1.C, and right-click, select "Options for ...", click "Generate Assembler SRC File" and "Assemble SRC File" on the right, and change the checkbox from gray to black (double-click);

Step 3:

Add the corresponding library file (e.g. Keil\C51\Lib\C51S.Lib in Small mode) to the project. This file must be the last file of the project (load it into the project like a header file);

Step 4:

Compile and generate HEX file in KEIL, and design the simulation diagram as shown below, and check the effect in simulation.

3. Demonstration Effect

As shown in the figure below, if you can see the 8 LEDs controlled by the P2 port of the microcontroller light up first and then automatically turn off after a delay of about 1S on your own simulation software PROTEUS, it means that you have fully mastered the method of nesting assembly language in C language.

Click to browse the next page

Homework: Implement C language nested in assembly language. Use C language to control the red LED of P2.0 to flash 5 times at a time interval of 0.1S. Use assembly language to control the green LED of P2.1 to flash 3 times at a time interval of 0.1S and then stop.

Keywords:KEIL Reference address:Implementing C language nested assembly language in KEIL

Previous article:Matrix keyboard of single chip microcomputer
Next article:STC12C2052AD MCU AD conversion C language program

Recommended ReadingLatest update time:2024-11-16 20:53

STM32 IAR Engineering-> KEIL MDK conversion detailed explanation
I found in the study of STM32 that most of the STM32 example programs are based on the IAR development environment, but I think it is more convenient to use the KEIL MDK development environment. I can use RVMDK's powerful peripheral simulation function to accelerate the development of STM32. K's software simulation fun
[Microcontroller]
STM32 IAR Engineering-> KEIL MDK conversion detailed explanation
Proteus and Keil Cx51 microcontroller simulation (flowing light)
Proteus circuit diagram Keil Cx51 program: #include reg51.h sbit VD9=P0^0;  sbit VD10=P0^1;  sbit VD11=P0^2; sbit VD12=P0^3; sbit VD13=P0^4; sbit VD14=P0^5; sbit VD15=P0^6; sbit VD16=P0^7; sbit VD1=P1^0; sbit VD2=P1^1; sbit VD3=P1^2; sbit VD4=P1^3; sbit VD5=P1^4; sbit VD6=P1^5; sbit VD7=P1^6; sbit VD8=P
[Microcontroller]
Keil C51 pointer summary
  A variable is a quantity whose value can change continuously during the execution of a program. To use a variable in a program, you must first use an identifier as the variable name and indicate the data type and storage mode used, so that the compiler system can allocate the corresponding storage space for the vari
[Microcontroller]
Keil C51 pointer summary
Keil C51, memory and pointer disassembly comparison
dATa: Fixed to the first 128 RAM from 0x00 to 0x7f, can be directly read and written with acc, fastest speed, and the smallest generated code. idATa: Fixed to the first 256 RAM from 0x00 to 0xff, the first 128 are exactly the same as the 128 of dATa, just because of the different access methods. idATa is accessed in a
[Microcontroller]
STM32 firmware library V3.4 migrated to Keil MDK v4.12 with pictures and text
   1: The MCU used in this example is STM32F103VET6, which has been tested. If it is other MCU, only minor modifications are needed. 2: First, create the corresponding application folder as shown in the figure below, and pay attention to the hierarchical relationship:   3: The following figure shows the cor
[Microcontroller]
STM32 firmware library V3.4 migrated to Keil MDK v4.12 with pictures and text
Detailed explanation of KeilC51 usage (Part 2)
Chapter 3 Keil C51 vs Standard C One of the keys to learning C51 is to deeply understand and apply the extensions of C51 to the standard ANSI C. This is because most of the extensions are directly targeted at the 8051 series CPU hardware. There are roughly 8 categories: l 8051 storage type and storage area l Storage m
[Microcontroller]
Positioning of variable constant functions in keil c51
Using KeilC51 software, you can easily locate code or data absolutely to a certain address. 1. Code location: Method 1: Use pseudo instruction CSEG. For example, if you want to locate MyFunc1 to the code area C:0x1000, create a new A51 file and add the following content:  PUBLIC MYFUNC1  CSEG AT 1000H MYFUNC1:  ; Othe
[Microcontroller]
Keil5 software simulation waveform and solution to unknown signal
When I was writing a report a few days ago, I accidentally needed to use the software simulation in Keil5 to see the output PWM waveform. After several attempts, I finally figured it out. The problem of unknown signal also appeared. 1. Setting steps for software simulation with Keil5 First, as shown in the figure
[Microcontroller]
Keil5 software simulation waveform and solution to unknown signal
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号