⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inflash.c

📁 基于MST-G240128点阵液晶的 状态机机制 人机界面四级滚屏菜单 源代码 ,带时间片机制模拟操作系统
💻 C
字号:
/****************************************************************************
 **
 ** 文件名:  InFLASH.c
 ** 功能:    C8051Fxxx的片内FLASH读写驱动;
 ** 创建时间:2005.08.05

 ** 修改时间:2005.12.01
 ** 修改说明:

 ** 作者:    李立学
 ** 版权申明:可以拷贝,可以修改,但必须保留修改时间和作者信息
 ** 
 ****************************************************************************/


#include "LZK.H"	          



uint16 xdata *InFlashWrPtr;

uint16 code  *InFlashRdPtr;


/****************************************************************************
** 函数名称: InFlash_Init()
** 功能描述: 内部FLASH初始化.
** 入口参数: InFlashAddr:要初始化的FLASH块首地址;
** 出口参数: bit:0/1:操作失败/成功.
** 全局变量: 无
** 调用模块: 无
** 说明:
****************************************************************************/
bit InFlash_Init( uint16 InFlashAddr )

{
   if( ( InFlashAddr % 0x200 ) != 0 )   // Must a Block Start Address.
      return 0;                         // Fail.
//FLSCL: FLASH Memory Control

//  Bit7   Bit6   Bit5   Bit4   Bit3   Bit2   Bit1   Bit0

//  FOSE   FRAE   Res    Res    Res    Res    Res    FLWE

//Bit7: FOSE: FLASH One-Shot Timer Enable  This isth e timer that turnso ff the sense ampsaf ter a FLASH read.

//      0: FLASH One-Shot Timer disabled.

//      1: FLASH One-Shot Timer enabled (recommended setting.)

//Bit6: FRAE: FLASH Read AlwaysE nable

//      0: FLASH readso ccur asn ecessary (recommended setting.).

//      1: FLASH reads occur every system clock cycle.

//Bits5-1: RESERVED. Read = 00000b. Must Write 00000b.

//Bit0: FLWE: FLASH Read/Write Enable   This bit must be set to allow FLASH writes from user software.

//      0: FLASH writesd isabled.

//      1: FLASH writesen abled.



//PSCTL: Program Store Read/Write Control

//  Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0

//   -    -    -    -    -   SFLE PSEE PSWE

//Bits7-3: UNUSED. Read = 00000b, Write = don't care.

//Bit2: SFLE: Scratchpad FLASH Memory Access Enable   When thisb it iss et, FLASH reads and writesfro m user software are directed to the 128-byte Scratchpad

//            FLASH sector. When SFLE is set to logic 1, FLASH accesses out of the address range 0x00-0x7F should not be attempted. Reads/Writes out of this range will yield undefined results.

//      0: FLASH access from user software directed to the 64k byte Program/Data FLASH sector.

//      1: FLASH access from user software directed to the 128 byte Scratchpad sector.

//Bit1: PSEE: Program Store Erase Enable.  Setting thisb it allowsan entire page of the FLASH program memory to be erased provided thePSWE bit is also set.

//            After setting this bit, a write to FLASH memory using the MOVX instruction will erase the entire page that contains the location addressed by the MOVX instruction. 

//            The value of the data byte written doesn ot matter. Note: The FLASH page containing the Read Lock Byte and Write/Erase Lock Bytes cannot be erased by software.

//      0: FLASH program memory erasure disabled.

//      1: FLASH program memory erasure enabled.

//Bit0: PSWE: Program Store Write Enable.   Setting thisb it allowswr iting a byte of data to the FLASH program memory using the MOVX write instruction. The location must be erased prior to writing data.

//      0: Write to FLASH program memory disabled. MOVX write operations target External RAM.

//      1: Write to FLASH program memory enabled. MOVX write operationst arget FLASH memory.



   SFRPAGE = 0x00;


   FLSCL = 0x81;

   PSCTL = 0x03;


   InFlashWrPtr = InFlashAddr;
   *InFlashWrPtr = 0;


   PSCTL = 0x01;
   return 1;
}


/****************************************************************************
** 函数名称: InFlashWriteEn()
** 功能描述: 内部FLASH写使能.
** 入口参数: InFwEN:1:允许写入;
** 出口参数: 无.
** 全局变量: 无
** 调用模块: 无
** 说明:
****************************************************************************/
void InFlashWriteEn(bit InFwEN)

{

   SFRPAGE = 0x00;


   if( InFwEN == 1 )

     FLSCL = FLSCL | 0x01;

   else

     FLSCL = FLSCL & 0xfe;

}



/****************************************************************************
** 函数名称: InFlashEraseEn()
** 功能描述: 内部FLASH块擦除使能.
** 入口参数: InFeEN:1:允许块擦除;
** 出口参数: 无.
** 全局变量: 无.
** 调用模块: 无.
** 说明:
****************************************************************************/
void InFlashEraseEn(bit InFeEN)

{

   SFRPAGE = 0x00;


   if( InFeEN == 1 )

     PSCTL = PSCTL | 0x02;

   else

     PSCTL = PSCTL & 0xfd;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -