Build a C51 Keil project environment using RTX51-Tiny

Publisher:sheng44Latest update time:2015-08-21 Source: eefocusKeywords:RTX51-Tiny  C51  Keil Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Personal Records:
I didn't expect that the stc microcontroller can run the system in addition to the bare board. I was a little surprised.
I remember that I first came into contact with rtx51 when I was playing with pSoC3 (51 core). Later, I changed to PSoC5 and replaced the arm core and put this part aside. Today, I accidentally saw that it can actually be run with an stc microcontroller, which is quite interesting.
Mark it.
You can check it out when you have time.
 
Wanfang also searched for two articles. You can take a look at other people's designs when you have time:
Design of Smart Card Electric Energy Meter Based on RTX51 Embedded Operating System
Two-player game design based on RTX51 Tiny operating system
 
I tried it and it's quite convenient and simple.
The system  can be initialized using the main function like this  (not recommended)
 void  main(void)   
     init_system();                                //System initialization   
       os_start_system(0);           //Start RTX51   
       
  
It can also be written in task0 (finally delete task0) 
void  startup_task  (void)  _task_ 

init_system();                                //System initialization   
os_create_task  (1);   
os_create_task  (2);   
os_delete_task  (0);   
}
 
The following is the reprinted text:

In the past month, I have been using my spare time to study the STC12A5C60S2 microcontroller and its applications to relax my nervous mood and mind after working on SharePoint every day. (It turns out that it would be strange if I could relax!)

After tinkering with LCD 1602, LCD 12864 (parallel and serial), PCF 8563 (clock chip), nRF24L01 (wireless communication), matrix keyboard, LN 298 (H-bridge motor driver), optocoupler counter, HC-SR 04 (ultrasonic ranging), I decided to give up the "idiot" "multitasking" program based on interrupts and timer loops and install an operating system. Otherwise, it would be almost impossible for me to write a slightly complex application later.

The following is the minimum system of the STC12A5C60S2 microcontroller I use. It comes with a USB-to-serial chip, all IO ports are brought out, and it is very convenient to burn and debug the chip:

This small board has its disadvantages, that is, there are no mounting holes, the whole board can only "float", and is fixed by the tension of the Dupont line (uh, that is, it is not fixed:), so when it is used on the car later, it can only be installed on the perforated board by welding the "bracket" at the bottom like this:

 

Choice of operating system

The first choice I considered was uc/OS-II, because it is well-known (I often see it), has powerful functions (it sounds good), and the book I bought also introduced this operating system.

The task scheduling of us/OS-II is a preemptive scheduling method based entirely on task priority. A low-priority task being executed can be interrupted by a high-priority task in the "READY" state. This can also be achieved in STC12A5C60S2 by setting the hardware interrupt priority, but it is impossible for me to interrupt every task. So I still have to use the operating system.

I looked up some information online and was stunned. us/OS-II is too complicated. No webpage can explain how to use it in a few paragraphs. Moreover, us/OC-II needs to be ported to STC12A5C60S2 (that is, you have to modify its source code to adapt to the special conditions of the hardware). Uh…

Then, I started to consider RTX-51. Because the C51 development tool Keil comes with an RTX-51 operating system and directly supports compilation and debugging in Keil, it is quite attractive:)

RTX-51 has 2 versions: Full and Tiny.

Full requires more resources, but supports preemptive task scheduling and interrupt tasks, as well as messaging between tasks; Tiny does not support preemptive scheduling, and tasks cannot send messages to each other, but consumes fewer resources.

Although the Full version is powerful, it takes up 8K ROM, and requires at least 450 bytes of xData! The STC12A5C60S2 only has 1024 bytes of on-chip xData RAM, and I also need xData as LCD display memory. After thinking about it, I decided to choose RTX-51 Tiny.

The Tiny version does not occupy xData and occupies very little RAM (7+3×number of tasks), which is quite suitable. As for the disadvantages, you can only know them after using them. The Tiny version is open source, and the source code is assembly. Someone in China wrote an operating system based on it, called  Small RTOS51 .

Chen Mingji, the author of Small RTOS 51, was unable to find a suitable MCU operating system and wrote this operating system in a rage. This operating system has the advantages of the Tiny version with less resource usage and supports preemptive task scheduling. (If you are unhappy, you create one. This seems to be the fundamental motivation for the emergence of many talented people and new technologies! So, when there is no good wheel to use, you have to invent a new wheel yourself.)

RTX-51 Tiny is very easy to use. I just browsed online and immediately found a usable guide ( MCU software design based on RTX51 ). The author wrote it very well. I understood it in 10 minutes and started working on it. 

 

Build the environment

The project name is Wave.

First, create a good project directory structure. Each subdirectory should contain corresponding content. Otherwise, all files will be piled up under the project folder, and you will soon feel dizzy:

100 Folder Structure

In the picture above,

  • code put your own code
  • lib stores the code of external libraries
  • listing puts the intermediate files generated by Keil (memory address mapping of methods and variables, etc.)
  • Output: HEX file generated by Keil
  • document put document

This directory structure is different from the "directory" structure in Keil IDE (and does not need to be the same).

 

Then, open Keil IDE and create a new project, and put it in the directory just now:

101 New Project

Keil IDE has a trial version. The trial version has all the functions, the only limitation is that it can only compile target code within 2K.

 [page]

Select the chip library, I use STC here:

102 Select chip library

There is no STC chip in Keil's default chip library. You can add the STC chip library to Keil by following the steps below:

  • Download UV3.CDB from the Hongjing official website
  • Rename UV3.CDB to STC.CDB and copy it to the UV4 subdirectory of the Keil installation directory
  • Modify the TOOLS.ini file in the Keil installation directory and add the following above [C51]: CDB0=UV4STC.CDB("STC Chip")
  • Create a new project, and then you can select the corresponding chip database

(Personal note: This part can be done with the latest version of STC-ISP, tab "keil simulation settings", click "add STC simulation driver to Keil, add model and header file to Keil", it's simple and easy)

 

Then, select the chip:

103 Select chip model

When asked if you want to automatically include the startup code, select "No" (unless you want to change the program start address or something):

104 Is a startup code required?

 

Change the name of the Target to make it look better, and then set the project properties:

110 Set target properties

Enter the crystal frequency and select "RTX-51 Tiny" as the operating system, so that Keil will automatically compile the lib file into the output (it is better to use Small as the Memory Model to avoid writing data modifiers every time you declare variables):

111 Setting up the RTX-51 Tiny operating system

Then select the output and listing directories to the directory structure created earlier:

112 Select output directory

113 Select listing directory

Then, ignore the call warning message (this warning will remind you which functions are defined but not called, so annoying!):

114 Set to ignore warnings

Set the debugging options (STC12A5C60S2 supports ISD-51 online debugging, but it is not very useful in practice. The peripheral hardware module will not wait for you at the breakpoint. It is better to use software simulation debugging first):

115 Setting Debug

 

Next, drag the commonly used library files into the lib directory:

  • ISD51.h, ISD51.A51 are used for online debugging.
    They conflict with serial port 0, so use with caution.
  • stc12c51a.h MCU built-in header file
  • Conf_tny.A51
    RTX-51 Tiny configuration program

120 Place library files

Conf_tny.A51 still needs some modifications:

  • INT_CLOCK, defines the number of clock cycles corresponding to each timer interrupt, the default is 10000, I changed it to 1000;)
    This value will affect the length of the second parameter of os_wait. For example, ow_wait(K_TMO, 5, 0) waits for 5 timer cycles, that is, waits for 5000 clock cycles.
  • TIMESHARING, the number of clock interrupts assigned to each task. The default is 5.
    In this way, each task will be assigned a task time of 5000 clock cycles. After the expiration, the task will be suspended and other tasks in the READY state will run.
    If this value is 0, then the Round Robin task polling algorithm will stop, and you must manually os_send_signal or os_switch_task to switch tasks. Sometimes, this will improve real-time performance.
  • RAMTOP. Specifies the top address of the available RAM, the default is 0FFH, which is 256 bytes of RAM.
    For the STC chip, this default setting is fine when the task code is very short, but if the task code is long, it is recommended to change it to a smaller value, such as 0CFH. The reason is unknown, but it may be because the direct access method of the upper 128 bytes of RAM is a special register for reading and writing. I found that it conflicts with RTX-51 Tiny and generates  runtime errors such as error 65 access violation at 0x3480  .

 

Type a piece of code and run it first (software debugging, Ctrl+F5):

122 The first test code

You can see in the monitoring window that c0 and c1 are jumping randomly:

123 Run the first test code

Here is another piece of code to see Keil's advanced functions (logic analysis):

124 Enhanced first test code

Now you can see the waveform:

125 Debug enhanced first test code

The environment is ready, remember to submit it to the configuration library. Now you can start porting the code to the new RTX-51 Tiny-based project.


Keywords:RTX51-Tiny  C51  Keil Reference address:Build a C51 Keil project environment using RTX51-Tiny

Previous article:Summary of methods for setting header file paths in keil4
Next article:How to use IIC bus

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号