Build the C51 Keil project environment using RTX51-Tiny

Source: Internet
Author: User
ArticleDirectory
    • Operating System Selection
    • Build Environment

I have been studying stc12a5c60s2 single-chip microcomputer and Its Application in my spare time in the past month. It is used to relax the tension and mind after SharePoint every day. (It turns out that it's strange to relax !)

LCD 1602, LCD 12864 (parallel, serial), PCF 8563 (clock chip), nrf24l01 (Wireless Communication), matrix keyboard, ln 298 (H Bridge motor drive), coupled counters, HC-SR 04 (Ultrasonic Ranging), decided to give up the "idiot" based on interrupt, Timer cycle "multi-task"Program, On the operating system. Otherwise, it is almost impossible to write a slightly complex application later.

The following is the minimum stc12a5c60s2 single-chip microcomputer system that I use. It comes with a U-to-string chip and all Io ports. It is very convenient to debug the chips:

This kind of Small board has some disadvantages, that is, there is no installation hole, the whole board can only "float", and it is fixed by the tension of the dubang line (er, that is, it is not fixed :), so when using the car later, you can only weld the "Bracket" at the bottom and then install it on the cave board like this:

 

Operating System Selection

The initial consideration is uC/OS-II. It is very famous (often seen) and has strong functions (sounds like it), and the operating system is also introduced in the books I bought.

The US/OS-II Job Scheduling is a fully preemptible Job Scheduling Method Based on the job priority, the low-priority job being executed can be interrupted by a high-priority job 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 any task. Therefore, you must use the operating system.

As a result, I rummaged over the information on the Internet. US/OS-II is too complex XX, no web page can clearly say how to use. Also, US/OC-II to stc12a5c60s2 need to be transplanted (that is, you have to change his source code to adapt to the special circumstances of the hardware ). Er... ...

Then begin to consider the RTX-51. Because the C51 development tool Keil built-in RTX-51 operating system, and directly support the compilation and debugging in Keil, very attractive :)

The RTX-51 has 2 versions: full and tiny.

Full requires many resources, but supports preemptible task scheduling and interruption tasks, and sending messages between tasks. Tiny does not support preemptible scheduling and cannot send messages between tasks, however, it consumes less resources.

Although the full version is powerful, it takes up to 8 KB of ROM and requires at least 450 bytes of xdata! Stc12a5c60s2 only has 1024 bytes of On-Chip xdata Ram, And I want xdata to be used as LCD display. Think of, decisive choice of RTX-51 tiny.

Tiny version does not occupy xdata, and Ram is also very small (7 + 3 × number of tasks), which is more appropriate. As for the disadvantages, you can only use it to know. Tiny is open-source and the source code is assembly. Some people in China write their own operating systems, called small rtos51.

Chen Ming, author of small RTOS 51, said that he did not find a suitable single-chip microcomputer operating system. He wrote "in an angry manner" this advantage of having less resource occupation in the tiny version, an operating system that supports preemptible task scheduling. (If you are not happy, create one. This seems to be the fundamental motivation for the emergence of many cattle and New Technologies! Therefore, when there are no good wheels, you must invent new wheels by yourself .)

RTX-51 tiny is still very simple to use, online casually flip, immediately find the available guide (based on rtx51 SCM software design), the author writes very well, 10 minutes to understand, then start.

 

Build Environment

The project name is wave.

First, build the project directory structure. Put the corresponding content in each subdirectory. Otherwise, all the files are piled under the project folder and you will soon be dizzy:

As shown in the figure above,

    • Put your own codeCode
    • Lib: code used to store external Libraries
    • Listing stores the intermediate files generated by Keil (method, memory address ing of variables or something)
    • Output: store the Hex file generated by Keil.
    • Document 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 to create a new project and put it under the directory just now:

Keil ide has a trial version. The trial version has all functions, and the only limit is that only the target code within 2 kb can be compiled.

 

Select the chip library. Here I use STC:

The default Keil chip library does not contain the STC chip. You can add the STC chip library to Keil by following the steps below:

    • Download uv3.cdb from hongjing Official Website
    • Change 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: cdb0 = uv4 \ STC. CDB ("STC chip") at the top of [C51 ")
    • Create a new project and select the corresponding chip database.

Then, select the chip:

Ask if you need to automatically include the startup code and select "no" (unless you want to change the starting address of the program or something ):

 

Modify the target name, which looks nice, and then set the project properties:

Write the crystal oscillator frequency and select "RTX-51 tiny" as the operating system, so Keil will automatically compile the Lib file into the output (Memory Model with small better, to avoid data modification for each declared variable ):

Then select the output and listing directories to the preceding directory structure:

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

Set the debugging option (stc12a5c60s2 support ISD-51 for online debugging, however, the actual use is not very useful, the peripheral hardware module will not follow the breakpoint waiting for you, or use the software to simulate debugging well again ):

 

Next, drag the common library files to the lib directory:

    • Isd51.h, isd51.a51 for online debugging
      Conflict with serial port 0, use with caution
    • The header file of stc12c51a. h Microcontroller
    • Conf_tny.a51
      Configuration program for RTX-51 tiny

Conf_tny.a51 still needs to be modified:

    • Int_clock defines the number of clock cycles corresponding to each timer interrupt. The default value is 10000. I changed it to 1000 ;)
      This value affects the length of the second OS _wait parameter. For example, ow_wait (k_tmo, 5, 0) waits for five time cycles, that is, waiting for 5000 time cycles.
    • Timesharing: the number of clock interruptions for each task. The default value is 5.
      In this way, each task will be allocated with 5000 time cycles. After expiration, the task will be suspended and other tasks in ready status will run.
      If the value is 0, the round robin taskAlgorithmIt will stop. You must manually switch the task OS _send_signal or OS _switch_task. In some cases, this will improve real-time performance.
    • Ramtop. Specifies the top address of available Ram. The default value is 0 FFH, Which is 256 bytes RAM.
      For the STC chip, this default setting is no problem when the task code is very short for an hour. However, if the task code is too long, it is recommended to reduce it, such as 0cfh. The reason is unknown, but it may be because the direct access to 128-byte RAM is a special register for reading and writing, and I found that it will conflict with the RTX-51 tiny, an error such as error 65 access violation at 0x3480 is generated.

 

Run the following code (software debugging, CTRL + F5 ):

In the Monitoring window, C0 and c1 are displayed as follows:

Let's take a look at the advanced features (logical analysis) of Keil with code ):

Now you can view the waveform:

When the environment is ready, submit it to the configuration library. Now you can start porting code to a new RTX-51-based tiny project. ■

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.