?? fram.c
字號:
//-----------------------------------------------------------------------------
// FRAM.C
//-----------------------------------------------------------------------------
// Author Zhou Ke
// Email zhoukesec@163.com
// Target: FRAM_UART
// Tool chain: Keil C51 8.02 / Keil EVAL C51
// Project Name: FRAM_UART
//
//
// Release 1.0
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include <intrins.h>
#include "stc12c2052.h"
#include "fram.h"
extern volatile unsigned char tx_buffer[8];
extern volatile unsigned char rx_buffer[4];
extern volatile unsigned char tmp_buffer[4];
/*------------------------------------------------------------------------------
Function Name : delay
Description : wait a short while
Parameters :
Input : none
Output : none
Return : none
Notes :
------------------------------------------------------------------------------*/
void delay(void)
{
unsigned char i;
for(i=0;i<100;i++)
_nop_();
}
/*------------------------------------------------------------------------------
Function Name : fram_write_enable
Description : enable the write function
Parameters :
Input : none
Output : none
Return : none
Notes :
------------------------------------------------------------------------------*/
void fram_write_enable()
{
FRAM_CS = 0;
SPSTAT = 0xC0;
SPDAT = WREN;
while((SPSTAT & 0x80) == 0);
FRAM_CS = 1;
}
/*------------------------------------------------------------------------------
Function Name : fram_read_status
Description : read status of the fram
Parameters :
Input : none
Output : none
Return : none
Notes :
------------------------------------------------------------------------------*/
/*
unsigned char fram_read_status()
{
FRAM_CS = 0;
SPSTAT = 0xC0;
SPDAT = RDSR;
while((SPSTAT & 0x80) == 0);
SPSTAT = 0xC0;
SPDAT = 0x00;
while((SPSTAT & 0x80) == 0);
FRAM_CS = 1;
return SPDAT;
}
*/
/*------------------------------------------------------------------------------
Function Name : fram_read_data
Description : read data from fram to ram
Parameters :
Input : none
Output : none
Return : none
Notes :
------------------------------------------------------------------------------*/
void fram_read_data(void)
{
unsigned char sum,i;
sum = 0;
FRAM_CS = 0;
//Command
SPSTAT = 0xC0;
SPDAT = READ;
while((SPSTAT & 0x80) == 0);
//Address
SPSTAT = 0xC0;
SPDAT = 0x00;
while((SPSTAT & 0x80) == 0);
for(i = 0; i < 4; i++){
SPSTAT = 0xC0;
SPDAT = 0x00;
while((SPSTAT & 0x80) == 0);
tx_buffer[i+2] = SPDAT;
sum += tx_buffer[i+2];
}
tx_buffer[6] = sum;
FRAM_CS = 1;
}
/*------------------------------------------------------------------------------
Function Name : fram_write_data
Description : write data from ram to fram
Parameters :
Input : none
Output : none
Return : none
Notes :
------------------------------------------------------------------------------*/
void fram_write_data(void)
{
unsigned char i;
fram_write_enable();
delay();
FRAM_CS = 0;
//Command
SPSTAT = 0xC0;
SPDAT = WRITE;
while((SPSTAT & 0x80) == 0);
//Address
SPSTAT = 0xC0;
SPDAT = 0x00;
while((SPSTAT & 0x80) == 0);
for(i = 0; i < 4; i++){
SPSTAT = 0xC0;
SPDAT = tmp_buffer[i];
while((SPSTAT & 0x80) == 0);
delay();
}
FRAM_CS = 1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -