?? eeprom.c
字號:
/*= eeprom.c ===================================================================
*
* Copyright (C) 2004 Nordic Semiconductor
*
* This file is distributed in the hope that it will be useful, but WITHOUT
* WARRANTY OF ANY KIND.
*
* Author(s): Ole Saether
*
* COMPILER:
*
* This program has been tested with Keil C51 V7.09
*
* $Revision: 3 $
*
*==============================================================================
*/
//#include "nrfexx.h"
//#include "util.h"
#include "eeprom.h"
#define EE_WRSR 0x01
#define EE_WRITE 0x02
#define EE_READ 0x03
#define EE_WRDI 0x04
#define EE_RDSR 0x05
#define EE_WREN 0x06
void EEInit(void)
{
P0_DIR &= ~0x01; // EECSN is output
SPICLK = 2; // CLK/32 SPI clock
EECSN = 1;
SPI_CTRL = 0x01; // Connect internal SPI to P1
}
unsigned char EEStatus(void)
{
unsigned char b;
EECSN = 0;
SpiReadWrite(EE_RDSR);
b = SpiReadWrite(0);
EECSN = 1;
return b;
}
/***************************************************************************************
Function: EERead
Description: 從eeprom中讀出一個數(shù)據(jù)
Calls: SpiReadWrite();
Called By:
void EERxbyte(unsigned int addr_str,unsigned char *a)
Input:
addr: 要讀出數(shù)據(jù)的地址
Output:
Return:
b:讀出的數(shù)據(jù)
Others:
***************************************************************************************/
unsigned char EERead(unsigned int addr)
{
unsigned char b;
while ((EEStatus() & 0x01) != 0x00) // Wait if busy
;
EECSN = 0;
SpiReadWrite(EE_READ);
SpiReadWrite(addr >> 8);
SpiReadWrite(addr & 0xff);
b = SpiReadWrite(0);
EECSN = 1;
return b;
}
/***************************************************************************************
Function: EEWrite
Description: 寫一個數(shù)據(jù)到eeprom中,
Calls: SpiReadWrite();
Called By:
vvoid EEWxbyte(unsigned int addr_str,unsigned char *a)
Input:
addr: 要寫入的地址 b,要寫入的數(shù)據(jù)
Output:
Return:
Others:
***************************************************************************************/
void EEWrite(unsigned int addr, unsigned char b)
{
while((EEStatus() & 0x01) != 0x00) // Wait if busy
;
EECSN = 0;
SpiReadWrite(EE_WREN);
EECSN = 1;
EECSN = 0;
SpiReadWrite(EE_WRITE);
SpiReadWrite(addr >> 8);
SpiReadWrite(addr & 0x00ff);
SpiReadWrite(b);
EECSN = 1;
}
/***************************************************************************************
Function: EEWxbyte
Description: 連續(xù)的寫四個數(shù)到eeprom中
Calls: EEWrite(unsigned int addr, unsigned char b)
Called By:
void main(void)
Input:
addr: 寫數(shù)據(jù)的開始地址 a:寫入數(shù)據(jù)的開始地址 I:寫入數(shù)據(jù)的個數(shù)
Output: a[0]-a[I-1];
Return:
Others:
***************************************************************************************
void EEWxbyte(unsigned int addr_str,unsigned char *a,unsigned char I)
{
unsigned char i;
unsigned char *snr;
memcpy(snr,a,I);
for(i=0;i++;i<I)
{
EEWrite(addr_str, snr[i]);
//EEWrite(addr_str, 0x23);
addr_str++;
}
memcpy(a,snr,I);
}
***************************************************************************************
Function: EERxbyte
Description: 連續(xù)的寫四個數(shù)到eeprom中
Calls: EERrite(unsigned int addr, unsigned char b)
Called By:
void main(void)
Input:
addr: 讀數(shù)據(jù)的開始地址 a:讀數(shù)據(jù)的開始地址 I:寫入數(shù)據(jù)的個數(shù)
Output: a[0]-a[i];
Return:
Others:
***************************************************************************************
void EERxbyte(unsigned int addr_str,unsigned char *a,unsigned char I)
{
unsigned char i;
unsigned char *snr;
memcpy(snr,a,I);
for(i=0;i++;i<I)
{
snr[i] = EERead(addr_str);
addr_str++;
}
memcpy(a,snr,I) ;
}
*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -