#include int i,b,c; //Write to Flash function void writeFlash(int Value){ int *Flash_ptr; //Flash Pointer Flash_ptr = (int *)0x1040; //Flash Pointer adress FCTL3 = FWKEY; //Flash clear FCTL1 = FWKEY + WRT; //Flash write bit *Flash_ptr = Value; //Flash write FCTL1 = FWKEY; //Flash clear FCTL3 = FWKEY + LOCK; //Flash lock } //Read from Flash function int readFlash(){ int readValue; //Variable int *Flash_ptr; //Flash Pointer Flash_ptr = (int *)0x1040; //Flash Pointer adress readValue = *Flash_ptr; //Flash Pointer to Variable return(readValue); } //Erase Flash function void eraseFlash(){ int *Flash_ptr; //Flash Pointer Flash_ptr = (int *)0x1040; //Flash Pointer adress FCTL1 = FWKEY + ERASE; //Flash erase bit FCTL3 = FWKEY; //Flash clear *Flash_ptr = 0; //Flash Pointer Dummy write FCTL1 = FWKEY; //Flash clear FCTL3 = FWKEY + LOCK; //Flash lock } void main(void){ WDTCTL = WDTPW + WDTHOLD; BCSCTL1 = CALBC1_16MHZ; DCOCTL = CALDCO_16MHZ; P1DIR |= BIT5; P1SEL = 0x00; P1OUT = 0x00; while(1){ if(i==17) P1OUT |= BIT5; if(i!=17) P1OUT &=~ BIT5; if(P1IN & BIT1) eraseFlash(); if(P1IN & BIT2) i = readFlash(); if(P1IN & BIT3) writeFlash(17); } }