S12 MCU module application and program download and debugging

Publisher:闪耀之星Latest update time:2011-10-17 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The MC9S12DG128 (hereinafter referred to as DG128) used in this Smart Car Invitational is an enhanced 16-bit microcontroller in the S12 series of microcontrollers launched by Freescale. It has rich on-chip resources and interface modules including SPI, SCI, IIC, A/D, PWM, etc. It has a wide range of uses in the field of automotive electronics applications. DG128 also has strong functions in Flash storage control and encryption, and encryption and decryption can be used in conjunction with third-party software.

The DG128 microcontroller uses an enhanced 16-bit HCS12 CPU, and the on-chip bus clock can reach up to 25MHz; on-chip resources include 8K RAM, 128K Flash, 2K EEPROM; SCI, SPI, PWM serial interface modules; the pulse width modulation module (PWM) can be set to 4 8-bit or 2 16-bit, and the logic clock selection frequency is wide. It includes two 8-channel 10-bit precision A/D converters, a controller area network module (CAN), an enhanced capture timer and supports background debugging mode. DG128 has two package forms: 112-pin and 80-pin. The 80-pin packaged microcontroller does not lead out a port for expansion, but only leads out an 8-channel A/D interface.

Common interface modules and external applications

PWM (Pulse Width Modulate) module: PWM pulse width modulation wave is a waveform that can be controlled by a program to control the waveform duty cycle, period, and phase. It is widely used in motor drive, D/A conversion and other occasions. The motor driver chip used in this Grand Prix is ​​MC33886, and its input signal is a PWM signal. MC33886 controls the direction and speed of the motor according to the period and duty cycle of the PWM signal. The servos used in the Grand Prix are also controlled by PWM. When the period of the PWM signal is greater than a certain threshold value, the servo can be driven to work. By maintaining the period and adjusting the PWM duty cycle, the direction of rotation of the servo can be adjusted. In the absence of specific parameters of the motor and servo, a PWM output program with adjustable period and duty cycle can be written for testing.

A/D (Analog/Digital) module: The A/D analog-to-digital conversion module can be divided into three parts: IP bus interface, conversion mode control/register list, and custom analog quantity. The IP bus interface is responsible for connecting the module to the bus to achieve the purpose of the A/D module and general I/O. The conversion mode control register list contains all the registers that control the module. The custom analog quantity is responsible for realizing the conversion from analog quantity to digital quantity. In order to synchronize the A/D conversion with the external signal, the A/D has an external trigger conversion channel, and the user can select the trigger mode (edge ​​trigger, level trigger).

The A/D module is equipped with a clock division mechanism. Users need to note that the maximum conversion clock of the A/D module is 2MHz, and the minimum conversion clock is 500KHz. Users need to check the internal bus clock of their own chips, and must make the conversion clock after division between the two, otherwise the correct conversion result may not be obtained. Users can set the conversion result to be signed or unsigned. For example, when Vrh is 5.12v and Vrl is 0v, the input is 5.12V, the 8-bit signed result is -$7F, and the unsigned result is $FF. The A/D module allows sequential conversion to be set, and the maximum sequential conversion sequence length is 8.

The A/D module may be used in the Grand Prix car model's recognition of the track. There are many implementation schemes for the front-end data acquisition system of the recognition circuit, such as infrared light-emitting diodes or CMOS cameras for data acquisition.

Codewarrior software usage

Codewarrior 3.1 for HCS12 is the recommended compiler software for the competition. "CodeWarrior for S12" is a software package for embedded application development of microcontrollers with HC12 or S12 as CPU. It includes integrated development environment IDE, processor expert library, full chip simulation, visual parameter display tool, project manager, C cross compiler, assembler, linker and debugger. In Codewarrior software, assembly language or C language, as well as mixed programming of the two languages ​​can be used.

After the project is created, the loading address needs to be defined. The default.prm file is used to define the loading address of the target code. The user should modify this file according to the memory allocation of the microcontroller. The .prm file automatically generated by CodeWarrior defaults the RAM of DG128 to:

RAM = READ_WRITE 0x0400 TO 0x1FFF;

This default range must be modified because there is 1K of I/O register space and 2K of EEPROM space in this space. Using the default definition will lose 1K RAM and 2K EEPROM.

We modify the RAM space in the monitoring program:

RAM = READ_WRITE 0x2000 TO 0x3FFF;

Of course, you can also modify it to:

RAM = READ_WRITE 0x1000 TO 0x2FFF.

Users are advised to adopt our definition.

Additionally, we use:

STACKTOP replaces STACKSIZE

Because STACKSIZE 0x100 leaves 0x100 space at the low end of RAM, and STACKTOP 0x3F00 can define SP to the high end of RAM. However, if this definition method is used, the definition needs to be modified to: RAM = READ_WRITE 0x2000 TO 0x3EFF when defining RAM in the previous step. In addition, the function in Start12.c in the project file needs to be:

void __interrupt 0 _Startup(void) Medium

#ifdef _HCS12_SERIALMON

.......

.......

#endif

Comment out the two macro commands, making the initialization statements for the EEPROM and RAM start position control registers valid. In this way, the program can run normally after downloading.

Download the user program using the monitoring program:

The main function of the monitor program is to debug the application system hardware and underlying software. It is also called the debug program and is the most basic debugging tool. The DG128 has 128K Flash and 8K RAM, while the monitor program source code occupies less than 3K FLASH and 23 bytes RAM. This does not have a big impact on the space of the user program. The asynchronous serial port is used for communication services with the PC. The monitor program can use it, and of course the application program can also use it.

Downloading user programs to on-chip resources is a basic function of the monitoring program. The code of the DG128-based monitoring program developed by the Freescale MCU & DSP Application Research and Development Center of Tsinghua University is less than 4KB, and the starting address is $F000. It moves the interrupt vector table of $FF80 to EF80, and the order remains unchanged. Users can use the interrupt vector table at $EF80. This interrupt vector table has the same order as the interrupt vector table in the MC9S12DG128 manual, except that it is moved from $FF80 to $EF80. When the monitoring program starts, if the serial port does not receive data within 4 seconds, it will check whether $EFFE-$EFFF (user reset vector table) is FFFF. If not, it means that there is a user program in FLASH, and the program automatically switches to the user program pointed to by $EFFE-$EFFF. If the serial port receives data within 4 seconds after the program starts or $EFFE-$EFFF is $FFFF, the DEBUG monitoring program is entered. In this monitoring program, the F command downloads the program to FLASH, and can recognize S19 files in S1 or S2 format. After pressing the "F" key, the MCU on the development board waits to receive the data file from the serial port. Then select "Send" → "Send Text File", find the *.S19 file to be downloaded, and press "Open (O)". In this way, the file is downloaded to the FLASH. Note that the file type should be "All Files". When the prompt appears again, it means that the program has been downloaded.

Start running the program from the address of the PC register. You can use the Ctrl+P command to modify the PC pointer to the starting address of the program to be run. If it is an assembled code, you can start executing from the download address; but if it is a code compiled by C language, you need to add the address after 29 before executing it. This is because the project starts from START12.C and then executes the user's main.c. This is the internal regulation of CodeWarrior. Users only need to know it. The entry address of the user program is the code address defined by the user in the default.prm file plus 29. Then type the "G" command. At this time, the user program can be executed. If the user program cannot jump out of the main loop, press the reset button when you need to stop the user program.

Reference address:S12 MCU module application and program download and debugging

Previous article:Realization of communication between touch screen and single chip microcomputer
Next article:Temperature controller based on 8-bit single chip microcomputer

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号