E91 - Embedded Systems, Lab 2

Introduction to Assembly Language

Back to Embedded Systems Page

Please contact me if there is a problem with this web page (e.g., errors, or sections that are unclear).

Creating an assembly language program:

  1. Start CCS and go to File->New CCS Project, and create a new project as before, but when you get to the "CCS Project Settings" window, click on the "Treat as an Assembly-only project" checkbox.

    Warning - Remember to uncheck this the next time you create a "C" project.  CCS remembers the setting.
  2. When the project is created, go to File->New Source file and create a new file with a ".asm" extension.
  3. Cut and past the following into the file:
      .cdecls C,LIST,  "msp430x20x3.h"
     .global progStart
    ;------------------------------------------------------------------------------
                .text                           ; Progam Start
    ;------------------------------------------------------------------------------
    progStart   mov.w   #0280h,SP               ; Initialize stackpointer
    StopWDT     mov.w   #WDTPW+WDTHOLD,&WDTCTL  ; Stop WDT
    SetupP1     bis.b   #001h,&P1DIR            ; P1.0  output
                                                ;
    Mainloop    bis.b   #001h,&P1OUT            ; Set P1.0
                mov.w   #05000h,R15             ; Delay to R15
    L1          dec.w   R15                     ; Decrement R15
                jnz     L1                      ; Delay over?
    
                bic.b   #001h,&P1OUT            ; Clr P1.0
                mov.w   #05000h,R15             ; Delay to R15
    L2          dec.w   R15                     ; Decrement R15
                jnz     L2                      ; Delay over?
               
                jmp     Mainloop                ; Again
                                                ;
    ;------------------------------------------------------------------------------
    ;           Interrupt Vectors
    ;------------------------------------------------------------------------------
    
                .sect   ".reset"                ; MSP430 RESET Vector
                .short  progStart               ;
                .end
  4. From the "C/C++" view,  go to Project->Properties and choose "C/C++ Build" in the left pane.  In the right pane, choose the "Tool Settings" tab, scroll down to "MSP430 Linker" and expand it if necessary.  Click on "Symbol Management."  In the right side of the window where it says "Specify program entry point for the output module (--entry_point, -e)" enter "progStart"  This tells the linker where the program starts.
  5. Build, download and run the program on an MSP430F2013.  The LED on P1.0 should blink.

As you write the programs below - if you get stuck, write the equivalent in C, and look at the assembly language output (the ".lst" file, or in the debugger).  To get a ".lst" file from the "C/C++" view go to Project->Properties and choose "C/C++ Build" in the left pane.  In the right pane, choose the "Tool Settings" tab, choose "MSP430 Compiler" and expand it if necessary.  Click on "Assembler Options."  Choose the text box for "Keep the generated assembly language file" to generate a ".asm" file, or choose "Generate listing file" to get a ".lst" file.

Task 1:

Write a program that makes an LED glow progressively brighter.  When it gets to full brightness, it should turn off and repeat the cycle continuously.  Brightness can be controlled by varying the percent of time an LED is on with a flash rate too fast for the human eye to perceive.

Task 2:

Write a program for the "MSP430 Experimeter's" board that lights an LED every time the pushbutton labeled "S1" is pushed.

Task 3:

Optional:  Something cooler than task 2.


To turn in:

Back to Embedded Systems Page

Please contact me if there is a problem with this web page (e.g., errors, or sections that are unclear).