#include <reg51.h>
#include <intrins.h>
#include <config.h>
extern bit x5045useflag;
void x5045_write_onebyte(unsigned char onedata){//只做时钟,不判断其他,在调用程序中加读写条件
unsigned char i;
for(i=0;i <8;i++){ //上升沿写入SI
x5045_si=(bit)(onedata&0x80);
x5045_sck=0;
onedata < <=1;
x5045_sck=1; //SCK=1;
}
}
unsigned char x5045_read_onebyte(void){//只做时钟,不判断其他,在调用程序中加读写条件
unsigned char i,onedata;
for(i=0;i <8;i++){ //下降沿读入So
x5045_sck=1;
x5045_sck=0; //sck=0;
onedata|=x5045_si;
onedata < <=1;
}
return(onedata);
}
unsigned char x5045_read_status(void){
unsigned char temp;
//*****************************
x5045_so=1;
x5045_si=1;
//*****************************/
x5045_cs=0;
x5045useflag=1;
x5045_write_onebyte(RSDR);
temp=x5045_read_onebyte();
x5045_cs=1;
x5045useflag=0;
return(temp);
}
void x5045_write_status(unsigned char vdata){
x5045_cs=0;
x5045useflag=1;
x5045_write_onebyte(WREN);
x5045_cs=1;
x5045_cs=0;
x5045_write_onebyte(WRSR);
x5045_write_onebyte(vdata);
x5045_cs=1;
x5045useflag=0;
}
void x5045_write_data(unsigned int adders,unsigned char data_buff){ //len <16,每页为16BYTE字节
x5045useflag=1;
x5045_cs=0;
x5045_write_onebyte(WREN);//写完后,CS需被拉高,write enble SCK=1
x5045_cs=1;
//temp=(adders> 255)?WRITE_ADDERS_H:WRITE_ADDERS_L; //写入高地址
x5045_cs=0;
x5045_write_onebyte((adders> 255)?WRITE_ADDERS_H:WRITE_ADDERS_L); //写入write 指令地址
//temp=(unsigned char)adders; //写入真实地址
x5045_write_onebyte((unsigned char)adders);
//temp=data_buff;//写入数据
x5045_write_onebyte(data_buff);
x5045_cs=1; //写入完成 SCK=1
x5045useflag=0;
if(x5045_read_status()&0x01){x5045_cs=0;
_nop_();
x5045_cs=1;}; //检查WIP状态,喂狗,=0时,写入完成
}
unsigned char x5045_read_data(unsigned int adders){//返还指定地址的数据
unsigned char temp;
x5045useflag=1;
x5045_so=1;
x5045_cs=0;
//temp=(adders> 255)?READ_ADDERS_H:READ_ADDERS_L;//高地址读
x5045_write_onebyte((adders> 255)?READ_ADDERS_H:READ_ADDERS_L); //写入读地址指令
x5045_write_onebyte((unsigned char )adders); //sck=1
temp=x5045_read_onebyte();
x5045_cs=1;
x5045useflag=0;
return(temp);
}
调用读寄存器的状态是FE,分别写入指定地址0x55,0xaa,读出来是00,fe。郁闷,一直调试不出来,请大侠们帮帮看看。 |