https://static.assets-stash.eet-china.com/album/old-resources/2009/8/26/cfd5b8a5-b545-4486-a952-d974f4af349d.rar
memey.c ATMEL的DATAFLASH操作函数库(FOR AT45DB161D)
/*
//调用字模写入程序;
G_ATFlash_buffer=1;
pageaddr="0";
addr_counter=0;
// &ASC_MSK812[kk].Asc[0] === ppziku=&ASC_MSK812[kk].Asc[0]; //??????
for (kt=0;kt<5;kt++) // 5页 , 5*5=25个字模; 16<21
{
for (kj=0;kj<21;kj++) // 12*N + 字库的代码 256除以12==21个代码;
{
G_ATFlash_Page=pageaddr;
//每次写12格,0--11, 地址加一, 对于结构数据来说, 以次排列字模的数据;&ASC_MSK812[kk]
DF_writeconst_zimobuf (&ASC_MSK812[kj+kt*21].Asc[0] ,G_ATFlash_buffer,addr,12); //&test 起始地址 addr, 写两个;
//FlashBufferWrite(addr, BUFFER_1_WRITE, 2, &temper); //int temper
addr=addr+12; //int 0--11 addr=0; //页面的地址;
addr_counter++; //统计字体数目;
}// for 1
// if (addr >=15*12 ) //21*12=252
// {
// DF_page_earse(G_ATFlash_Page);
// BufferToPageWithErase(B1_TO_PAGE_WITH_ERASE, pageaddr);
DF_buf_to_mm ( G_ATFlash_buffer,G_ATFlash_Page ); //G_ATFlash_buffer , 会擦除吗????
pageaddr++;
G_ATFlash_Page=pageaddr;
addr=0; // 页面的地址;
if(pageaddr>=4095) pageaddr=0;
// } // if
// pageaddr++;
if(addr_counter>=95) break; //数据超出了;
}//for 2
///////////////////////////////////////////////////////////////////////////////////////////////////
*/
// for (kt=0;kt<5;kt++)
// {
//
//// Ki="0"; //地址指针;
// for(ki=0;ki<16;ki++)
// {
//// Showascll_8_12(kt,ki,&ASC_128_MSK[(12*Ki+12*16*Kt)],1); // 1
// Showascll_8_12(kt,ki,&ASC_MSK812[ki+kt*16],1);
// }
//
// }
// for(ki=0;ki<63;ki++)
// {
// Flash_datatemp[ki]=0; //正弦值;
// }
//确定,字符的页区域, 释放到缓冲区域; 再计算定位到具体的字符地址偏移量;
G_ATFlash_buffer=1;
// pageaddr=0;
G_ATFlash_Page=0;
G_ATFlash_addr=0; //页面的地址;
DF_mm_to_buf(G_ATFlash_buffer,G_ATFlash_Page); //主存到缓存, 经过BUFFER;
// &ASC_MSK812[kk].Asc[0] === ppziku=&ASC_MSK812[kk].Asc[0]; //??????
addr_counter=0;
for (kt=0;kt<5;kt++) // 5页 , 5*5=25个字模;
{
// DF_mm_to_buf(G_ATFlash_buffer,G_ATFlash_Page); //主存到缓存, 经过BUFFER;
for(kj=0;kj<16;kj++) // 12*N + 字库的代码 256除以12==21个代码;
{
// Showascll_8_12(kt,ki,&ASC_MSK812[ki+kt*16],1);
// temper="kk"+100; //int ==2 char
G_ATFlash_Page=0;
DF_read_buf (&Asc12_readflashatram[0].Asc[0],G_ATFlash_buffer,G_ATFlash_addr,12);
//每次写12格,0--11, 地址加一, 对于结构数据来说, 以次排列字模的数据;&ASC_MSK812[kk]
// DF_read_buf ( Flash_datatemp,G_ATFlash_buffer,addr,12);
// DF_writeconst_zimobuf (&ASC_MSK812[kk].Asc[0] ,G_ATFlash_buffer,addr,12); //&test 起始地址 addr, 写两个;
Showascll_8_12(kt,kj,&Asc12_readflashatram[0],1);
// FlashBufferWrite(addr, BUFFER_1_WRITE, 2, &temper); //int temper
G_ATFlash_addr=G_ATFlash_addr+12; //int 0--11 addr=0; //页面的地址;
addr_counter++; //统计字体数目;
if(addr_counter>96) break; //数据超出了;
if (G_ATFlash_addr >=21*12 ) //21*12=252 不能放到外面,因为,那样会错过换页的;
{
// DF_buf_to_mm ( G_ATFlash_buffer,G_ATFlash_Page ); //G_ATFlash_buffer , 会擦除吗?
G_ATFlash_Page++;
// DF_page_earse(G_ATFlash_Page);
//BufferToPageWithErase(B1_TO_PAGE_WITH_ERASE, pageaddr);
DF_mm_to_buf( G_ATFlash_buffer, G_ATFlash_Page); //主存到缓存, 经过BUFFER; 换页后再读才好
G_ATFlash_addr=0; //页面的地址;
if(G_ATFlash_Page>=4095) G_ATFlash_Page=0;
} // if
}// for 1
// pageaddr++;
}//for 2
Clear_lcd(0);
//最后,通过计算得到, 待显示字符号到读取数据,到显示的过程; 如'a' ==> 计算存储区域, 读缓冲,在送显示;
// 从字符标号,到偏移量,再到数据,直到写入显示;关键数据是, 页地址page与偏移量addr
Asc_12chardata='C'; // 存待写字符, 计算出页与偏移地址;
// &ASC_MSK812['A'-0x20] 21--N ASC_MSK812[kj+kt*21] ==>base_page=0
temp='8'-0x20; //结构的偏移
G_ATFlash_Page=temp/21; //21个数据 ,每页
G_ATFlash_addr=(temp%21)*12; //偏移量addr
DF_mm_to_buf( G_ATFlash_buffer, G_ATFlash_Page); //必须要有的;
DF_read_buf (&Asc12_readflashatram[0].Asc[0],G_ATFlash_buffer,G_ATFlash_addr,12);
//每次写12格,0--11, 地址加一, 对于结构数据来说, 以次排列字模的数据;&ASC_MSK812[kk]
// DF_read_buf ( Flash_datatemp,G_ATFlash_buffer,addr,12);
// DF_writeconst_zimobuf (&ASC_MSK812[kk].Asc[0] ,G_ATFlash_buffer,addr,12); //&test 起始地址 addr, 写两个;
Showascll_8_12(1,1,&Asc12_readflashatram[0],1);
// for(i=0;i<4096;i++)//2M=2*(256*8)*1024*2
// 次数0-3 版本4
/****************************************************************
* ATMEL的DATAFLASH操作函数库(FOR AT45DB161D) *
* *
*
* 最后修改时间:2007年2月18日(大年初一) *
* *
* 感谢www.ouravr.com、
* *
* 己的一些日常积累拿出来分享,这个世界需要更多的无私开源, *
-- 作者:microcon
-- 发布时间:2007-8-4 16:05:00 -- 发布时间:2007-8-4 17:50:00
*****************************************************************/
//#include <avr/io.h>
//#include <util/delay.h>
//#include "main.h"
#include "mainconfig.h" //系统配置说明; //#include <pic18.h>
#include "memory.h" //可对。C的所有函数调用; //dataout
//99 99 99 99 (高到低)
// --------------------------------------------------------------------------------
//#define AT_CS RC2 //1写数据,0写指令
#define Num 50 // ??
// unsigned char DF_buffer[50];//Num bank1
char cc="0";// char Myspidata="0";
unsigned int AT45DB161_PageAddr=0; //地址, ? 哪里的地址啊;
unsigned int G_ATFlash_Page=0; //页面;
unsigned char G_ATFlash_buffer=1; //缓存指定; 对指定数据的读是 要通过缓存的;
//SMP: Sample bit
//CKE: SPI Clock Edge Select
//留意,函数间的影响;
// SSPCON1=0x32; // 1/64 clk 修改传送的速度!!!
void SPI_INIT(void) //PIC16F
{
PIR1=PIR1&0xf7; //bit3
SSPCON1=0x30; //CKP=1(无效为1); SSPEN="1";时钟= FOSC/4 同步串行口控制寄存器
//bit 3-0 SSPM<3:0>:同步串行口模式选择位
//0000 = SPI 主模式,时钟= FOSC/4
SSPSTAT=0xC0; // SMP="1"; CKE="1"(无效到有郊); 设置SPI的控制方式,允许SSP方式,并且时钟上边沿 (下降)沿发送 CKP
TRISC =0xd7; //TRISC& // SDO(RC5)引脚为输出,SCK(RC3)引脚为输出
SSPCON1=0x32; // 1/64 clk
// TRISC="0xec" ; // c.3sclk c4 in // c.5dou //SDO引脚为输出,SCK引脚为输
CKP="1"; //降沿传送;
// TRISC="0xD7"; //c.3sclk c.5dout //SDO引脚为输出,SCK引脚为输出
// TRISC=TRISC&0xf7; // SCK(RC3)引脚为输出
// TRISC=TRISC|0x10; // SDI(RC4)引脚为输入
// TRISC="0xD7"; //
ADCON1=0x07; //实现对A口进行初始化//ADCON1=0x06; // P114 设置与模拟通道有关的口全部为数字
TRISA=0x00; // 设置A口所有引脚为输out;
PORTA=0x00; //RA0--5
}//
// --------------------------------------------------------------------------------
//模拟SPI 初始化
void Moni_SPI_INIT(void) //PIC16F // SSPCON1=0x32; // 1/64 clk
{
// SSPSTAT=0xC0; // SMP="1"; CKE="1"(无效到有郊); 设置SPI的控制方式,允许SSP方式,并且时钟上边沿 (下降)沿发送 CKP
TRISC="0xd7"; //TRISC&
// SDO(RC5)引脚为输出,SCK(RC3)引脚为输出
// c.3sclk c4 in //c.5dou //SDO引脚为输出,SCK引脚为输
// CKP="1"; //降沿传送;
}//
// --------------------------------------------------------------------------------
/*
// --------------------------------------------------------------------------------
void write_SPI (unsigned char data)
{
//data=SSPBUF; //读走;
char dat;
SSPBUF=data; //启动发送
do {
;
}while(SSPIF==0); //查询发送完成, 若打开了中断(适用于从模式),不能在中断时清SSPIF;
SSPIF=0;
dat="SSPBUF"; //读走;
//不可少的延时, 不知道为什么, 没有就会错;
asm("nop"); // NOP;
asm("nop"); // NOP;
} //
// SPIholdclk="1"; //锁存的准备;
// SPIholdclk="1";
unsigned char GetSPIByte(void) //finish //
{
unsigned char data;
// SPI_In_initial(); // SPI输入初始化子程序
// RA4=0; // 74HC165并行置数使能,将8位开关量置入器件
// RA4=1; // 74HC165移位置数使能,芯片串行工作
data=SSPBUF; // 读走;
SSPBUF=0x00; //启动SPI,此操作用于清除SSPSTAT的BF位
do
{
;
}while(SSPIF==0); //查询数据接收完毕否?
//统计8个时钟;
//清除SSPIF标志
data=SSPBUF;
SSPIF=0;
return(data); //返回接收到的数据
}//
*/
// SPIdo = 1; //对应从机的SI
// SPIdin; //对应从机的SO //SO; //Mi
// SPIclk =1;
//
//================================================================//
/*功能说明: SPI总线通用写操作子程序 */
//模拟SPI
//void hc59send(uchar c) //模拟SPI
// SPIholdclk=0; //锁存的准备;
// 什么沿发送一个位呢??? 上升沿???
// 下降沿发一个;
void write_SPI (unsigned char data)
{
char temp="0";
for(temp=0;temp<8;temp++)
{
SPIclk="1"; //
if(data &0x80)
SPIdo = 1; //对应从机的SI
else SPIdo = 0;
SPIclk =0;
// delay();
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
SPIclk =1;
// delay();
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
data<<=1;
}
// SPIholdclk="1";
// Myspidata=data;
// Myspidata=data;
}//
// uchar temp,Receive;
// SPIholdclk=1;
// 龙一啸
char GetSPIByte(void) //finish//
{
unsigned char ctrl_i=0,Ddata=0;
// 下降沿读取一个位;
for(ctrl_i=0;ctrl_i<8;ctrl_i++)
{
SPIclk="1";// SpiDelay(1);
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
// SpiDelay(1);
SPIclk="0";
Ddata="Ddata"<<1;
Ddata |= SPIdin; //对应从机的SO //SO; //Mi
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
asm("nop"); // NOP;
SPIclk="1"; // SpiDelay(1);
}
// Myspidata="Ddata";
// Myspidata="data";
return(Ddata);
}//
/* */
////////////////////////////////////////////////////////////
//格式化主存储器(以扇区<0A,0B,1……15>为单位删除所有页数据)
void DF_format(void)
{
unsigned char i;
DF_SPI_ON;
DF_wait_busy();
DF_SELECT_1;
write_SPI(SECTOR_ERASE);
write_SPI(0x00);
write_SPI(0x00);
write_SPI(0x00);
DF_DESELECT_1;
DF_wait_busy();
DF_SELECT_1;
write_SPI(SECTOR_ERASE);
write_SPI(0x00);
write_SPI(0x20);
write_SPI(0x00);
DF_DESELECT_1;
for (i=1;i<16;i++)
{
DF_wait_busy();
DF_SELECT_1;
write_SPI(SECTOR_ERASE);
write_SPI(i << 2);
write_SPI(0x00);
write_SPI(0x00);
DF_DESELECT_1;
}
DF_SPI_OFF;
}//
//检测并等待器件忙状态,8引脚封闭器件没有 RDY/BUSY引脚 为些通过读状态寄存器来检测忙状态
//读取状态寄存器
//bit7 bit6 bit6 bit6 bit6 bit6 bit6 bit6
//RDY/BUSY COMP 1 0 1 1 PROTECT PAGE SIZE
unsigned char
DF_read_reg(void)
{
unsigned char temp;
DF_SPI_ON;
DF_SELECT_1;
write_SPI(READ_STATE_REGISTER);
write_SPI(0x00);
write_SPI(0x00);
write_SPI(0x00);
write_SPI(0x00);
temp="GetSPIByte"();
// temp=SPDR;
DF_DESELECT_1;
DF_SPI_OFF;
return temp;
}//
//检查状态寄存器最高位是否为忙,并等待空闲
void DF_wait_busy(void)
{
unsigned char state_reg=0x00;
DF_SELECT_1;
write_SPI(READ_STATE_REGISTER);
write_SPI(0x00);
write_SPI(0x00);
write_SPI(0x00);
while((state_reg&0x80) == 0)
{
// write_SPI(0x00);
// state_reg = SPDR;
state_reg = GetSPIByte();
}
DF_DESELECT_1;
}//
//擦除指定的主存储器页(地址范围0-4095)
void DF_page_earse( unsigned int page )
{
DF_SPI_ON;
DF_wait_busy();
DF_SELECT_1;
write_SPI(PAGE_ERASE);
write_SPI((unsigned char)(page >> 6));
write_SPI((unsigned char)(page << 2));
write_SPI(0x00);
DF_DESELECT_1;
DF_SPI_OFF;
}//
// 将保存在数组DF_buffer[]中的一页数据写入第一或者第二缓冲区后送入主存储区
//(先擦除后写入模式,页地址范围0-4095)
void DF_write_page(unsigned char buffer, unsigned int page ) // Num
{
unsigned int i;
DF_SPI_ON;
DF_wait_busy();
DF_SELECT_1;
if(buffer == 1)
write_SPI(BUFFER_1_WRITE);
else
write_SPI(BUFFER_2_WRITE);
write_SPI(0x00);
write_SPI(0x00);
write_SPI(0x00);
for (i=0;i< Num;i++)
{
// write_SPI(DF_buffer);
write_SPI(Flash_datatemp);
}//
DF_DESELECT_1;
if (page<4096)
{
DF_SELECT_1;
if(buffer == 1)
write_SPI(B1_TO_MM_PAGE_PROG_WITH_ERASE);
else
write_SPI(B2_TO_MM_PAGE_PROG_WITH_ERASE);
write_SPI((unsigned char)(page>>6));
write_SPI((unsigned char)(page<<2));
write_SPI(0x00);
DF_DESELECT_1;
DF_wait_busy();
}
DF_SPI_OFF;
}//
//将指定主存储器页的数据转入第一缓冲区后读出,保存在DF_buffer[]数组中
//(页地址范围0-4095)
void DF_read_page(unsigned char buffer, unsigned int page)
{
unsigned int i;
DF_SPI_ON; //中断读取??????
// while(!(DF_STA_PORT & (1<< DF_STATE)));//DF_STA_PORT--PINC, DF_STATE---PC2
DF_SELECT_1;
if(buffer == 1)
write_SPI(MM_PAGE_TO_B1_XFER);
else
write_SPI(MM_PAGE_TO_B2_XFER);
write_SPI((unsigned char)(page >> 6));
write_SPI((unsigned char)(page << 2));
write_SPI(0x00);
// write_SPI(0x00);//Four Bytes don't care Bytes
// write_SPI(0x00);
// write_SPI(0x00);
// write_SPI(0x00);
DF_DESELECT_1; // DF_DESELECT_1;
DF_wait_busy();
DF_SELECT_1;
if(buffer == 1)
write_SPI(BUFFER_1_READ);
else
write_SPI(BUFFER_2_READ);
write_SPI(0x00);
write_SPI(0x00);
write_SPI(0x00);
write_SPI(0x00);
for (i=0;i< Num;i++) //提前结束,页面的读写;
{
// DF_buffer=GetSPIByte();
Flash_datatemp=GetSPIByte();
}
DF_DESELECT_1;
DF_SPI_OFF;
}//
// write_SPI(0xFF);
// DF_buffer = SPDR;
//以直接读取方式读取指定的主存储器页数据(页地址范围0-4095)
void DF_MM_read_page(unsigned int page )
{
unsigned int i;
DF_SPI_ON;
// while(!(DF_STA_PORT & (1<< DF_STATE)));
DF_SELECT_1;
write_SPI(MAIN_MEMORY_PAGE_READ); //
write_SPI((unsigned char)(page >> 6));
write_SPI((unsigned char)(page << 2));
write_SPI(0x00);
write_SPI(0x00);
write_SPI(0x00);
write_SPI(0x00);
write_SPI(0x00);
for (i=0;i< Num;i++)
{
// write_SPI(0x00);
// DF_buffer = SPDR;
// DF_buffer=GetSPIByte();
Flash_datatemp=GetSPIByte();
}
DF_DESELECT_1;
DF_SPI_OFF;
}//
//将指定主存储器页的数据转入指定缓冲区
void DF_mm_to_buf( unsigned char buffer,unsigned int page)
{
DF_SPI_ON;
DF_wait_busy();
DF_SELECT_1;
if (buffer==1)
write_SPI(MM_PAGE_TO_B1_XFER);
else
write_SPI(MM_PAGE_TO_B2_XFER);
write_SPI((unsigned char)(page >> 6));
write_SPI((unsigned char)(page << 2));
write_SPI(0x00);
DF_DESELECT_1;
DF_SPI_OFF;
}//
//********************************************************************************************************
// 启用缓存2读
//从缓冲区2的指定位置(0-263)中读入指定字节
//********************************************************************************************************
/*
void FlashBuffer2Read(unsigned int star_addr,unsigned int len, unsigned char *buffer)
{
unsigned int i;
DF_RDY_BUSY;//测芯片准备好?
DF_CHIP_SELECT;//芯片选择
SendSPIByte(0x56); //缓冲区2为56H
SendSPIByte(0);
SendSPIByte((unsigned char)(star_addr>>8));
SendSPIByte((unsigned char)star_addr);
SendSPIByte(0);
for (i=0;i<len;i++)
{
*buffer = GetSPIByte(); // read data from SPI
buffer++;
}
DF_CHIP_NOSELECT;
}
*/
//******************************************************************************************************
//启用缓存1写
//向缓冲区1的指定位置(0-263)写入指定字节
//******************************************************************************************************
/*
void FlashBuffer1Write(unsigned int start_addr, unsigned int len,unsigned char *buffer)
{
unsigned int i;
DF_RDY_BUSY; //测芯片准备好?
DF_CHIP_SELECT; //芯片选择
SendSPIByte(0x84); //缓冲区1为84H
SendSPIByte(0x00);
SendSPIByte((unsigned char)(start_addr>>8));
SendSPIByte((unsigned char)start_addr);
for (i=0;i<len;i++)
{
SendSPIByte(*buffer);
buffer++;
}
DF_CHIP_NOSELECT;
}
*/
//指定的页, 起始ADDR, 长度;
// DF_read_buf(unsigned char buffer,unsigned int start_address,unsigned int length)
// DF_write_buf(unsigned char buffer,unsigned int start_address,unsigned int length)
// 读取指定缓冲区指定单元的数据,保存在DF_buffer[]数组中
unsigned char
DF_read_buf( unsigned char *datatemp ,unsigned char buffer,unsigned int start_address,unsigned int length )
{
unsigned int i="0";
if ((527-start_address)>=length)
{
DF_SPI_ON;
DF_wait_busy();
DF_SELECT_1;
if (buffer==1)
{
write_SPI(BUFFER_1_READ);
}
else //buffer==2
{
write_SPI(BUFFER_2_READ);
}
write_SPI(0x00);
write_SPI((unsigned char) (start_address >> 8));
write_SPI ((unsigned char) start_address);
write_SPI(0x00);
for (i=0;i<length;i++)
{
// write_SPI(0xFF);
// DF_buffer = SPDR;
// DF_buffer= GetSPIByte(); //???
// Flash_datatemp=GetSPIByte();
*(datatemp+i)=GetSPIByte();
}
DF_DESELECT_1;
DF_SPI_OFF;
return 1;
}
else
return 0;
}//
// 将DF_buffer[]数组中指定长度的数据写入指定缓冲区 //PIC中,对数据组操作要指出,是常数还是变数据
unsigned char DF_write_buf ( unsigned char *datatemp ,unsigned char buffer,unsigned int start_address,unsigned int length)
{
unsigned int i="0";
if ((527-start_address)>=length) //addr <<527
{
DF_SPI_ON;
DF_wait_busy();
DF_SELECT_1;
if (buffer==1)
write_SPI(BUFFER_1_WRITE);
else{
write_SPI(BUFFER_2_WRITE);
}
write_SPI(0x00);
write_SPI((unsigned char)(start_address >> 8));
write_SPI((unsigned char)start_address);
for (i=0;i<length;i++)
{
// write_SPI(DF_buffer);
// write_SPI(Flash_datatemp); //换成指针的数据组;
write_SPI( *(datatemp+i));
}
DF_DESELECT_1;
return 1;
}
else return 0; //失败的提示;
}//
// 将DF_buffer[]数组中指定长度的数据写入指定缓冲区 //PIC中,对数据组操作要指出,是常数还是变数据
// 专用 写出字模数据的数组, 指针定义在常数空间;
// 结构数组的引用规则:(注意字模的数据空间,RAM和CONST ) &ASC_MSK812[kk]<==> &ASC_MSK812[kk].Asc[0]
// === ppziku=&ASC_MSK812[kk].Asc[0];
unsigned char DF_writeconst_zimobuf ( const unsigned char *Zimo_datatemp ,unsigned char buffer,unsigned int start_address,unsigned int length)
{
unsigned int i="0";
if ((527-start_address)>=length) //addr <<527
{
DF_SPI_ON;
DF_wait_busy();
DF_SELECT_1;
if (buffer==1)
write_SPI(BUFFER_1_WRITE);
else{
write_SPI(BUFFER_2_WRITE);
}
write_SPI(0x00);
write_SPI((unsigned char)(start_address >> 8));
write_SPI((unsigned char)start_address);
for (i=0;i<length;i++)
{
// write_SPI(DF_buffer);
// write_SPI(Flash_datatemp); //换成指针的数据组;
write_SPI( *(Zimo_datatemp+i));
}
DF_DESELECT_1;
return 1;
}
else return 0; //失败的提示;
}//
//将指定缓冲区中的数据写入主存储区的指定页
void DF_buf_to_mm ( unsigned char buffer,unsigned int page )
{
DF_SPI_ON;
DF_wait_busy();
if (page<4096)
{
DF_SELECT_1;
if (buffer==1)
write_SPI(B1_TO_MM_PAGE_PROG_WITH_ERASE);
else
write_SPI(B2_TO_MM_PAGE_PROG_WITH_ERASE);
write_SPI((unsigned char)(page>>6));
write_SPI((unsigned char)(page<<2));
write_SPI(0x00);
DF_DESELECT_1;
}
DF_SPI_OFF;
} //
//================================================================//
/*功能说明: SPI总线通用写操作子程序 */
/*函数名: Senddata() */
/*入口参数: Ddata--写数据 */
/* Number--写位数目 */
/*中间参数: */
/*出口参数: */
/*子程序编号: */
/*
撰写人: 龙一啸 撰写时间:2003-12 15:45
void Senddata(unsigned char Ddata)
{
unsigned char ctrl_i;
for(ctrl_i=0;ctrl_i<8;ctrl_i++)
{
SI=(bit)(Ddata&0x80); //这种发送方式适合C 51 , 但是对于ARM应该变化一下;
Ddata=Ddata<<1;
// SpiDelay(1);
SCK=1;
// SpiDelay(2);
SCK=0;
// SpiDelay(1);
// 平时是低电平的; SCK=0;
}
}
*/
//================================================================//
/*功能说明: SPI总线通用读操作子程序 */
/*函数名: Readdata() */
/*入口参数: Ddata--写数据 */
/*中间参数: */
/*出口参数: */
/*子程序编号: */
/*撰写人: 撰写时间:2003-12 15:45
//================================================================//
unsigned char Readdata()
{
unsigned char ctrl_i,Ddata;
for(ctrl_i=0;ctrl_i<8;ctrl_i++)
{
SCK=1;
// SpiDelay(1);
Ddata=Ddata<<1;
Ddata|=SO;
// SpiDelay(1);
SCK=0;
// SpiDelay(1);
}
return(Ddata);
}
文章评论(0条评论)
登录后参与讨论