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

📄 flash.c

📁 c8051f310xmodembootloader.rar
💻 C
字号:
#include <c8051f310.h>                
#include <intrins.h>
#include <string.h>
#include <stdio.h>
#include "bootloader.h"
#include "flash.h"
#include "xmodem.h"

/******************************************************************************
**函数功能:flash_c8051f310	 PageEras
**入参:	addr
**返回值:	无
**作者:	jerkoh
**日期:	2009-03-16
**说明:	c8051f310
******************************************************************************/ 

void FLASH_PageErase (UINT addr)
{
   bit EA_SAVE = EA;                // preserve EA
   UCHAR xdata * data pwrite;       // FLASH write pointer

   EA = 0;                          // disable interrupts

                                    // change clock speed to slow, then restore later
   VDM0CN = 0x80;                   // enable VDD monitor
   RSTSRC = 0x02;                   // enable VDD monitor as a reset source
   pwrite = (UCHAR xdata *) addr;
   FLKEY  = 0xA5;                   // Key Sequence 1
   FLKEY  = 0xF1;                   // Key Sequence 2
   PSCTL |= 0x03;                   // PSWE = 1; PSEE = 1
   VDM0CN = 0x80;                      // enable VDD monitor
   RSTSRC = 0x02;                   // enable VDD monitor as a reset source
   *pwrite = 0;                     // initiate page erase
   PSCTL &= ~0x03;                  // PSWE = 0; PSEE = 0
   EA = EA_SAVE;                    // restore interrupts
}
/******************************************************************************
**函数功能:flash_c8051f310	 ByteWrite
**入参:	addr
**返回值:	无
**作者:	jerkoh
**日期:	2009-03-16
**说明:	c8051f310
******************************************************************************/
void FLASH_ByteWrite (UINT addr, UCHAR byte)
{
   bit EA_SAVE = EA;                   // preserve EA
   UCHAR xdata * data pwrite;          // FLASH write pointer

   EA = 0;                             // disable interrupts

                                       // change clock speed to slow, then restore later
   VDM0CN = 0x80;                      // enable VDD monitor
   RSTSRC = 0x02;                      // enable VDD monitor as a reset source
   pwrite = (UCHAR xdata *) addr;

   FLKEY  = 0xA5;                      // Key Sequence 1
   FLKEY  = 0xF1;                      // Key Sequence 2
   PSCTL |= 0x01;                      // PSWE = 1
   VDM0CN = 0x80;                      // enable VDD monitor
   RSTSRC = 0x02;                      // enable VDD monitor as a reset source
   *pwrite = byte;                     // write the byte
   PSCTL &= ~0x01;                     // PSWE = 0
   EA = EA_SAVE;                       // restore interrupts
}
/******************************************************************************
**函数功能:flash_c8051f310	 PageRead
**入参:	addr
**返回值:	无
**作者:	jerkoh
**日期:	2009-03-16
**说明:	c8051f310
******************************************************************************/
UCHAR FLASH_PageRead(UINT addr)
{ 
   bit EA_SAVE = EA;                   // preserve EA
   UCHAR dat;
   char code * data pread;             // FLASH read pointer
   EA = 0;

   pread=(char code *)addr;
   dat=*pread;   
   EA = EA_SAVE;                       // restore interrupts
   return dat;
}

/***********************(C) COPYRIGHT 2009 SKsystem***************************/

⌨️ 快捷键说明

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