|
发表于 2008-5-19 12:56:46
|
显示全部楼层
void flash_eraseFLASH(int *seg)
{
FCTL2 = FWKEY | FSSEL0 | 20; //clock source is MCLK, divisor is 20
do
{
_NOP();
} while(FCTL3 & 0x0001); // wait for BUSY to reset
FCTL3 = FWKEY; // reset the LOCK bit to enable program/erase
FCTL1 = FWKEY | ERASE; // set single segment erase function
*seg = 0xFF; // do a dummy write to start erase
FCTL3 = FWKEY | LOCK; // lock the flash again
return;
}
void flash_writeByte(int *dst, int value)
{
FCTL2 = FWKEY | FSSEL0 | 20; //clock source is MCLK, divisor is 20
do
{
_NOP();
} while(FCTL3 & 0x0001); // wait for BUSY to reset
FCTL3 = FWKEY; // reset the LOCK bit to enable program/erase
FCTL1 = FWKEY | WRT; // set WRT for single acces
*dst = value; // do the write as a byte
*Flash_ptr = *dst;
return;
}
/////////////
写数据必需先擦除,再写.... |
|