本帖最后由 stm8l151f2 于 2011-6-20 18:12 编辑
- #include "stm8l10x.h"
- #include "periph_io.h"
- #include "delay.h"
- __root __no_init volatile uint8 flash_u8 @0x9000;
- uint32 addr;
- void main( void )
- {
-
- FLASH_WaitForLastOperation();
- FLASH_Unlock(FLASH_MemType_Program);
-
- addr = (uint32_t)&flash_u8;
-
- FLASH_ProgramByte(addr , 0xaa);
- FLASH_WaitForLastOperation();
- if(flash_u8!=0xaa)
- {
- while(1);
- }
-
- asm("nop"); //设置断点
-
- FLASH_ProgramByte(addr , 0xbb);
- FLASH_WaitForLastOperation();
- if(flash_u8!=0xbb)
- {
- while(1);
- }
-
- asm("nop"); //设置断点
-
- FLASH_EraseByte(addr);
- FLASH_WaitForLastOperation();
-
- if(flash_u8!=0x00)
- {
- while(1);
- }
-
- asm("nop"); //设置断点
-
- FLASH_Lock(FLASH_MemType_Program);
-
- while(1);
-
- }
可以写进去。
只是IAR调试显示的值不会(IAR可能认为FLASH的是不变的,没有刷新)。
你全速运行可以看到。
|