📄 at45db041.c
字号:
#include "at45db041.h"
#include "msp430x16x.h"
INT8U DF_R[256];//存放读取的值
/*
********************************************************************************
**函数名称: DF_Send_Byte()
**函数功能: 发送字节
**入口参数: INT8U word
**出口参数: 无
********************************************************************************
*/
void DF_Send_Byte(INT8U word)
{
INT8U i;
INT8U Tamp;
for (i=0;i<8;i++)
{
DF_SCK_0;
Tamp = word;
Tamp &= 0x80;
if(!Tamp)
DF_SI_0;
else
DF_SI_1;
DF_SCK_1;
word = word << 1;
}
}
/*
********************************************************************************
**函数名称: DF_Read_Byte(void)
**函数功能: 读取一个字节的内容
**入口参数: 无
**出口参数: INT8U R_word
********************************************************************************
*/
INT8U DF_Read_Byte(void)
{
INT8U i;
INT8U R_word = 0x00;
DF_CS;
for(i=0;i<8;i++)
{
R_word = R_word << 1;
DF_SCK_0;
DF_SCK_1;
if(P4IN & 0x10)
R_word |= 0x01;
else
R_word &= 0xFE;
DF_SCK_0;
}
return R_word;
}
/*
********************************************************************************
**函数名称: void DF_Stop(void)
**函数功能: 停止操作
**入口参数: 无
**出口参数: 无
********************************************************************************
*/
void DF_Stop(void)
{
P4OUT |= 0X27;
}
/*
********************************************************************************
**函数名称: void DF_Write_Buf()
**函数功能: 写Buffer
**入口参数: INT8U type--1选择BUF1,2选择BUF2;
** unsigned int addr--BUF地址(0~263)
** INT8U *data--要写入的数据首地址
** INT16U data_L--待写入数据的长度
**出口参数: 无
********************************************************************************
*/
void DF_Write_Buf(INT8U type,unsigned int addr,INT8U *data,INT16U data_L)
{
unsigned char addr_H = addr>>8;
unsigned char addr_L = addr&0x00ff;
while(!DF_Status());
switch(type)
{
case 1:type=0x84;break;
case 2:type=0x87;break;
}
INT16U j;
DF_CS;
DF_Send_Byte(type);
DF_Send_Byte(0x00);
DF_Send_Byte(addr_H);
DF_Send_Byte(addr_L);
for(j=0;j<data_L;j++)
{
DF_Send_Byte(data[j]);
}
DF_Stop();
}
/*
********************************************************************************
**函数名称: void DF_Read_Buf()
**函数功能: 从BUF中读取数据,放入DF_R[]数组中
**入口参数: INT8U type--1选择BUF1,2选择BUF2
** unsigned int addr--读数据的地址
** INT16U data_L--要读取的长度
**出口参数: 无
********************************************************************************
*/
void DF_Read_Buf(INT8U type,unsigned int addr,INT16U data_L)
{
unsigned char addr_H = addr>>8;
unsigned char addr_L = addr&0x00ff;
while(!DF_Status());
switch(type)
{
case 1:type=0x54;break;
case 2:type=0x56;break;
}
INT16U j;
DF_CS;
DF_Send_Byte(type);
DF_Send_Byte(0x00);
DF_Send_Byte(addr_H);
DF_Send_Byte(addr_L);
DF_Send_Byte(0xff);
for(j=0;j<data_L;j++)
{
DF_R[j] = DF_Read_Byte();
}
DF_Stop();
}
/*
********************************************************************************
**函数名称: void DF_Write_Main()
**函数功能: 写主存,Buffer to Main Memory Page Program with Built_In Erase
**入口参数: unsigned char type--1选择BUF1,2选择BUF2
** unsigned int addr--主存的地址
** unsigned char *data--待写入的数据
** unsigned int L--待写入数据的长度
**出口参数: 无
********************************************************************************
*/
void DF_Write_Main(unsigned char type,unsigned int addr,unsigned char *data,unsigned int L)
{
unsigned char addr_H = addr>>7;
unsigned char addr_L = (addr<<1) & 0x00FF;
unsigned char type1;
unsigned char type2;
switch(type)
{
case 1:type1=0x84;type2=0x83;break;
case 2:type1=0x87;type2=0x86;break;
}
while(!DF_Status());
DF_CS;
DF_Write_Buf(type1,0,data,L);
while(!DF_Status());
DF_CS;
DF_Send_Byte(type2);
DF_Send_Byte(addr_H);
DF_Send_Byte(addr_L);
DF_Send_Byte(0x00);
DF_Stop();
}
/*
********************************************************************************
**函数名称: void DF_Read_Main()
**函数功能: 读主存
**入口参数: unsigned int addr_P--主存页地址
** unsigned int addr_B--主存页中字节地址
** unsigned int L--读取数据的长度
********************************************************************************
*/
void DF_Read_Main(unsigned int addr_P,unsigned int addr_B,unsigned int L)
{
unsigned char addr_PH = addr_P>>7;
unsigned char addr_PL = ((addr_P<<1)&0x00ff)+(addr_B>>8);
unsigned char addr_BL = addr_B & 0x00ff;
while(!DF_Status());
INT16U j;
DF_CS;
DF_Send_Byte(0x52);
DF_Send_Byte(addr_PH);
DF_Send_Byte(addr_PL);
DF_Send_Byte(addr_BL);
DF_Send_Byte(0x00);
DF_Send_Byte(0x00);
DF_Send_Byte(0x00);
DF_Send_Byte(0x00);
for(j=0;j<L;j++)
{
DF_R[j]=DF_Read_Byte();
}
DF_Stop();
}
/*
********************************************************************************
**函数名称: void DF_Main2Buf(INT8U type)
**函数功能: 将主存中addr_P的内容复制到BUF中
**入口参数: unsigned char type--1选择BUF1,2选择BUF2
** unsigned int addr_P--页地址
**出口参数: 无
********************************************************************************
*/
void DF_Main2Buf(INT8U type,unsigned int addr_P)
{
unsigned char addr_PH = addr_P>>7;
unsigned char addr_PL = (addr_P<<1);
switch(type)
{
case 1:type=0x53;break;
case 2:type=0x55;break;
}
DF_CS;
DF_Send_Byte(type);
DF_Send_Byte(addr_PH);
DF_Send_Byte(addr_PL);
DF_Send_Byte(0x00);
DF_Stop();
}
/*
********************************************************************************
**函数名称: void DF_Port_Init(void)
**函数功能: 端口初始化
**入口参数: 无
**出口参数: 无
********************************************************************************
*/
void DF_Init(void)
{
P4DIR = 0X2F;
P4OUT |= 0X27;
}
/*
********************************************************************************
**函数名称: INT8U DF_Status(void)
**函数功能: 读取状态
**入口参数: 无
**出口参数: INT8U status--1不忙,0忙
********************************************************************************
*/
INT8U DF_Status(void)
{
INT8U status=0;
DF_CS;
DF_Send_Byte(0x57);
status = DF_Read_Byte();
DF_Stop();
if(status&0x80)
return 1;
else
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -