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

📄 25lc320.c

📁 nrf9e5 nordic公司出品的带有无线发送接收的单片机的bootloader程序。支持xmodem下载
💻 C
字号:
#include "reg9e5.h"
#include "PubFunc.h"
#include "spi.h"
#include "25lc320.h"
#include "serial.h"
#include <absacc.h>
//BYTE data cmdBufRW[35];
BYTE data cmdBufRW[67];
BYTE _25LC320_ReadStatus(void)
{
	BYTE data buf[2];
	
//	ChoiceSPIModule(EXTERNAL);    //当调用这个函数时候,此句肯定被调用过
	
	buf[0] = _25LC320_RDSR;
	SPIReadWrite(buf, 2);
	return buf[1];
}

void _25LC320_SetWEL(BYTE data in)
{
	BYTE data buf[1];
	
	ChoiceSPIModule(EXTERNAL);		
	
	buf[0] = (in) ? _25LC320_WREN : _25LC320_WRDI;
	Wait_25LC320_IDLE;
	SPIReadWrite(buf, 1);
//	WaitSPIDataReady();
}


void _25LC320_WriteStatus(BYTE data in)
{
	BYTE data buf[2];
	
	_25LC320_SetWEL(1);
	
//	ChoiceSPIModule(EXTERNAL);
	buf[0] = _25LC320_WRSR;
	buf[1] = in;
	Wait_25LC320_IDLE;
	SPIReadWrite(buf, 2);
}

void Init25lc320(void)
{
	_25LC320_WriteStatus(0x00);
}

void _25LC320_WriteByteInPage(WORD data addr, BYTE idata *buf)
{
	BYTE data i;
	_25LC320_SetWEL(1);
	
//	ChoiceSPIModule(EXTERNAL);
	cmdBufRW[0] = _25LC320_WRITE;
	cmdBufRW[1] = addr >> 8;
	cmdBufRW[2] = addr & 0xFF;
	
	for (i = 0; i < _25LC320_PAGE_SIZE; i++) {
		cmdBufRW[i+3] = buf[i];
	}
	Wait_25LC320_IDLE;
	SPIReadWrite(cmdBufRW, _25LC320_PAGE_SIZE+3);
/*
	ActionSPI_CS(0);
	SPI_DATA = _25LC320_WRITE;				// Move byte to send to SPI data register
	while((EXIF & 0x20) == 0x00); 
	EXIF &= ~0x20;
	SPI_DATA = addr >> 8;				// Move byte to send to SPI data register
	while((EXIF & 0x20) == 0x00); 
	EXIF &= ~0x20;
	SPI_DATA = addr & 0xFF;				// Move byte to send to SPI data register
	while((EXIF & 0x20) == 0x00); 
	EXIF &= ~0x20;
	
	i=0;
		
	do{	//for(i=0;i<size;i++)
	//{
	SPI_DATA = buf[i];				// Move byte to send to SPI data register
	while((EXIF & 0x20) == 0x00);    // Wait until SPI hs finished transmitting 
	EXIF &= ~0x20;                  // Clear SPI interrupt
	i++;
	}while(i<32);
  ActionSPI_CS(1);
  */
}

⌨️ 快捷键说明

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