Code Warrior
Code Warrior
Code Warrior
STARTED WITH
CODEWARRIOR
11/8/2021 Group Design Exercise
Table of Contents
1. Introduction to CodeWarrior ............................................................................................................ i
2. Downloading CodeWarrior in Pc ..................................................................................................... i
1. Download CodeWarrior 10 Evaluation Version (Eclipse, Windows-hosted) .............................. i
2. Download and install CodeWarrior. ............................................................................................ ii
4. Creating a New Project ................................................................................................................... iv
3. Some important terms to remember while writing code ................................................................. v
4. Exercise 1: Keyboard Interrupt...................................................................................................... vi
REFERENCES .......................................................................................................................................... xiv
1. Introduction to CodeWarrior
Code Warrior is an Interactive Development Environment (IDE) for the FreeScale HCS12
microcontroller family. It is a collection of applications that contains an editor for writing
programs, compilers, and linkers for converting programs to machine code. There is also a
project manager to assist you in keeping track of the numerous files necessary
(manualzz.com, n.d.).
A key component of any program development is how to detect and rectify any faults that
will inevitably arise when your program is performed. Mistakes are referred to as bugs in the
programming world, and the programs used to detect and eliminate errors are referred to as
debuggers. You may use a debugger to go through your code one line at a time. You can
check and, if required, update the contents of a variable at any time (manualzz.com, n.d.).
The debugger embedded into the chip of the microcontroller we're utilizing is one of its
features. The debugger in codeWarrior communicates with the on-chip debugger directly
through a download connection connected to particular pins on the chip. This has the
advantage of allowing you to debug your software while it is running on the chip that is
connected to all of your devices (manualzz.com, n.d.).
2. Downloading CodeWarrior in Pc
1. Download CodeWarrior 10 Evaluation Version (Eclipse, Windows-hosted)
To Program your microcontroller you will need to set up the CodeWarrior Integrated
Development Environment. CodeWarrior is available on the Freescale.com Website
(NXP Community, 2012).
1. Run the CodeWarrior installation with the 'Run as administrator' option selected. The
Eclipse Updater installs CodeWarrior service packs. This option should also be used
when running the updater. To launch the Eclipse Updater, go to the menu and select
'Window > Install new software.'
2. Read/write access to the installation folder is required by Eclipse. Ascertain that the
eclipse installation folder has the proper permissions for all users.
3. Ensure that your project workspace has both read and write rights (NXP Community,
2012).
Evaluation Edition User:
If you are installing the Evaluation Edition, the Evaluation license is automatically
installed with your product and you do not need to register it. This license allows you to
develop projects as Professional Edition within the 30-day evaluation period. After 30
days, the license works as Special Edition license (free permanent, but feature limited)
which supports unlimited assembly code, up to 32KB of C code for HCS08/RS08
derivatives, up to 64KB of C code for V1 ColdFire derivatives and up to 128KB of C
code for V2-V4 ColdFire and Kinetis derivatives and up to 512KB of C code for
MPC56xx derivatives (NXP Community, 2012).
When you launch CodeWarrior, a startup window will appear, giving you the opportunity to
create a new project from the file menu (manualzz.com, n.d.).
Create New Project: From the start-up window, select the Create New Project option.
MC9S12DP256B
Multilink P&E USB BDM: On the right, click P&E USB BDM Multilink under
Connections. This is the download cable that we're utilizing to connect to the microcontroller
(manualzz.com, n.d.).
Project Parameters
C: Under Languages, make sure that only the C programming language is ticked.
Location C:\work\robot: Make sure that you are working in the robot directory. There
may be an additional directory under robot. This is the project directory that will change
when you enter the project name. You can navigate to a different directory using the Set
button below the location box.
Project Name ex1.mcp: Of course, you can name a project whatever you wish. It must have
a .mcp suffix. The location should change to C:\work\robot\ex1
Next: Hit the Next button for the next window (manualzz.com, n.d.).
A stack is an array-like data structure in memory that allows data to be stored and deleted
from a position known as the stack's top. Data that must be saved is 'pushed' into the stack,
while data that must be retrieved is 'popped' out of the stack. The stack data structure is a
LIFO data structure, which means that the data placed first is retrieved last.
For stack operations, the assembly language offers two instructions: PUSH and POP. The
syntax of these instructions is as follows:
POP address/registration
Stack is implemented using the memory space allotted in the stack segment. The stack is
implemented using the registers SS and ESP (or SP). The SS:ESP register points to the top of
the stack, which points to the last data item entered into the stack, where the SS register
points to the beginning of the stack segment and the SP (or ESP) specifies the offset within
the stack segment (Stack Overflow, n.d.).
Registers
A register is a processor component that can store a bit pattern. A register on the MIPS has 32
bits. The CPU contains several registers, but only a subset of them is accessible in assembly
language. The processor uses the others to carry out its tasks. A load operation is used to
copy a bit pattern from memory to a register. A store operation is used to copy a bit pattern
from a register into memory. General purpose registers and floating point registers are the
registers exposed in assembly language. There are a total of 32 general purpose registries. A
32 bit pattern is stored in each general purpose register. These registers are denoted in
assembly language as $0, $1, $2... $31. There are a total of 32 floating point registers (Stack
Overflow, n.d.).
Flags
The FLAGS register is a status register that includes information about the present state of a
CPU. The size and meaning of the flag bits vary according on the architecture. It often
displays the outcome of mathematical operations as well as information about current CPU
operating limits (Stack Overflow, n.d.).
Subroutine
To distinguish between functions used in other programming languages and those used in
assembly languages, we use the term subroutine for all subprograms in assembly language. A
subroutine is a set of instructions that may be added at any time in the main programme when
that job is required.
Routine
In assembler languages, a process that requires variable input is often encoded into a macro
definition with a specific interface called a macro instruction. Instead of including and
managing the branching to a procedure, the programmer can utilize a macro instruction.
Push
The push instruction moves its operand to the top of memory's hardware-supported stack.
Push, in particular, decrements ESP by 4, then inserts its operand into the contents of the 32-
bit location at address [ESP].
muint8 LED_onseq;
void main(void)
{
PTDPE = 0xFF; /* enable port D pullups for push button switch interrupt
*/
//********************************************************************
*************
//* KBI1PE7 * KBI1PE6 * KBI1PE5 * KBI1PE4 * KBI1PE3 * KBI1PE2 * KBI1PE1
* KBI1PE0 *
//********************************************************************
*************
// KBI1PE register; each bit selects the corresponding keyboard interrupt pin.
//********************************************************************
*************
//* KBEDG7 * KBEDG6 * KBEDG5 * KBEDG4 * KBF * KBACK * KBIE
* KBIMOD *
//********************************************************************
*************
// KBI1SC register; top four bits 0 = falling edge 1 = rising edge of corresponding
// pins KBEDG7 to 4. KBF keyboard interrupt flag, KBACK acknowledges interrupt
flag.
// KBIE turns on the keyboard interrupt system, KBIMOD 0 = edge detection.
} /* loop forever */
/* make sure that you never leave main! */
}
// What follows is the interrupt service routine, which is called if either of the
// selected keyboard interrupts occurs on pins 5 and 6. However, Port D is tested
// and the LED toggle only happens if SW3 is pressed. (KBI 6, Port D3).
*************************************************************************
;* kbi_adc.asm
*
;*
*
;* MC9S08AW60 Evaluation board keyboard interrupt example
*
;* - Switch SW3 onboard connected to Port D bit 3, KBI pin6;
*
;* - Switch SW4 onboard connected to Port D bit 2, KBI pin5
*
;*
*
<<<<<<< HEAD
;* Function:
*
;* On reset, all LEDs are off. When either SW3 or SW4 are
pressed, *
;* then the ADC channel 8 is read and sent to the LEDs.
*
=======
;* Function:
*
;* on reset all LEDs will light on. If SW3 or SW4 pressed,
*
;* an interrupt is generated, which set LEDs 0:3 to light on.
*
;* More interrupts are generated if SW3 or SW4 are pressed.
*
>>>>>>> master
;*************************************************************************
INCLUDE 'derivative.inc' ; Include derivativespecific
definitions
FLASH EQU
$2000
RAM EQU
$0070
WATCH EQU
$1802
ConvComp EQU %10000000 ;Mask for
Conversion Complete flag
ORG
RAM
LED_on DS.B 1 ; Define a variable
VAR_D with a size of 1 byte
;Start program after reset
ORG
FLASH
START_UP
LDA
#$00
STA WATCH ; Turn off the
watchdog timer
;Init_GPIO init code
LDA
#$FF
STA
PTFDD
MOV #$0F, LED_on ; Initialize VAR_D,
used to control the LEDs
LDA
#$FF
STA PTDPE ; Port D is enabled
with pull-up
RSP ; Reset stack
pointer to $0080
;Enable interrupt for Keyboard input
LDA
#$60
STA KBI1PE ; KBI1PE: enable
KBI function for pins 5 and 6 only
BSET $02, KBI1SC ; KBI1SC: KBACK=1,
to clear KBI flag
BSET $01, KBI1SC ; KBI1SC: KBIE=1,
enable KBI
CLI ; Enable
interrupt
MAINLOOP
LDA LED_on ; Simple loop with
"dummy" operation
BRA
MAINLOOP
;Interrupt service routine for a keyboard interrupt generated upon
the press of a pushbutton
;with a falling edge (transition from high logic level "1" to low
logic level "0")
LED_SWITCH
BSET $02, KBI1SC ; Clear KBI flag
LDA #8 ; Select analogue
input 8 (the blue potentiometer).
STA ADC1SC1 ; ADC conversion
will start after a number is written to ADC1SC1 register.
ADCLOOP
LDA ADC1SC1 ;
AND #ConvComp ; Check the
COCO bit (conversion complete flag).
BEQ ADCLOOP ; if not complete,
wait in the ADC loop.
LDA ADC1RL ; if complete, read
the ADC outcome (digital value) from the register.
STA PTFD ; display over LED
bar
RTI
;INT_VECTOR
ORG
$FFD2
DC.W
LED_SWITCH
ORG
$FFFE
DC.W
START_UP
By doing experiments with the slightly modified sample C programme, you are required to
answer the following questions.
1. Upon the generaon of keyboard interrupt requests, the ISR will be run by the CPU.
Experiment with the evaluator board, record and compare the content in the stack just
before and aer the CPU enters the ISR and just before and aer the CPU leaves the ISR
corresponding to a keyboard interrupt. You can get the stack pointer value from the
register panel in the real-me debugger window.
First two instructions in the subroutine ms_delay push index registers X and Y on the
stack.order of pulling stack must be opposite from the order of pushing of stack. For each
push instruction one led must be on from the stack. when a loop execute it show first most
left digit and closed the loop and went back into void main loop. Then loop rerun and execute
again then it show second most left digit. Due to outer loop command stack content changes.
muint8 LED_onseq;
unsigned char binary_pattern[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
void main(void)
{
PTDPE = 0xFF; /* enable port D pullups for push button switch interrupt
*/
//********************************************************************
*************
//* KBI1PE7 * KBI1PE6 * KBI1PE5 * KBI1PE4 * KBI1PE3 * KBI1PE2 * KBI1PE1
* KBI1PE0 *
//********************************************************************
*************
// KBI1PE register; each bit selects the corresponding keyboard interrupt pin.
//********************************************************************
*************
//* KBEDG7 * KBEDG6 * KBEDG5 * KBEDG4 * KBF * KBACK * KBIE
* KBIMOD *
//********************************************************************
*************
// KBI1SC register; top four bits 0 = falling edge 1 = rising edge of corresponding
// pins KBEDG7 to 4. KBF keyboard interrupt flag, KBACK acknowledges interrupt
flag.
// KBIE turns on the keyboard interrupt system, KBIMOD 0 = edge detection.
} /* loop forever */
/* make sure that you never leave main! */
}
// What follows is the interrupt service routine, which is called if either of the
// selected keyboard interrupts occurs on pins 5 and 6. However, Port D is tested
// and the LED toggle only happens if SW3 is pressed. (KBI 6, Port D3).
To conclude the whole discussion this report contains many important aspects cover of
codeWarrior. It is being discussed in the report that what the codeWarrior software why it is
used is, how to install it in pc and what are main terms that a person should know before
writing any sort of code in assembly language. Afterwards 3 parts are implemented in the
software once is to Interrupt Generation with the Evaluation Board n which an interrupt is
being generated by code, secondly a code is being written to generate student number is
assembly language also it also being concluded that First two instructions in the subroutine
ms_delay push index registers X and Y on the stack.order of pulling stack must be opposite
from the order of pushing of stack. For each push instruction one led must be on from the
stack. When a loop execute it show first most left digit and closed the loop and went back
into void main loop. Then loop rerun and execute again then it show second most left digit.
Due to outer loop command stack content changes.
REFERENCES
1. manualzz.com. (n.d.). Introduction to CodeWarrior | Manualzz. [online]
Available at: https://manualzz.com/doc/25792906/introduction-to-
codewarrior [Accessed 8 Nov. 2021].
2. NXP Community. (2012). Download And Install Codewarrior 10. [online]
Available at: https://community.nxp.com/t5/University-Programs-
Knowledge/Download-And-Install-Codewarrior-10/ta-p/1114244 [Accessed
8 Nov. 2021].
3. Stack Overflow. (n.d.). Terminology: “registers” in assembly language
programming. [online] Available at:
https://stackoverflow.com/questions/814448/terminology-registers-in-
assembly-language-programming [Accessed 8 Nov. 2021].