Application and program download and debugging of

  • Detail

The MC9S12DG128 (hereinafter referred to as DG128) used in this smart car Invitational is an enhanced 16 bit single chip microcomputer in the S12 series single chip microcomputer launched by Freescale company. The on-chip resources are rich, and the interface modules include SPI, SCI, IIC, a/d, PWM, etc., which are widely used 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 with third-party software

dg128 MCU adopts enhanced 16 bit HCS12 CPU, and the on-chip bus clock can reach 25MHz at most; On chip resources include 8K ram, 128K flash and 2K EEPROM; SCI, SPI, PWM serial interface module; The pulse width modulation module (PWM) can be set to 4 channels of 8 bits or 2 channels of 16 bits, and the logical clock has a wide selection frequency. It includes two 8-way 10 bit precision a/d converters, controller area module (can), and enhanced capture fixed UTM. It can also be used in product quality control timers and support background debugging mode. DG128 has two packaging forms: 112 pin and 80 pin. The single chip microcomputer in 80 pin package does not lead to the port for expansion, but only leads to an 8-way a/d interface

common interface module and external application

pwm (pulse width modulated) module: PWM pulse width modulated wave is a waveform that can be programmed to control the duty cycle, period and phase of the waveform. 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 steering and speed of the motor according to the cycle and duty cycle of PWM signal. The steering gear used in the Grand Prix is also controlled by PWM. After the period of PWM signal is greater than a certain domain value, the steering gear can be driven to work. Maintaining the period and adjusting the duty cycle of PWM can adjust the rotation direction of the steering gear. In the absence of specific parameters of motor and actuator, carbon dioxide or methane can be directly converted into green substrate, and a PWM output program with adjustable cycle 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 the connection between the module and the bus to realize the purpose of a/d module and general i/o. The list of conversion mode control registers contains all registers that control the module. Custom analog quantity is responsible for the conversion from analog quantity to digital quantity. In order to perform a/d conversion synchronously with external signals, a/d has an external trigger conversion channel, and the user can choose the trigger mode (edge trigger, level trigger)

a/d module is equipped with clock frequency division mechanism. It should be noted 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 chip. They must make the conversion clock after frequency division between the two, otherwise they may not get the correct conversion result. You can set the conversion result to signed or unsigned numbers. For example, when VRH is 5.12v and VRL is 0V, enter 5.12v, the 8-bit signed result is - $7f, and the unsigned result is $ff. The a/d module allows setting sequence conversion, and the maximum sequence length of sequence conversion is 8

the a/d module may be used in the recognition of the runway by the car model in the Grand Prix. There are many implementation schemes for the front-end data acquisition system of the recognition circuit, such as infrared LED or CMOS camera for data acquisition

codewarrior software uses

CodeWarrior 3.1 for HCS12 as the recommended program compilation software in the competition. CodeWarrior for S12 is a software package for embedded application development of single chip microcomputer with hc12 or S12 as CPU. It includes IDE, processor expert library, full chip simulation, visual parameter display tool, project manager, C cross compiler, assembler, linker and debugger. Assembly language or C language and mixed programming of the two languages can be used in CodeWarrior software. After the project is established, the loading address needs to be defined. M file is used to define the loading address of the object code. Users should modify this file according to the memory allocation of the single chip microcomputer. CodeWarrior is automatically generated By default, the ram of DG128 in PRM file is:

ram = read_ WRITE 0x0400 TO 0x1FFF;

this default interval must be modified because there are 1K i/o register space and 2K EEPROM space in this space. Using the default definition will lose 1K ram and 2K EEPROM

we modify RAM space in the monitor program:

ram = read_ Write 0x2000 to 0x3f such a query time will be very slow and may not be satisfied with the user's needs FF

of course, it can also be modified to:

ram = read_ WRITE 0x1000 TO 0x2FFF。

users are advised to adopt our definition

in addition, we use:

stacktop to replace stacksize

because stacksize 0x100 leaves 0x100 space at the low end of ram, while using stacktop 0x3f00 can define SP to the high end of ram. However, if this method of definition is adopted, the definition of ram needs to be modified to ram=read when defining ram previously_ WRITE 0x2000 TO 0x3EFF。 In addition, for start12 in engineering documents Functions in C:

void__ interrupt 0 _

ifdef in startup (void)_ HCS12_ SERIALMON



The two macro commands


are commented out, which makes the initialization statement of ram start position control register valid for EEPROM. In this way, the program can run normally after downloading

use the monitor program to download user programs:

the main function of the monitor program is to debug the application system hardware and underlying software, also known as the debug program, which is the most basic debugging tool. The flash of DG128 has 128K and ram has 8K, while the source code of the monitoring program occupies less than 3K flash and 23 bytes of ram. This has little impact on the space of user programs. The serial port of different active access Internet step is used to communicate with PC. the monitoring program can be used, and the application program can also be used

downloading user programs to on-chip resources is the basic function of the monitoring program. The monitoring program code based on DG128 developed by Tsinghua University Freescale MCU DSP application research and development center 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. The user can use the interrupt vector table at $ef80. This interrupt vector table is in 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 is up, 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 will automatically transfer to the user program pointed by $effe-$efff. If the serial port receives data within 4 seconds after the program gets up or $effe-$efff is $ffff, enter the debug monitoring program. The f command in the monitoring program downloads the program to flash, and S19 files in S1 or S2 format can be recognized. 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 and find the * S19 file, press open (o), so that the file can be downloaded to flash. Note that the document type should be all documents. When the prompt appears again, it indicates that the program has been downloaded

start 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 the code is assembled, it can be executed from the download address; However, if the code is compiled by C language, it needs to add the address after 29 before execution. This is because the project is from start12 C starts to execute, and then executes the user's main c。 This is an internal regulation of CodeWarrior. Users only need to know. The entry address of the user program is the code address defined by the user in the m file plus 29. Then type the G command. Then the user program can be executed. If the user program cannot jump out of the main cycle, just press the reset key when you need to stop the user program

Copyright © 2011 JIN SHI