CodeWarrior TM

pleasanthopebrothersElectronics - Devices

Nov 2, 2013 (3 years and 7 months ago)

109 views

Intro. to CodeWarrior™
--
Running
Assembly Programs on the
Microcontroller

Freescale University Programs

Document Number:
LABS12CINTRO4S/REV1

Author: Fred Cady

Sample Code


LED1 and 2 will blink


Export Symbols (assembler directive)


XDEF Entry, main


XREF ___SEG_END_STACK

User Register Definitions


BASE:


EQU


0


PORTA:

EQU


BASE+0


DDRA:


EQU


BASE+2


PORTB:

EQU


BASE+1


DDRB:


EQU


BASE+3


LED1:


EQU


%00000001 ;A0


LED2:


EQU


%00010000 ;B4

User Constant Definitions


DELAY1:

EQU


$ffff ;inner lp cnt


DELAY2:

EQU


$04


;outer lp cnt

User code Section


MyCode:

Section


main:


Entry:

Initialize stack pointer register


LDS

#__SEG_END_SSTACK

Initialize I/O


bset

DDRA,LED1

;Make A0 output


bset

DDRB,LED2

;Make B4 output


ldaa

#LED1


;Initial LED Display


ldab

#~LED2


; ~ = 1’s comp.


main_loop:

; DO

; Display the current pattern on the LEDs



staa


PORTA



stab


PORTB

;Delay some time



jsr


delay_sub


main_loop (cont.)

;Complement the display values


coma

; Complement A register


comb

; Complement B register

; Forever




bra


main_loop

delay_sub


See page 5


X and Y are pushed on the stack.


DELAY2 is loaded into Y (initialization)


While Y is not zero, outer loop counter is
decremented.


While X register is not zero; branch if zero to
“all_done:”.


Inner loop is processed.


Registers are restored and then a return from
subroutine occurs.


Result, LED’s blink at different rates.