School Work

Assembly Language

Description
msp430 tuto
Categories
Published
of 16
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Related Documents
Share
Transcript
  launchpad msp430 assembly language tutorial by ralph heymsfeld The Texas Instruments LaunchPad is a handy tool for evaluating and learning about the MSP430 Value Line series of microcontrollers. This tutorial uses the LaunchPad with its included MSP430G2231 processor to introduce MSP430 assembly language programming. A small program is developed which reads the status of a LaunchPad push button. While the button is not pushed the LaunchPad's red LED is turned on. If the button is pushed the green LED is turned on. Although this first program is short - only 20 lines of code - the tutorial covers a lot of ground. In addition to an overview of the basic syntax and structure of MSP430 assembly language, information is provided on how to:    Configure a pin as an input or output    Turn an output on or off    Read a digital input    Branch to a different place in a program    Implement a simple IF/THEN construct    Implement a simple LOOP construct    Implement a simple DELAY construct The syntax presented here is based on TI's Code Composer Studio (CCS) and therefore to complete this exercise you will need to have CCS downloaded and installed on your computer. A free version of CCS is available from the TI website. basic assembly language syntax An assembly language source program is a text file made up of a series of source statements. A source statement will contain one or more of the following elements:     Label - acts as a marker in the source code, useful as the destination in branching statements and subroutine calls    Mnemonic - a machine instruction, assembler directive, or macro    Operand List - one or more values to be operated on by the instruction, directive, or macro    Comment - note inserted by the programmer that is not included in the assembly The following example source statement contains all of these elements: label mnemonic operand list comment Mainloop bit.b #00001000b,&P1IN ; Read switch at P1.3 The most fundamental of the elements are the machine instruction mnemonics, as these map directly to the functions of the microcontroller's CPU. The complete MSP430 instruction set consists of 27 core instructions. There are an additional 24 emulated instructions which are translated to core instructions by the assembler software. When compared to the command set of some higher level languages, these machine instructions are very basic, performing tasks such as mathematical and logical operations, writing and retrieving values from memory, and branching to different sections of code. For example, the instruction statement: add.w #10,R5 takes the number 10, adds it to the value stored in general register R5 and stores the result back in R5.   While the instruction statement: jmp Delay will relocate program execution to the point marked by the Delay label.    Operands are very flexible. In the two examples above there are three different operand types - the number 10, the general register R5, and the user-defined symbol label Delay. In all, there are seven different addressing modes as well as support for numerous constant types including binary, decimal, hexadecimal, and ASCII. The nature of assembler directives is very different from that of machine instructions. While machine instructions relate directly to the operation of the microcontroller itself, assembler directives are instructions related to the assembly process. A few common functions of directives include defining symbols, initializing memory, and specifying libraries from which the assembler can obtain macros. Assembler directives can be distinguished from machine instructions by their leading dot, for example: .end is the directive which tells the assembler that it has reached the last source statement of a program. Labels are optional. When used they must be the first character of a line. They cannot begin with a number or contain a blank space, but otherwise can include the alphanumeric characters A-Z, a-z, 0-9, _, and $. Labels are case sensitive by default but can be set as case insensitive as an option. A label can be followed by a colon(:), but this is not required and the colon is not treated as part of the label name when referenced elsewhere in the program. Comments are also optional. They can use any ASCII character including spaces. When a comment starts at the first character in a line it can begin with either an asterisk(*) or a semicolon(;), if it does not begin at the first character it can only begin with a semicolon.  The first character of a line can only be a label, asterisk, semicolon, or a blank space. The first character cannot be a mnemonic or it will be treated as a label by the assembler. a note about architecture The register is an extremely important concept in microcontroller programming. On the MSP430 all operations except for program flow instructions are implemented as register operations. To set the frequency of a timer, a value is written to a register. To retrieve the status of an input pin, a value is read from a register. To save a value for later, that value is written to a register. In terms of the CPU all of these operations are functionally the same - a bit, byte, or word is written to or read from a specified location. Once you have mastered the basic techniques for manipulating these bits, bytes and words, learning to implement a feature of the MSP430

Esperanzas

Jul 23, 2017

Davao

Jul 23, 2017
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks