MSP430 MCU FLASH read and write operation examples

Publisher:大头玩家Latest update time:2016-03-25 Source: eefocusKeywords:MSP430 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
//******************************************************************************
// MSP430F149
// M. Mitchell
// Texas Instruments Inc.
// Feb 2005
// Built with IAR Embedded Workbench Version: 3.21A
//******************************************************************************

#include

char value;                                // 8-bit value to write to segment A

// Function prototypes
void write_SegA (char value);
void copy_A2B (void);

void main(void)
{
    WDTCTL = WDTPW + WDTHOLD;              // Stop watchdog timer
    FCTL2 = FWKEY + FSSEL0 + FN0;          // MCLK/2 for Flash Timing Generator
    value = 0;                             // Initialize value

    while(1)                               // Repeat forever
   {
      write_SegA(value++);                 // Write segment A, increment value
      copy_A2B();                          // Copy segment A to B
     _NOP();                               // SET BREAKPOINT HERE
   }
}

void write_SegA (char value)
{
    char *Flash_ptr;                       // Flash pointer
    unsigned int i;

    Flash_ptr = (char *) 0x1080;           // Initialize Flash pointer
    FCTL1 = FWKEY + ERASE;                 // Set Erase bit
    FCTL3 = FWKEY;                         // Clear Lock bit
    *Flash_ptr = 0;                        // Dummy write to erase Flash segment

    FCTL1 = FWKEY + WRT;                   // Set WRT bit for write operation

    for (i=0; i<128; i++)
    {
        *Flash_ptr++ = value;              // Write value to flash
    }

    FCTL1 = FWKEY;                         // Clear WRT bit
    FCTL3 = FWKEY + LOCK;                  // Set LOCK bit
}


void copy_A2B (void)
{
    char *Flash_ptrA;                      // Segment A pointer
    char *Flash_ptrB;                      // Segment B pointer
    unsigned int i;

    Flash_ptrA = (char *) 0x1080;          // Initialize Flash segment A pointer
    Flash_ptrB = (char *) 0x1000;          // Initialize Flash segment B pointer
    FCTL1 = FWKEY + ERASE;                 // Set Erase bit
    FCTL3 = FWKEY;                         // Clear Lock bit
    *Flash_ptrB = 0;                       // Dummy write to erase Flash segment B
    FCTL1 = FWKEY + WRT;                   // Set WRT bit for write operation

    for (i=0; i<128; i++)
    {
        *Flash_ptrB++ = *Flash_ptrA++;     // Copy value segment A to segment B
    }

    FCTL1 = FWKEY;                         // Clear WRT bit
    FCTL3 = FWKEY + LOCK;                  // Set LOCK bit
}
Keywords:MSP430 Reference address:MSP430 MCU FLASH read and write operation examples

Previous article:MCU DS18B20 water temperature control system design program source code
Next article:Advantages of AVR over 51 series microcontrollers

Recommended ReadingLatest update time:2024-11-16 15:37

Single chip microcomputer realizes multi-gas detection system
A gas sensor is a device that can convert information about the type of gas and its concentration into electrical signals. Based on the strength of these electrical signals, information about the presence of the gas to be tested in the environment can be obtained, so that detection, monitoring and alarm can be perfo
[Analog Electronics]
Single chip microcomputer realizes multi-gas detection system
Design of Temperature Monitoring System Based on 89C52 Single Chip Microcomputer
introduction Temperature detection is one of the important working conditions in many industries. Whether it is a grain warehouse, a Chinese medicine warehouse, or a book storage, it needs to be in a temperature environment that meets the specified conditions. However, temperature is the most difficult indicator t
[Microcontroller]
Design of Temperature Monitoring System Based on 89C52 Single Chip Microcomputer
Introduction to MSP430 Series MCU
1. Development of MSP430 microcontroller   The MSP430 series is a 16-bit, ultra-low power hybrid microcontroller with a streamlined instruction set. It was launched in 1996. It has become a shining star among many microcontroller series due to its extremely low power consumption, rich on-chip peripherals and conveni
[Microcontroller]
Design of a multifunctional guide car system based on AVR MCU
1. Project Overview 1.1 Introduction With the development of society, the blind people are more and more eager to pursue independent life and career, but to ensure safe and comfortable activities in the busy city life, they need a special guide device to assist. Therefore, we have to design a multifunctional guide c
[Microcontroller]
Design of a multifunctional guide car system based on AVR MCU
How to calculate the execution time of AB program segment during PIC microcontroller software simulation
In MPLAB IDE, when you select MPLAB SIM as the debugger, there is a simulator logic analyzer under the view menu. Before and after the program segment to be calculated in the program, add the same IO port to set the output signal to 0 or 1. For example, to calculate the delay of delaynus(160), you can set RC0=1;RC0=0;
[Microcontroller]
Design of Embedded Display System Based on 8-bit Single-chip Microcomputer C51
  introduction   Embedded devices have developed rapidly and penetrated into every corner of life due to their affinity with users and natural human-computer interaction interface. The design method introduced in this paper is to use the high-performance 8-bit microcontroller C8051F120 as the core processor, SRAM as
[Microcontroller]
Design of Embedded Display System Based on 8-bit Single-chip Microcomputer C51
51 single chip ultrasonic ranging module
//Crystal oscillator = 8M   //MCU=STC10F04XE   //P0.0-P0.6 common anode digital tube pin   //Trig  = P1^0   //Echo = P3^2   #include reg52.h //Include a 52 standard kernel header file   #define uchar unsigned char //define for easy use   #define uint  unsigned int   #define long unsigned long   //***********
[Microcontroller]
8051 MCU Tutorial Lesson 12: Logical Operation Instructions
MCU Tutorial Lesson 12: Logical Operation Instructions: Logical operations on accumulator A: CLRA; clear the value in A to 0, single-cycle single-byte instruction, with the same effect as MOVA, #00H. CPLA; reverse the value in A bit by bit RLA; logically shift the value in A to the left RLCA; logically sh
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号