ece 2510/4510/5530 hc12 microprocessor

46
ECE 2510/4510/5530 ECE 2510/4510/5530 HC12 Microprocessor D-Bug12 Functions: Stepping Through Programs & Performing I/O Dr. Bradley J. Bazuin Associate Professor Associate Professor Department of Electrical and Computer Engineering College of Engineering and Applied Sciences

Upload: others

Post on 17-Jun-2022

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ECE 2510/4510/5530 HC12 Microprocessor

ECE 2510/4510/5530ECE 2510/4510/5530 HC12 Microprocessor

D-Bug12 Functions:Stepping Through Programs

& Performing I/O

Dr. Bradley J. BazuinAssociate ProfessorAssociate Professor

Department of Electrical and Computer EngineeringCollege of Engineering and Applied Sciences

Page 2: ECE 2510/4510/5530 HC12 Microprocessor

Basic D-Bug12 Debugging Operationsg gg g p

• Executing a program starting at an instruction (g 122A)g p g g (g )• Executing a program until some critical instruction, go

until (gt <addr>)– Also <RegisterName> and <RegisterName> <RegisterValue>

• Tracing program execution (t) • Setting and clearing program breakpoints (br nobr)• Setting and clearing program breakpoints (br, nobr)• Modifying (mm, mmw) and displaying (md, mdw)

memory locations– Also a block fill (bf) command for multiple locations– Also move a block of memory (move)

• Modifying (rm) and displaying (rd) registersECE 2510 2

• Modifying (rm) and displaying (rd) registersGordon Doughman, Reference Guide for D–Bug12 Version 4.x.x,

Freescale Semiconductor, April 4, 2005.

Page 3: ECE 2510/4510/5530 HC12 Microprocessor

D-Bug12 Command Summary (1)g y ( )

• ALTCLK - Specify an alternate BDM communications rate. 22• ASM - Single line assembler/disassembler. 24g• BAUD - Set the SCI communications BAUD rate. 28• BDMDB - Enter the BDM command debugger. 29• BDMPGMR - Load BDM Programmer Firmware Image Into MCU Flash 30• BF - Block Fill user memory with data. 32• BR - Set/Display user breakpoints. 33

BS Bl k S h S h Add R F A D P 35• BS - Block Search, Search an Address Range For A Data Pattern 35• BULK - Bulk erase on-chip EEPROM 37• CALL - Execute a user subroutine, return to D-Bug12 when finished. 38• DEVICE - Select/define a new target MCU device. 39• EEBASE - Inform D-Bug12 of the target’s EEPROM base address 42• FBULK - Erase the target processor’s on-chip Flash EEPROM 44• FBULK - Erase the target processor s on-chip Flash EEPROM 44• FLOAD - Program the target processor’s on-chip Flash EEPROM from S-Records 46• FSERASE - Erase one or more sectors of target Flash 49• G - Go. Begin execution of user program. 51• GT - Go Till. Set a temporary breakpoint and begin execution of user program. 52• HELP - Display D-Bug12 command set and command syntax. 53p y g y• LOAD - Load user program in S-Record format. 55• MD - Memory Display. Display memory contents in hex bytes/ASCII format. 57• MDW - Memory Display Words. Display memory contents in hex words/ASCII format. 58• MM - Memory Modify. Interactively examine/change memory contents. 59• MMW - Memory Modify Words. Interactively examine/change memory contents. 60

ECE 2510 3Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 4: ECE 2510/4510/5530 HC12 Microprocessor

D-Bug12 Command Summary (2)g y ( )

• MOVE - Move a block of memory. 61• NOBR - Remove one/all user breakpoints 62NOBR Remove one/all user breakpoints. 62• PCALL - Execute a user subroutine in expanded memory, return to D-Bug12 when finished. 63• RD - Register Display. Display the CPU register contents. 64• REGBASE - Inform D-Bug12 of the target’s I/O register’s base address 65• RESET - Reset the target CPU 67

