1 / 10

A Simple Tour of the MSP430

A Simple Tour of the MSP430. Light LEDs in C. LEDs can be connected in two standard ways . A ctive high circuit, the LED illuminates if the pin is driven high (logic 1) and extinguishes if the pin is driven low ( logic 0 ).

annora
Download Presentation

A Simple Tour of the MSP430

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. A Simple Tour of the MSP430

  2. Light LEDs in C • LEDs can be connected in two standard ways. • Active high circuit, the LEDilluminates if the pin is driven high (logic 1) and extinguishes if the pin is driven low(logic 0). • Input andoutput is memory mapped, which means that nothing unusual is needed tocontrol outputpins:We simply write in the normal way to the register that controls them. • The complete program needs to carry out the following tasks: • 1. Configure the microcontroller. • 2. Set the relevant pins to be outputs by setting the appropriate bits of PxDIR. • 3. Illuminate the LEDs by writing to PxOUT. • 4. Keep the microcontroller busy in an infinite, empty loop.

  3. Light LEDs in C

  4. Assignment • The basic instruction in assembly language is mov.w source,destination tomove a word or mov.b for a byte. • A single character denotes the mode in the operand. • • immediate, #: The value itself (word or byte) is given and stored in the wordfollowing the instruction. This is also known as a literal value. • • absolute, &: The address of a register in memory space is given and stored in theword following the instruction. • • register, R: This specifies one of the 16 registers in the CPU. • The immediate mode is clearly useful only for the source but the other two can be used foreither the source or destination, provided that it is possible to write to the destination—it isnot in ROM, for instance.

  5. Infinite Loop • The flowof control is based on jump instructions, which can be either conditional or unconditional(always taken). • You have no choice in assemblylanguage. • Normally the CPU executes instructions from memory one after the other. The program counter (PC) is automaticallyincremented so that it is ready to fetch the next instructionas soon as it is needed. Thissequence is broken by a jump, which causes a new address to be loaded into in the PC.

  6. Program ISStored in Memory • Generally thecode should go into the flash ROM and variables should be allocated in RAM.We putthe code in the most obvious location, which is at the start of the flash memory (lowaddresses). The Memory Organization section of the data sheet shows that the main flashmemory has addresses 0xF000–FFFF.We therefore instruct the assembler to start storingthe code at 0xF000.

  7. Program Start • In the MSP430, the address of the first instruction to be executed is stored at a specificlocation in flash memory, rather than the instruction itself. This address, called the resetvector, occupies the highest 2 bytes of the vector table at 0xFFFE:FFFF. It is set up asfollows: • 1. Put a label in front of the first instruction to be executed. • 2. Use an directive to tell the assembler where the reset vector shouldbe stored. It is at the same address in all current MSP430 devices. • 3. This is followed by a DW Reset directive for “define word,” which tells theassembler to store the following word (2 bytes) in memory. This is the address ofthe first instruction to be executed and the assembler replaces the label with itsnumerical value.

  8. Read Input from a Switch • The pull-upresistor Rpull holds the input at logic 1 (voltage VCC) while the button is up; closing theswitch shorts the input to ground, logic 0 or VSS. The input is therefore active low, meaningthat it goes low when the button is pressed. • Most MCUs offer internal pull-ups to reduce the number ofexternal components needed.

  9. Read Input from a Switch • A program can respond to inputs in two ways. • Polling • Interrupt • Polling issimple but carries the overhead of regular checking, which is high if checks must be madefrequently. An interrupt needs special hardware and requires tidying up sothat normal operation can be resumed after the interrupt has been serviced.

  10. Two Loops, One for Each State of the Button • The LED is continually being switched on or off in the first version. The action is repeatedcontinually. • The LED is turned on or off only when necessary in the second version, just at thepoints when the button is pressed or released.

More Related