I have the following code:
#include <msp430f47197.h>
#include <stdbool.h>
bool flag = true;
unsigned short read_flash (unsigned short address);
void erase_flash(unsigned short address);
void write_flash (char value,unsigned short address);
const char numbers[]={0x7D,0x05,0x3E,0x7A,0x63,0x5B,0x5F,0x70,0x7F,0x7B};
int main(void)
{
volatile unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
FLL_CTL0 |= XCAP11PF; // Configure load caps
// Wait for xtal to stabilize
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
for (i = 0x47FF; i > 0; i--); // Time for flag to set
}
while ((IFG1 & OFIFG)); // OSCFault flag still set?
P5SEL =BIT1+BIT2+BIT3+BIT4; // Set COM pins for LCD
LCDACTL = LCDON+LCD4MUX; // 4mux LCD, ACLK/32
LCDAPCTL0 = 0x7F; // Segments 0-24
for( i = 1; i <= 20; i ++)
{
LCDMEM[i] = 0; // Clear LCD We have 20 LCDMemory
}
P5SEL =BIT1+BIT2+BIT3+BIT4; // Set COM pins for LCD
LCDACTL = LCDON+LCD4MUX; // 4mux LCD, ACLK/32
LCDAPCTL0 = 0xF6; // Segments 0-24
erase_flash(0x0ffB1); // erasing the flash
// write_flash(0x67,0x0ffc0); // Writing 'H'
for (i =0; i <= 9 ; i++)
{
LCDMEM[4] = numbers[i];
write_flash(numbers[i],0x0ffB1);
read_flash(0x0ffB1);
__delay_cycles(1000000);
}
}
void erase_flash(unsigned short address)
{
char *Flash_ptr;
Flash_ptr = (char*) address;
FCTL1 = FWKEY + ERASE;
FCTL3 = FWKEY;
*Flash_ptr = 0;
FCTL3 = FWKEY + LOCK;
}
void write_flash (char value,unsigned short address)
{
char *Flash_ptr;
Flash_ptr = (char*) address;
FCTL1 = FWKEY + ERASE;
FCTL3 = FWKEY;
FCTL1 = FWKEY + WRT;
*Flash_ptr = value;
FCTL1 = FWKEY;
FCTL3 = FWKEY + LOCK;
}
unsigned short read_flash (unsigned short address)
{
char value;
char *Flash_ptr;
Flash_ptr = (char*) address;
value = *Flash_ptr;
LCDMEM[2] = value ;
return (value);
}
It counts 0 to 9 .... on one cell of the LCD and on the other it shows the flash memory's content which is as the same as count-up cell.
The LCD shows like this:
flash ram
1 sec : 0 0
2 sec: 1 1
3 sec: (dummy) 2
4 sec: 3
5 sec: 4
...
Why the flash goes crazy from 2 on?!!!