Programming the HCS12 with asm

Thread Starter

Sparky49

Joined Jul 16, 2011
822
Hi guys,

I been doing some reading again on the Freescale HCS12, and I've taken the plunge into doing some learning with it. I was thinking that the experience I have gained with PIC asm might have helped.

I'm using the Codewarrior IDE, with a MC9S12GD128 uC. To start with I thought I would write a toggle the LEDs program, however this seems to be more complex than with the PIC.

Below is my attempt to create something meaningful.

Rich (BB code):
;**************************************************************
;*       LED Test Program                                     *
;*       Written by Sparky 31/03/14                           *
;*       Designed to toggle the LEDs of PORTA                 * 
;**************************************************************

; Include derivative-specific definitions
            INCLUDE 'mc9s12dg128.inc'  ;uC on board
            
;------------------
;Memory locations

R1  EQU   $1000
R2  EQU   $1001
R3  EQU   $1002

;------------------
;ORG directive

      ORG   $4000
    
Entry: 
      LDS   #$4000    ;Stack
      LDAA  #$FF
      STAA  DDRA      ;Set PORTA as output
      
BACK  LDAA  #$55      ;Load 0x55
      STAA  PORTA     ;Display on PORTA LEDs
      JSR   DELAY     ;Delay
      LDAA  #$AA      ;Repeat above for 0xAA
      STAA  PORTA
      JSR   DELAY
      
      BRA   BACK
      
;------------------
;DELAY subroutine

DELAY

        PSHB		;Save Reg A on Stack
        LDAB    #10		;Change this value to see  
        STAB    R3		;how fast LEDs Toggle
;--10 msec delay.
;Freq. for Instruction Clock Cycle is 24MHz (1/2 of 48Mhz). 
;(1/24MHz) x 10 Clk x240x100=10 msec. Overheads are excluded in this calculation.         
L3      LDAB    #100
        STAB    R2
L2      LDAB    #240
        STAB    R1
L1      NOP         ;1 Intruction Clk Cycle
        NOP         ;1
        NOP         ;1
        DEC     R1  ;4
        BNE     L1  ;3
        DEC     R2  ;Total Instr.Clk=10
        BNE     L2
        DEC     R3
        BNE     L3
;--------------        
        PULA			;Restore Reg A
        RTS
;-------------------
;**************************************************************
;*                 Interrupt Vectors                          *
;**************************************************************
            ORG   $FFFE
            DC.W  Entry     ;Reset Vector. CPU wakes here and it is sent to start of the code at $4000
However, when I go to debug, it comes up with the following messages:

L1115: Function entry not found
L1106: Object entry not found

I have tried to google this, but I cannot make heads nor tails of wha is being discussed. Might someone be able to offer some advice?

Also, if anyone might be kind enough to offer some template I can use to set up my uC, it would be much appreciated. I might be able to concentrate on getting a program to work then, hehehe. :)

Regards,

Sparky
 

Papabravo

Joined Feb 24, 2006
12,397
You might need a statement that declares "Entry" to be a global symbol.

In systems where the assembler produces modules that a "linked" together with a linkage editor there needs to be a way to tell the difference between local symbols and global symbols. In the PIC world you can still do absolute assembly, but I'm not sure if this platform supports it.

How the code gets located at 0x4000 has to do with the reset vector and some instruction to the linkage editor to locate the code section at 0x4000.
 

Thread Starter

Sparky49

Joined Jul 16, 2011
822
Ah that makes sense, thank Papabravo.

I admit seeing a greyed out option for absolute assembly - I don't know how, but I have just managed to tick it.

I am now lost in some port setup wizard thing. :D

Again, thanks. :)
 

Papabravo

Joined Feb 24, 2006
12,397
Ah that makes sense, thank Papabravo.

I admit seeing a greyed out option for absolute assembly - I don't know how, but I have just managed to tick it.

I am now lost in some port setup wizard thing. :D

Again, thanks. :)
You're welcome!

My advice on wizards is to treat them like porcupines -- very carefully.
 

Thread Starter

Sparky49

Joined Jul 16, 2011
822
Yeah... I've just learned that... Seems to have spat out a load of just everything. erm. :D

I shall persevere though.
 
Top