Programming the HCS12 with asm

Discussion in 'Embedded Systems and Microcontrollers' started by Sparky49, Mar 31, 2014.

  1. Sparky49

    Thread Starter Active Member

    Jul 16, 2011
    834
    417
    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.

    Code ( (Unknown Language)):
    1. ;**************************************************************
    2. ;*       LED Test Program                                     *
    3. ;*       Written by Sparky 31/03/14                           *
    4. ;*       Designed to toggle the LEDs of PORTA                 *
    5. ;**************************************************************
    6.  
    7. ; Include derivative-specific definitions
    8.             INCLUDE 'mc9s12dg128.inc'  ;uC on board
    9.            
    10. ;------------------
    11. ;Memory locations
    12.  
    13. R1  EQU   $1000
    14. R2  EQU   $1001
    15. R3  EQU   $1002
    16.  
    17. ;------------------
    18. ;ORG directive
    19.  
    20.       ORG   $4000
    21.    
    22. Entry:
    23.       LDS   #$4000    ;Stack
    24.       LDAA  #$FF
    25.       STAA  DDRA      ;Set PORTA as output
    26.      
    27. BACK  LDAA  #$55      ;Load 0x55
    28.       STAA  PORTA     ;Display on PORTA LEDs
    29.       JSR   DELAY     ;Delay
    30.       LDAA  #$AA      ;Repeat above for 0xAA
    31.       STAA  PORTA
    32.       JSR   DELAY
    33.      
    34.       BRA   BACK
    35.      
    36. ;------------------
    37. ;DELAY subroutine
    38.  
    39. DELAY
    40.  
    41.         PSHB        ;Save Reg A on Stack
    42.         LDAB    #10     ;Change this value to see  
    43.         STAB    R3      ;how fast LEDs Toggle
    44. ;--10 msec delay.
    45. ;Freq. for Instruction Clock Cycle is 24MHz (1/2 of 48Mhz).
    46. ;(1/24MHz) x 10 Clk x240x100=10 msec. Overheads are excluded in this calculation.        
    47. L3      LDAB    #100
    48.         STAB    R2
    49. L2      LDAB    #240
    50.         STAB    R1
    51. L1      NOP         ;1 Intruction Clk Cycle
    52.         NOP         ;1
    53.         NOP         ;1
    54.         DEC     R1  ;4
    55.         BNE     L1  ;3
    56.         DEC     R2  ;Total Instr.Clk=10
    57.         BNE     L2
    58.         DEC     R3
    59.         BNE     L3
    60. ;--------------        
    61.         PULA            ;Restore Reg A
    62.         RTS
    63. ;-------------------
    64. ;**************************************************************
    65. ;*                 Interrupt Vectors                          *
    66. ;**************************************************************
    67.             ORG   $FFFE
    68.             DC.W  Entry     ;Reset Vector. CPU wakes here and it is sent to start of the code at $4000      
    69.            
    70.  
    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
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,152
    1,793
    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.
     
    royalt213 and Sparky49 like this.
  3. Sparky49

    Thread Starter Active Member

    Jul 16, 2011
    834
    417
    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. :)
     
  4. Papabravo

    Expert

    Feb 24, 2006
    10,152
    1,793
    You're welcome!

    My advice on wizards is to treat them like porcupines -- very carefully.
     
    Sparky49 likes this.
  5. Sparky49

    Thread Starter Active Member

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

    I shall persevere though.
     
Loading...