|
头文件 SPI.H
#ifndef SPI_H
#define SPI_H
#define WREN 0x06
#define READ 0x03
#define WRITE 0x02
#define RDID 0x9F
#define SNR 0xC3
void WriteSPI(uchar dat);
uchar ReadSPI(void);
uchar Read_Byte(ulong add);
void Write_Byte(ulong add,uchar dat);
void Write_String(ulong add,uchar *pStr,uint len);
void Read_String(ulong add,uchar *pStr,uint len);
#endif
//SPI.C程序
#include "C8051F120.h"
#include "main.h"
#include "spi.h"
void WriteSPI(uchar dat)
{
uchar SFR_PAGE_SAVE = SFRPAGE;
SFRPAGE = SPI0_PAGE;
SPIF = 0;
SPI0DAT = dat;
while(!SPIF);
SPIF = 0;
SFRPAGE = SFR_PAGE_SAVE;
}
更多源码见:http://www.52embed.com/viewthread.php?tid=95 |
|