分享到:
#include "msp430x14x.h"
#define SET_FE_CS_DIR P3DIR|=BIT0
#define SET_FE_CLK_DIR P3DIR|=BIT3
#define SET_FE_IN_DIR P3DIR|=BIT2
#define SET_FE_OUT_DIR P3DIR|=BIT1
#define CLR_FE_CS_DIR P3DIR&=~BIT0
#define CLR_FE_CLK_DIR P3DIR&=~BIT3
#define CLR_FE_IN_DIR P3DIR&=~BIT2
#define CLR_FE_OUT_DIR P3DIR&=~BIT1
#define SET_FE_CS P3OUT|=BIT0
#define SET_FE_CLK P3OUT|=BIT3
#define SET_FE_IN P3OUT|=BIT2
#define SET_FE_OUT P3OUT|=BIT1
#define CLR_FE_CS P3OUT&=~BIT0
#define CLR_FE_CLK P3OUT&=~BIT3
#define CLR_FE_IN P3OUT&=~BIT2
#define CLR_FE_OUT P3OUT&=~BIT1
#define FE_WREN 0X06
#define FE_WRDI 0X04
#define FE_WRSR 0X01
#define FE_RDSR 0X05
#define FE_READ 0X03
#define FE_WRITE 0X02
#define READ_FE_IN ((P3IN>>2)&0X01)
void FE_SET(void);
void FE_START(void);
void FE_END(void);
void FE_WREN1(void);
void FE_WRDI1(void);
void FE_OUT(unsigned char wData);
void FE_Writebyte1(unsigned int adr,unsigned char wByte);
void FE_WriteBlock(unsigned int adr,unsigned char *WriteData,unsigned int count);
void FE_ReadBlock(unsigned int adr,unsigned char *ReadData,unsigned int count);
unsigned char FE_IN(void);
unsigned char FE_Readbyte1(unsigned int adr,unsigned char rByte);
void FE_SET(void)
{
SET_FE_CS_DIR;
SET_FE_CLK_DIR;
CLR_FE_IN_DIR;
SET_FE_OUT_DIR;
}
void FE_START(void)
{
SET_FE_CS;
CLR_FE_CLK;
CLR_FE_CS;
}
void FE_END(void)
{
CLR_FE_CLK;
SET_FE_CS;
}
void FE_WREN1(void)
{
FE_START();
FE_OUT(FE_WREN);
FE_END();
}
void FE_WRDI1(void)
{
FE_START();
FE_OUT(FE_WRDI);
FE_END();
}
unsigned char FE_IN(void)
{
unsigned char i;
unsigned char TempBit = 0;
unsigned char TempData = 0;
CLR_FE_IN_DIR;
for(i=0;i<8;i++)
{
SET_FE_CLK;
if (READ_FE_IN == 0x01 /*sda==1*/)
{
TempBit = 1;
}
else
{
TempBit = 0;
}
TempData = (TempData << 1) | TempBit;
CLR_FE_CLK;
_NOP();
_NOP();
}
return(TempData);
}
void FE_OUT(unsigned char WriteData)
{
unsigned char i;
SET_FE_OUT_DIR;
for(i=0;i<8;i++)
{
// SET_FE_CLK;
if (((WriteData >> 7) & 0x01) == 0x01)
{
SET_FE_OUT;
SET_FE_CLK;
CLR_FE_CLK;
_NOP();
_NOP();
}
else
{
CLR_FE_OUT;
SET_FE_CLK;
CLR_FE_CLK;
_NOP();
_NOP();
}
WriteData = WriteData << 1;
}
}
/*
void FE_Protect(void)
{
FE_WREN();
FE_START();
FE_OUT(FE_WRSR);
FE_OUT(0X01);
FE_END();
}
void FE_UNProtect(void)
{
FE_WREN();
FE_Start();
FE_OUT(FE_WRSR);
FE_OUT(0X02);
FE_END();
}
*/
void FE_Writebyte1(unsigned int adr,unsigned char wByte)
{
unsigned char temp;
//FE_UNProtect();
FE_WREN1();
FE_START();
FE_OUT(FE_WRITE);
temp=(unsigned char)(adr>>8);
FE_OUT(temp);
FE_OUT((unsigned char)(adr));
FE_OUT(wByte);
FE_END();
//FE_Protect();
}
unsigned char FE_Readbyte1(unsigned int adr,unsigned char rByte)
{
unsigned char temp;
FE_WREN1();
FE_START();
FE_OUT(FE_READ);
temp=(unsigned char)(adr>>8);
FE_OUT(temp);
FE_OUT((unsigned char)(adr));
rByte=FE_IN();
FE_END();
return rByte;
}
void FE_WriteBlock(unsigned int adr,unsigned char *WriteData,unsigned int count)
{
unsigned int i;
//FE_UNProtect();
FE_WREN1();
FE_START();
FE_OUT(FE_WRITE);
temp=(unsigned char)(adr>>8);
FE_OUT(temp);
FE_OUT((unsigned char)(adr));
for(i=0;i<count;i++)
{
FE_OUT(WriteData[i]);
}
FE_END();
//FE_Protect();
}
void FE_ReadBlock(unsigned int adr,unsigned char *ReadData,unsigned int count)
{
unsigned int i;
FE_WREN1();
FE_START();
FE_OUT(FE_READ);
temp=(unsigned char)(adr>>8);
FE_OUT(temp);
FE_OUT((unsigned char)(adr));
for(i=0;i<count;i++)
{
ReadData[i]=FE_IN();
}
FE_END();
}
void main(void)
{
unsigned char t,i;
unsigned int tt;
float b=0.0;
WDTCTL=WDTPW+WDTHOLD;
//select clk
BCSCTL1=0;
BCSCTL2=0X88;//SELM.1+SELS
do
{
IFG1&=~OFIFG;
for(i=0xff;i>0;i++);
}
while((IFG1&OFIFG)!=0);
//_EINT();
P2DIR|=BIT7;
P2OUT|=BIT7;
FE_SET();
tt=0x3FFF;
t=0x80;
FE_Writebyte1(tt,t);
b=FE_Readbyte1(0x3FFF,t);
// tt=t;
while(1)
{
;
}
}
(0 )
(0 )
回复
举报
-
- 0000000000000000
-
1888 发帖7917 回复34980 积分
- 私信他 +关注
发表回复
版
块
导
航
块
导
航
举报
请选择举报类别
- 广告垃圾
- 违规内容
- 恶意灌水
- 重复发帖

发帖
回复
楼主