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

📄 hal_flash.c

📁 这是nrf24lu1的无线鼠标源代码,应用平台是keil c
💻 C
字号:
/** @file
 * Implementation of the Flash HAL module
 * @author Ole Saether
 */

#include <Nordic\reg24lu1.h>
#include "hal_flash.h"

void hal_flash_page_erase(uint8_t pn)
{
  // Save interrupt enable state and disable interrupts:
  F0 = EA;
  EA = 0;
  // Enable flash write operation:
  FCR = 0xAA;
  FCR = 0x55;
  WEN = 1;
  //
  // Write the page address to FCR to start the page erase
  // operation. This operation is "self timed"; the CPU
  // will halt until the operation is finished:
  FCR = pn;
  WEN = 0;
  EA = F0; // Restore interrupt enable state
}

void hal_flash_byte_write(uint16_t a, uint8_t b)
{
  uint8_t xdata *data pb;

  // Save interrupt enable state and disable interrupts:
  F0 = EA;
  EA = 0;
  // Enable flash write operation:
  FCR = 0xAA;
  FCR = 0x55;
  WEN = 1;
  //
  // Write the byte directly to the flash. This operation is
  // "self timed"; the CPU will halt until the operation is
  // finished:
  pb = (uint8_t xdata *)a;
  *pb = b;
  WEN = 0;
  EA = F0; // Restore interrupt enable state
}

void hal_flash_bytes_write(uint16_t a, uint8_t *p, uint16_t n)
{
  uint8_t xdata *data pb;

  // Save interrupt enable state and disable interrupts:
  F0 = EA;
  EA = 0;
  // Enable flash write operation:
  FCR = 0xAA;
  FCR = 0x55;
  WEN = 1;
  //
  // Write the bytes directly to the flash. This operation is
  // "self timed"; the CPU will halt until the operation is
  // finished:
  pb = (uint8_t xdata *)a;
  while(n--)
  {
    //lint --e{613} Suppress possible use of null pointer warning:
    *pb = *p;
    pb++;
    p++;
  }
  WEN = 0;
  EA = F0; // Restore interrupt enable state
}

uint8_t hal_flash_byte_read(uint16_t a)
{
  //lint --e{613} Suppress possible use of null pointer warning:
  uint8_t xdata *pb = (uint8_t xdata *)a;
  return *pb;
}

void hal_flash_bytes_read(uint16_t a, uint8_t *p, uint16_t n)
{  
  uint8_t xdata *pb = (uint8_t xdata *)a;
  while(n--)
  {
    //lint --e{613} Suppress possible use of null pointer warning:
    *p = *pb;
    pb++;
    p++;
  }  
}

⌨️ 快捷键说明

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