Using modules to write microcontroller programs

Publisher:qinghongLatest update time:2016-12-10 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Environment description: Keil + Proteus circuit simulation

First, create a project in Keil and create three files in the project. The file names are: "header file.c", "delay.c", and "delay.h"

Write the corresponding content in the header files .c, delay.c, and delay.h respectively: (Be careful not to insert the delay.h file into the project file)

Copy code

 1 #include 2 #include"delay.h" 3 4 main() 5 { 6 while(1) 7 { 8 P1 = 0x00; 9 delay();10 P1 = 0xff;11 delay(); 12 }13 }

Copy code

Copy code

1 #include"delay.h"2 delay()3 {4 int x;5 for(x = 0;x < 250;x++)6;7 }

Copy code

Copy code

1 #ifndef _DELAY_H_2 #define _DELAY_H_3 delay();4 5 #endif

Copy code

Set the directory for generating Hex files:

Click Rebuild all target files, and the generated effect is as follows:

Insert an 80C51 microcontroller chip into the Proteus simulation software, and then burn the newly generated Hex file into the chip:

The simulation results are as follows:

The entire process of writing an LED light program using modules has been introduced.

Kind tips:

1. Delay plays a delay role in the program.

2. The difference between #include and #include"delay.h"

#include is stored in the header file directory of the microcontroller

 

#include "delay.h" is a custom function, stored in your new working directory

3. The main purpose of writing this article is not to introduce how to write a microcontroller program for turning an LED on and off, but to introduce the steps of writing programs using modules through this small program.

When I was writing C language, I only used a header file and a main function. At that time, I was thinking, if I do engineering projects in the future, do I have to write a very long C language file like this?

This problem has been bothering me for a long time, but it was solved today. In this way, a large project can be divided into several sub-modules, and then the modules can be tested one by one. Where there are problems, targeted debugging can be carried out, which improves the overall efficiency.


Reference address:Using modules to write microcontroller programs

Previous article:How to tell how big a microcontroller program is
Next article:MCU external crystal and oscillation circuit

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号