RM R i M dif I i l i / h CPU i 68• RM - Register Modify. Interactively examine/change CPU register contents. 68• SETVFP - Sets nominal Vfp Voltage to 12.0 or 12.6 volts. 69• SO - Step over subroutine calls. 71• STOP - Stop the execution of user code in the target processor and place the target processor in

background mode. 72• T - Trace. Execute an instruction, disassemble it, and display the CPU registers. 73• TCONFIG - Configure target before erasing or programming target Flash 74• UPLOAD - Display memory contents in S-Record format. 75• USEHBR - Use EVB/Target Hardware breakpoints. 77• VER - Display the running version of D-Bug12 78VER - Display the running version of D-Bug12 78• VERF - Verify memory contents against S-Record Data. 79• <RegisterName> <RegisterValue> - Set CPU <RegisterName> to <RegisterValue> 81

ECE 2510 4Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 5: ECE 2510/4510/5530 HC12 Microprocessor

D-Bug12 Operation Gg p

• Go, execute the code starting at the current or a specified , g paddress (execute until swi, reset or a breakpoint)– Execute the following line after the code has been downloaded

G 122A<CR>G 122A<CR>– D-Bug12 will execute program from 122A until an swi in the code,

the reset button is pressed, or a user set breakpoint is encountered. It will then stop print the register values with the next PC valueIt will then stop, print the register values, with the next PC value and next instruction to be executed.

ECE 2510 5Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 6: ECE 2510/4510/5530 HC12 Microprocessor

Go (G) Command( )G - Begin execution of user code• Command Line Format• Command Line Format

G [<Address> | <PPAGENum>:<PPAGEWinAddr>]• Parameter Description

<Address>A 16-bit hexadecimal number or simple expression<PPAGENum> - An 8-bit hexadecimal number or simple expression<PPAGEWinAddr> - A 16-bit hexadecimal number or simple expression

• Command DescriptionThe G command is used to begin the execution of user code in real time Before– The G command is used to begin the execution of user code in real time. Before beginning execution of user code, any breakpoints set using the BR command are placed in memory. Execution of the user program will continue until a user breakpoint is encountered, a CPU exception occurs or the reset switch on the HC12EVB is pressed. When user code halts for one of these reasons and control is preturned to D-Bug12, a message is displayed explaining the reason for program termination. In addition, D-Bug12 displays the CPU12’s register contents, disassembles the instruction at the current PC address, and waits for the next DBug12 command to be entered by the user.If i dd i li d i h d li

ECE 2510 6

– If a starting address is not supplied in the command line parameter, program execution will begin at the address defined by the current value of the Program Counter. Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x,

Freescale Semiconductor, April 4, 2005.

Page 7: ECE 2510/4510/5530 HC12 Microprocessor

D-Bug12 Operation Tg p

• Trace program executionp g– First, set the PC to the program start address $122a

PC 122A<CR>Type in T and <CR> and D Bug12 will execute the instruction at– Type in T and <CR> and D-Bug12 will execute the instruction at the PC and then print the register values, with the next PC value and next instruction to be executed.Repeat a desired– Repeat a desired

PC 122A<CR>T<CR>

To trace m ltiple instr ctions at a time t pe T (n mber)<CR>– To trace multiple instructions at a time, type T (number)<CR>PC 122A<CR>T 10<CR>

ECE 2510 7Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 8: ECE 2510/4510/5530 HC12 Microprocessor

Trace (T) Command( )

T - Trace (Execute) CPU12 Instruction(s)• Command Line Format

T [<Count>]

• Parameter Description• Parameter Description<Count> An 8-bit decimal number in the range 1..255

• Command Descriptionp– The Trace command is used to execute one or more user program

instructions beginning at the current Program Counter (PC) location. As each program instruction is executed, the CPU12’s p g ,register contents are displayed and the next instruction to be executed is displayed.

– A single instruction may be executed by entering the trace

ECE 2510 8

g y y gcommand followed immediately by a carriage.

Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 9: ECE 2510/4510/5530 HC12 Microprocessor

D-Bug12 Operation GTg p

• Go until a specific address is reached (a breakpoint)p ( p )– First, set the PC to the program start address $122a

PC 122A<CR>Type in GT (command address) <CR> and D Bug12 will execute– Type in GT (command address) <CR> and D-Bug12 will execute program from 122A until the specified address. It will then stop, print the register values, with the next PC value and next instruction to be executed. You may then trace (T) or repeat GT.instruction to be executed. You may then trace (T) or repeat GT.

– Go Until a desired addressPC 122A<CR>GT 1234<CR>GT 1234<CR>

ECE 2510 9Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 10: ECE 2510/4510/5530 HC12 Microprocessor

Go Until (GT) Command( )

GT - Go Until, Execute user code until temporary breakpoint is reachedC d Li F t• Command Line FormatGT <Address> | <PPAGENum>:<PPAGEWinAddr>

• Parameter Description<Address>A 16 bit hexadecimal number or simple expression<Address>A 16-bit hexadecimal number or simple expression<PPAGENum> - An 8-bit hexadecimal number or simple expression<PPAGEWinAddr> - A 16-bit hexadecimal number or simple expression

• Command DescriptionCommand Description– The GT command is similar to the G command except that a temporary breakpoint

is placed at the address supplied on the command line. Any breakpoints set by the BR command are NOT placed in the user’s code before program execution begins. Program execution begins at the address defined by the current value of theProgram execution begins at the address defined by the current value of the Program Counter. When user code reaches the temporary breakpoint and control is returned to D-Bug12, a message is displayed explaining the reason for user program termination. In addition, D-Bug12 displays the CPU12’s register contents, disassembles the instruction at the current PC address, and waits for the next D-B 12 d t b t d b th

ECE 2510 10

Bug12 command to be entered by the user.

Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 11: ECE 2510/4510/5530 HC12 Microprocessor

D-Bug12 OperationsBR d NOBRBR and NOBR

Helpful debugging hints:p gg g• Breakpoints that cause the code to stop at one or more

specific locations may be set. – To set a breakpoint, provide the appropriate instruction address

BR 1234<CR>BR 1242<CR>G 122A

– D-Bug12 will execute program from 122A until a breakpoint address or swi is encountered.

• One or all breakpoints can be removed using NOBRNOBR 1234<CR>NOBR <CR>

ECE 2510 11

NOBR CR

Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 12: ECE 2510/4510/5530 HC12 Microprocessor

Breakpoint (BR) Commandp ( )BR - Set/Display User Breakpoints• Command Line Format• Command Line Format

BR [<Address> | <PPAGENum>:<PPAGEWinAddr>…]• Parameter Description

<Address>A 16-bit hexadecimal number or simple expression<PPAGENum> - An 8-bit hexadecimal number or simple expression<PPAGEWinAddr> - A 16-bit hexadecimal number or simple expression

• Command DescriptionThe BR command is used to set a breakpoint at a specified address or to display– The BR command is used to set a breakpoint at a specified address or to display any previously set breakpoints. The function of a breakpoint is to halt user program execution when the program reaches the breakpoint address. When a breakpoint address is encountered, D-Bug12 will disassemble the instruction at the breakpoint address, print the CPU12’s register contents, and wait for the next D-Bug12 command to be entered by the usercommand to be entered by the user.

– Breakpoints are set by entering the breakpoint command followed by one or more breakpoint addresses. Entering the breakpoint command without any breakpoint addresses will display all the currently set breakpoints.

– A maximum of 10 breakpoints may be set at one time when using software

ECE 2510 12

p y gbreakpoints (default).

Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 13: ECE 2510/4510/5530 HC12 Microprocessor

No Breakpoints (NOBR) Commandp ( )

NOBR - Remove one/all user breakpointsC d Li F t• Command Line FormatNOBR [<Address> | <PPAGENum>:<PPAGEWinAddr>…]

• Parameter Description<Address>A 16 bit hexadecimal number or simple expression<Address>A 16-bit hexadecimal number or simple expression<PPAGENum> - An 8-bit hexadecimal number or simple expression<PPAGEWinAddr> - A 16-bit hexadecimal number or simple expression

• Command DescriptionCommand Description– The NOBR command is used to remove one or more of previously entered

breakpoints. If the NOBR command is entered without any arguments, all user breakpoints are removed from the breakpoint table.

ECE 2510 13Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 14: ECE 2510/4510/5530 HC12 Microprocessor

D-Bug12 Operation MDg p

• Display memory in hexadecimal bytes and ASCII formatp y y y– Display the values in memory 1000:100F while in the debug mode

of operationMD 1000 <CR>MD 1000 CR

– The debugger will respond with the start address requested, the next 16 memory bute values in hex, and then the ASCII equivalents of the memory locations.equivalents of the memory locations.

• The ASCII fields are useful if the memory is supposed to be ASCII characters. If not, it looks like a mess ….

– Alternate commandAlternate commandMD 1000 11FF <CR>

– The debugger will respond with all memory bytes from 1000 to 11FF.

ECE 2510 14

11FF.

Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 15: ECE 2510/4510/5530 HC12 Microprocessor

Memory Display (MD) Commandy p y ( )

MD - Display memory in hexadecimal bytes and ASCII format• Command Line Format

MD <StartAddress> [<EndAddress>]• Parameter DescriptionParameter Description

<StartAddress> A 16-bit hexadecimal number or simple expression<EndAddress> A 16-bit hexadecimal number or simple expression

• Command Description• Command Description– The memory display command displays the contents of memory in both

hexadecimal bytes and ASCII, 16-bytes on each line. The <StartAddress> parameter must be supplied, however, the <EndAddress> parameter is optional. Wh th E dAdd t i t li d i l li i di l d (16When the <EndAddress> parameter is not supplied, a single line is displayed (16 bytes).

– The number supplied as the <StartAddress> parameter is rounded down to the next lower multiple of 16. While the number supplied as the <EndAddress> parameter is

ECE 2510 15

rounded up to the next higher multiple of 16 - 1.

Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x,Freescale Semiconductor, April 4, 2005.

Page 16: ECE 2510/4510/5530 HC12 Microprocessor

D-Bug12 Operation MMg p

• Modify memory bytes in hexadecimal formaty y y– Modify memory byte values beginning at a starting address

MM 1000 <CR>The debugger will respond with the address requested and the byte– The debugger will respond with the address requested and the byte value. The value can be modified by typing in a new value and hitting a <CR>. The memory will be modified and the next address will be printed to continue sequential modifications. If there are nowill be printed to continue sequential modifications. If there are no more modification, type a period (,) <CR>

– To control the modification point displayed next, use:• [<Data>]<CR> update current location and display the next location[ Data ] CR update current location and display the next location• [<Data>] / or = update current location and redisplay the current location• [<Data>] ^ or - update current location and display the previous location• [<Data>] . update current location and exit Memory Modify

ECE 2510 16Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 17: ECE 2510/4510/5530 HC12 Microprocessor

Memory Display (MM) Commandy p y ( )

MM - Modify memory bytes in hexadecimal format• Command Line Format

MM <Address> [<data>]• Parameter Description

<Address> A 16-bit hexadecimal number or simple expression<Address> A 16-bit hexadecimal number or simple expression.<data> An 8-bit hexadecimal number.

• Command Description– The memory modify word command allows the contents of memory to be examined and/or

modified as 8 bit hexadecimal data If the 8 bit data parameter is present on the command linemodified as 8-bit hexadecimal data. If the 8-bit data parameter is present on the command line, the byte at memory location at <Address> is replaced with <data>. If not, D-Bug12 will enter the interactive memory modify mode. In the interactive mode, each byte is displayed on a separate line following the data's address.

– Once the memory modify command has been entered, several sub-commands are used for the difi ti d ifi ti f t t Th b d h th f ll imodification and verification of memory contents. These sub-commands have the following

format:[<Data>]<CR> Optionally update current location and display the next location[<Data>] / or = Optionally update current location and redisplay the current location[<Data>] ^ or - Optionally update current location and display the previous location

ECE 2510 17

[<Data>] . Optionally update current location and exit Memory Modify

Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 18: ECE 2510/4510/5530 HC12 Microprocessor

D-Bug-12 Operation RDg p

• Display CPU12 Register Contentsp y g– Display the contents of the CPU12 registers.

RD <CR>The debugger response 1st line is the register names the second– The debugger response 1st line is the register names, the second line is the registre contents, and the third line is the current PC, machine language command and disassembled command.

• It tells you what is in the registers and what the next instruction to beIt tells you what is in the registers and what the next instruction to be executed is.

ECE 2510 18Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 19: ECE 2510/4510/5530 HC12 Microprocessor

Register Display (RD) Commandg p y ( )

RD - Display CPU12 Register Contentsp y g• Command Line Format

RD

• Parameter DescriptionNot applicable

• Command Description• Command Description– The Register Display command is used to display the CPU12’s

registers. The registers are displayed in the same format used when a breakpoint is encountereda breakpoint is encountered.

ECE 2510 19Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 20: ECE 2510/4510/5530 HC12 Microprocessor

D-Bug-12 Operation RMg p

• Interactively Modify CPU12 Register Contentsy y g– Modify the contents of the CPU12 registers.

RM <CR>The debugger response sequentially with each of the registers If– The debugger response sequentially with each of the registers. If you want to modify it, provide a value. If not, step to the next one with a <CR> or exit the modification mode with a period (.)

ECE 2510 20Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 21: ECE 2510/4510/5530 HC12 Microprocessor

Register Modify (RM) Commandg y ( )

RM - Interactively Modify CPU12 Register Contents• Command Line Format

Rm• Parameter DescriptionParameter Description

Not applicable• Command Description

– The register modify command is used to examine and/or modify the contents of theThe register modify command is used to examine and/or modify the contents of the CPU12's registers in an interactive manner. As each register and its contents is displayed, D-Bug12 allows the user to enter a new value for the register in hexadecimal. If modification of the displayed register is not desired, entering a carriage return causes the next CPU12 register and its contents to be displayed oncarriage return causes the next CPU12 register and its contents to be displayed on the next line. Typing a period (.) as the first non space character on the line will exit the interactive mode of the register modify command and return to the D-Bug12 prompt.The registers are displayed in the following order one register per line: PC SP X

ECE 2510 21

– The registers are displayed in the following order, one register per line: PC, SP, X, Y, A, B, CCR.

Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 22: ECE 2510/4510/5530 HC12 Microprocessor

<RegisterName> <RegisterValue> Command (1 of 2)Command (1 of 2)

<RegisterName> - Modify a CPU12 Register Value• Command Line Format

– <RegisterName> <RegisterValue>• Parameter Description

– Where <RegisterName> is one of the following CPU12 register names:Register Name Description Legal Range• PC Program Counter $0..$FFFF• SP Stack Pointer $0..$FFFF• X X-Index Register $0..$FFFF• Y Y-Index Register $0..$FFFF• A A Accumulator $0..$FF• B B Accumulator $0..$FF

D D A l t (A B) $0 $FFFF• D D Accumulator (A:B) $0..$FFFF• CCR Condition Code Register $0..$FF• PP PPAGE Register $0..$FF

– For each of the CPU register names, <RegisterValue> may be a hexadecimal number or a simple expression

ECE 2510 22

number or a simple expression.

Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 23: ECE 2510/4510/5530 HC12 Microprocessor

<RegisterName> <RegisterValue> Command (2 of 2)Command (2 of 2)

<RegisterName> - Modify a CPU12 Register Value• Command Line Format

– <RegisterName> <RegisterValue>• Parameter Description

– Each of the fields in the CCR may also be modified by using the following field Names:

CCR Bit Name Description Legal Range• S STOP Enable 0..1• H Half Carry 0..1• N Negative Flag 0..1• Z Zero Flag 0..1• V Overflow Flag 0..1

C C Fl 0 1• C Carry Flag 0..1• IM IRQ Interrupt Mask 0..1• XM XIRQ Interrupt Mask 0..1

– For the CCR bit names only a value of zero or one may be supplied for the <RegisterValue> parameter

ECE 2510 23

<RegisterValue> parameter.

Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 24: ECE 2510/4510/5530 HC12 Microprocessor

D-Bug-12 Operation ASMg p

• Single Line Assembler/Disassembler Commandg– Disassemble the machine language to assembly language with

absolute addresses and values inserted for variables and labels ASM 122A <CR>ASM 122A CR

– This allows you to compare your original code to the code in the CPU12 that will execute.

• All conveniences of the assembly language are removed So theAll conveniences of the assembly language are removed. So the actual hexadecimal variable values, label addresses, and branch offset values are shown. This is what the machine is really running!

ECE 2510 24Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 25: ECE 2510/4510/5530 HC12 Microprocessor

Assemble/Disassemble (ASM) Command (1)Command (1)

ASM - Single Line Assembler/Disassembler Command• Command Line Format

ASM <Address> | <PPAGENum>:<PPAGEWinAddr>• Parameter Description

<Address> - A 16-bit hexadecimal number or simple expression<PPAGENum> - An 8-bit hexadecimal number or simple expression<PPAGEWinAddr> - A 16-bit hexadecimal number or simple expression

C d D i i• Command Description– The assembler/disassembler is an interactive memory editor that allows

memory contents to be viewed and altered using assembly language mnemonics. Each entered source line is translated into machine language g gcode and placed into memory at the time of entry. When displaying memory contents, each instruction is disassembled into its source mnemonic form and displayed along with the hexadecimal machine code and any instruction operands.

ECE 2510 25

y p

Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x,Freescale Semiconductor, April 4, 2005.

Page 26: ECE 2510/4510/5530 HC12 Microprocessor

Assemble/Disassemble (ASM) Command (2)(2)

ASM - Single Line Assembler/Disassembler CommandDi bl C d D i ti• Disassembler Command Description

– When displaying memory contents, each instruction is disassembled into its source mnemonic form and displayed along with the hexadecimal machine code and any instruction operands.

– When an instruction has been disassembled and displayed, the D-Bug12 prompt is displayed following the disassembled instruction. If a carriage return is entered immediately following the

t th t i t ti i i di bl d d di l d th t liprompt, the next instruction in memory is disassembled and displayed on the next line.• Assembler Command Description

– Assembler mnemonics and operands may be entered in any mix of upper and lower case letters. Any number of spaces may appear between the assembler prompt and the instruction mnemonic or between the instruction mnemonic and the operand. By default, numeric values appearing in h d fi ld i d i d d i l b l i $ i f f bthe operand field are interpreted as signed decimal numbers. Placing a $ in front of a number

will cause the number to be interpreted as a hexadecimal number.– If a CPU12 instruction is entered following the prompt, the entered instruction is assembled and

placed in memory. The line containing the new entry is erased and the new instruction is disassembled and displayed on the same line. The contents of the next memory location(s) is disassembled and displayed on the screendisassembled and displayed on the screen.

– The instruction mnemonics and operand formats accepted by the assembler follow the syntax as described in the M68HC12 Family CPU12 Reference Manual..

ECE 2510 26Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 27: ECE 2510/4510/5530 HC12 Microprocessor

DEBUG-12 SUBROUTINESDEBUG 12 SUBROUTINES

ECE 2510 27Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 28: ECE 2510/4510/5530 HC12 Microprocessor

D-Bug12 Functions to Perform I/Og

• D-Bug12 monitor provides a few subroutines to support g p ppI/O operations– I/O routines can be utilized to facilitate program developments on

a demo board that contains the D-Bug12 monitora demo board that contains the D-Bug12 monitor

• User accessible routines are written in C– All except the first parameter are passed to the user callable

functions on the stack– Parameters are to be pushed in the reverse order they are listed in

the function declaration– First parameter is passed to the function in D accumulator

ECE 2510 28Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 29: ECE 2510/4510/5530 HC12 Microprocessor

User Accessible Utility Functionsy

ECE 2510 29Note: far name must use CALL others use JSR

Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 30: ECE 2510/4510/5530 HC12 Microprocessor

D-Bug12 Functions to Perform I/Og

• Parameter Restrictions– Parameters of type char must be converted to an integer– Parameters of type char will occupy the lower order byte of a word

pushed onto the stack or accumulator B if the parameter is passedpushed onto the stack or accumulator B if the parameter is passed in D accumulator

– All 8-bit and 16-bit function values are returned in accumulator DA value of type char returned in accumulator D is located in the 8– A value of type char returned in accumulator D is located in the 8-bit accumulator B

• None of the CPU registers contents, except the stack pointer are preserved by the called functions– Register values needs to be pushed onto the stack before any

parameters have been pushed onto the stack and should be restored

ECE 2510 30

after de-allocating the parametersGordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4,

2005.

Page 31: ECE 2510/4510/5530 HC12 Microprocessor

Calling D-Bug12 Functions from A blAssembly

• Calling the functions from assembly involvesg y– Pushing the parameters onto the stack in the proper order– Loading the first or only function parameter into accumulator D

Calling the D Bug12 function with a JSR instruction– Calling the D-Bug12 function with a JSR instruction– Code following the JSR instruction should remove any parameters

pushed onto the stack

• Addressing mode used in the JSR instruction is Indexed Indirect Addressing Mode

Ex: JSR [getchar,PCR] PCR is an index register X

ECE 2510 31Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 32: ECE 2510/4510/5530 HC12 Microprocessor

Functions Called using JSR g

Function Description Pointer Address

getchar() Get a character from SCI0 or SCI1 $EE84 putchar() Send a character out SCI0 or SCI1 $EE86 printf() Formatted Output - Translates binary values to characters $EE88 isxdigit() Checks for membership in the set [0..9, a..f, A..F] $EE92s d g t() C ec s o e be s p t e set [0..9, a.. , .. ] $ 9toupper() Converts lower case characters to upper case $EE94 isalpha() Checks for membership in the set [a..z, A..Z] $EE96 strlen() Returns the length of a null terminated string $EE98 strcpy() Copies a null terminated string $EE9Astrcpy() Copies a null terminated string $EE9ASetUserVector() Setup user interrupt service routine $EEA4

• Basic IO functions with a few additions

ECE 2510 32Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 33: ECE 2510/4510/5530 HC12 Microprocessor

getcharg

Int getchar (void)g ( )• Pointer Address: $EE84

– This function receives a single character from the control terminal (S i l C i ti I t f k b d)(Serial Communication Interface or keyboard)

– The character is returned as an integer, the 8-bit character is placed in accumulator B

ECE 2510 33Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 34: ECE 2510/4510/5530 HC12 Microprocessor

Example of getchar Functionp g

• Ex:Getchar = $EE84------------------Jsr [getchar,x]------------

• This code will read one character typed on the keyboardThis code will read one character typed on the keyboard

ECE 2510 34Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 35: ECE 2510/4510/5530 HC12 Microprocessor

putcharp

Int putchar(int)• Pointer Address: $EE86

– This function outputs a single character to the control terminal Serial Communication interfaceSerial Communication interface

Ex:Putchar = $EE86--------Ldd #$32Jsr [putchar,x]---

• Output one ASCII character to the terminal ( a 2 is printed)ECE 2510 35

• Output one ASCII character to the terminal ( a 2 is printed)Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4,

2005.

Page 36: ECE 2510/4510/5530 HC12 Microprocessor

printfp

Int printf(char *format,----------)p ( , )• Pointer Address: $EE88

– This function is used to convert, format and print its argument on th t d d t t it LCD d th t l f th f tthe standard output monitor, LCD under the control of the format string pointed to by format.

– All except floating-point data types are supported.

• The format string contains two basic types of objects: – ASCII characters which will be copied directly to the display

device.– Conversion specifications. Each conversion specification begins

with a percent sign (%).

ECE 2510 36Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 37: ECE 2510/4510/5530 HC12 Microprocessor

printf Optional Formattingp p g

• Conversion specifications. Each conversion specification begins with a percent sign (%).

• Optional formatting characters may appear between the percent sign and ends with a single conversion character in the following order: [-][<FieldWidth>][.][<Precision>][h | l]

ECE 2510 37Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 38: ECE 2510/4510/5530 HC12 Microprocessor

printf Conversion Charactersp

• This set is universal to applications based on C (e.g. MATLAB)

ECE 2510 38

pp ( g )

Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 39: ECE 2510/4510/5530 HC12 Microprocessor

printf Examplep p

printf = $EE88prompt: .asciz “Flight Simulation\n”--------ldd #promptjsr [printf,x]--------

• This instruction sequence will cause the message “Flight Simulation” to be displayed and cursor will be moved toSimulation to be displayed and cursor will be moved to the beginning of next line.

ECE 2510 39Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 40: ECE 2510/4510/5530 HC12 Microprocessor

printf Example 2p p

• Suppose labels m, n and gcd represent three memory locations pp , g p yand gcd holds greatest common divisor and m ,n represent the two numbers

printf = $EE88printf = $EE88prompt .asciz “The Greatest Common Divisor of %d and %d is %d\n”ldd gcdpshdldd npshdldd m

hdpshdldd #promptjsr [printf,x]leas 6 SP

ECE 2510 40

leas 6,SP

Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 41: ECE 2510/4510/5530 HC12 Microprocessor

GetCmdLine

Int far GetCmdLine(char *cmdLineStr, int CmdLineLen)• Pointer Address: $EE8A

– This function is used to get line of input from the userGetCmdLine accepts inputs from the user one character at a time– GetCmdLine accepts inputs from the user one character at a time by calling getchar() function

– The received characters are placed in the character array pointed by the cmdLineStr using putchar() instructionby the cmdLineStr using putchar() instruction

– A maximum of CmdLineLen-1 characters may be entered– Only printable ascii characters are accepted as inputs

ECE 2510 41Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 42: ECE 2510/4510/5530 HC12 Microprocessor

GetCmdLine Examplep

Printf = $EE88GetCmdLine = $EE8A

Prompt: .asciz “Please Enter a String\n”Inbuf: .blkb 100Cmdlinelen: .byte 100

ldd Promptjsr [printf x]jsr [printf,x]ldd Cmdlinelenpshdldd b fldd Inbufcall [GetCmdLine,x]

ECE 2510 42Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 43: ECE 2510/4510/5530 HC12 Microprocessor

toupperpp

Int toupper(int c)pp ( )• Pointer Address: $EE94

– If c is a lowercase character, toupper() will return the di l ttcorresponding uppercase letter

– If the character is in uppercase, it simply returns c

• Example:toupper = $EE94

C buf: asciz “a”C_buf: .asciz aldab c_bufclrajsr [toupper x]

ECE 2510 43

jsr [toupper,x]

Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 44: ECE 2510/4510/5530 HC12 Microprocessor

isalphap

Int isalpha(int c)p ( )• Pointer Address: $EE96

– This function tests the character passed in c for membership in h t t ( A Z)character set (a-z, A-Z)

– If the character c is in this set, the function returns a non-zero value, else returns a zero value

– This function is useful for validating an input string

• Example:Isalpha = $EE96p

c_buf: .ascii “b”ldab c_bufclra

ECE 2510 44

jsr [isalpha,x]Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4,

2005.

Page 45: ECE 2510/4510/5530 HC12 Microprocessor

strlen

Unsigned int strlen(const char *cs)g ( )• Pointer Address: $EE98

– The strlen() function returns the length of the string pointed to by cs

• Example:strlen = $EE98strlen = $EE98

cs: .asciz “----------------------------------”ldd #csjsr [strlen x]jsr [strlen,x]

ECE 2510 45Gordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4, 2005.

Page 46: ECE 2510/4510/5530 HC12 Microprocessor

strcpypy

Char *strcpy(char *s1, char *s2)py( , )• Pointer Address: $EE9A

– This function copies the string pointed to by s2 into the string i t d t b 1pointed to by s1

• Example:strcpy = $EE9A

S2: .asciz “--------------------------”S1: .blkb ---

ldd #S2pshdldd #S1jsr [strcpy,x]

ECE 2510 46

leas 2,SPGordon Doughman, Reference Guide for D–Bug12 Version 4.x.x, Freescale Semiconductor, April 4,

2005.