?? 16.c
字號:
// X25043/45 應(yīng)用
write_status(status) // 寫狀態(tài),一般寫0
clr_wchdog(void) //清看門狗
unsigned char read_byte(address) //讀一個字節(jié)
void write_byte(address,Data) //寫一個字節(jié)
#define ALONE_COMPILE
#ifdef ALONE_COMPILE
#include "INTRINS.H"
#endif
#ifndef nop2()
#define nop2() _nop_();_nop_();_nop_()
#endif
#define WREN 0x06
#define WRDI 0x04
#define RDSR 0x05
#define WRSR 0x01
#define READ 0x03
#define WRITE 0x02
//#define PORT P1
sfr PORT=0x90; //25045的4根io腳接在同一端口,本例為p1
//請根據(jù)實際電路更改引腳定義
#define _SI 0x80 //si接在p1.3,0x80=00001000b
#define _SCK 0x40 //sck接在p1.2,0x80=00000100b
#define _SO 0x20 //so接在p1.1
#define _CS 0x10 //cs接在p1.0
#ifndef dword
#define dword unsigned long
#define word unsigned int
#define byte unsigned char
typedef union
{
word w;
byte bh;
byte bl;
}
WordType;
typedef union
{
dword dw;
word w[2];
byte b[4];
}
DwordType;
#endif
void _w_byte(Data)
char Data;
{
char i;
PORT &= (_SCK^0xff);
for(i=0;i<<255 ? (0x08|READ): READ));
_w_byte((char)(address & 0x00ff));
result=_r_byte();
nop2();nop2();/////////////
PORT |=_CS;
// Chip unselect
return(result);
}
void write_byte(address,Data)
unsigned int address;
char Data;
{
write_status(WREN);
nop2();nop2();/////////////
PORT &= (_CS^0xff);
nop2();nop2();/////////////
_w_byte((unsigned char)(address>255 ? (0x08|WRITE): WRITE));
_w_byte((unsigned char)(address & 0x00ff));
_w_byte(Data);
nop2();nop2();/////////////
PORT |=_CS;
wait_free();
return;
}
unsigned long read_data(format,address)
unsigned char format;
unsigned int address;
{
DwordType result;
switch(format&0xdf)
{
case'L':
result.b[0]=read_byte(address);
result.b[1]=read_byte(address+1);
result.b[2]=read_byte(address+2);
result.b[3]=read_byte(address+3);
break;
case'D':
result.b[2]=read_byte(address);
result.b[3]=read_byte(address+1);
break;
case'C':
result.b[3]=read_byte(address);
break;
}
return(result.dw);
}
void write_data(format,address,Data)
unsigned char format;
unsigned int address;
DwordType data* Data;
{
switch(format&0xdf)
{
case'L':
write_byte(address , Data->b[0]);
write_byte(address+1, Data->b[1]);
write_byte(address+2, Data->b[2]);
write_byte(address+3, Data->b[3]);
break;
case'D':
write_byte(address , Data->b[2]);
write_byte(address+1, Data->b[3]);
break;
case'C':
write_byte(address , Data->b[3]);
break;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -