93c46读写程序

[09-12 17:55:46]   来源:http://www.88dzw.com  单片机学习   阅读:8947

文章摘要:#include <reg52.h>sbit CS=P2^7;sbit SK=P2^6;sbit DI=P2^5;sbit DO=P2^4;/*extern unsigned char ReadChar(unsigned char address);extern void WriteChar(unsigned char address,unsigned char InData);extern void ReadString(unsigned char data *RamAddress,unsigned char RomAddress,unsigned char Number);ex

93c46读写程序,标签:单片机开发,单片机原理,单片机教程,http://www.88dzw.com
#include <reg52.h>
sbit CS=P2^7;
sbit SK=P2^6;
sbit DI=P2^5;
sbit DO=P2^4;

/*
extern unsigned char ReadChar(unsigned char address);
extern void WriteChar(unsigned char address,unsigned char InData);
extern void ReadString(unsigned char data *RamAddress,unsigned char RomAddress,
unsigned char Number);
extern void Writestring(unsigned char data *RamAddress,unsigned char RomAddress,
unsigned char Number);
*/

// Write enable must precede all programming modes.
void Ewen(void) {
unsigned char temp,InData;
CS=0;
SK=0;
CS=1;
InData=0x98; // 10011XXXX
for(temp=9;temp!=0;temp--) { // 9
DI=InData&0x80;
SK=1; SK=0;
InData<<=1;
}
CS=0;
}

// Disables all programming instructions.
void Ewds(void) {
unsigned char temp,InData;
CS=0;
SK=0;
CS=1;
InData=0x80; // 10000XXXX
for(temp=9;temp!=0;temp--) { // 9
DI=InData&0x80;
SK=1; SK=0;
InData<<=1;
}
CS=0;
}

// Reads data stored in memory, at specified address.
unsigned int Read(unsigned char address) {
unsigned char temp;
unsigned int result;
Ewen();
SK=0; DI=1; // 110 A5-A0
CS=0; CS=1;
SK=1; SK=0; // 1
address=address&0x3f|0x80;
for(temp=8;temp!=0;temp--) { // 8
DI=address&0x80;
SK=1; SK=0;
address<<=1;
}
DO=1;
for(temp=16;temp!=0;temp--) { // 16
SK=1;
result=(result<<1)|DO;
SK=0;
}
CS=0;
Ewds();
return(result);
}

// Writes memory location An - A0.
void Write(unsigned char address,unsigned int InData) {
unsigned char temp;
Ewen();
SK=0; DI=1; // 101 A5-A0
CS=0; CS=1;
SK=1; SK=0; // 1
address=address&0x3f|0x40;
for(temp=8;temp!=0;temp--) { // 8
DI=address&0x80;
SK=1; SK=0;
address<<=1;
}
for(temp=16;temp!=0;temp--) { // 16
DI=InData&0x8000;
SK=1; SK=0;
InData<<=1;
}
CS=0; DO=1;
CS=1; SK=1;
while(DO==0) { // busy test
SK=0; SK=1;
}
SK=0; CS=0;
Ewds();
}

/*
// Erase memory location An - A0.
void Erase(unsigned char address) {
unsigned char temp;
Ewen();
SK=0; DI=1; // 111 A5-A0
CS=0; CS=1;
SK=1; SK=0; // 1
address|=0xc0;
for(temp=8;temp!=0;temp--) { // 8
DI=address&0x80;
SK=1; SK=0;
address<<=1;
}
CS=0; DO=1;
CS=1; SK=1;
while(DO==0) {
SK=0; SK=1;
}
SK=0; CS=0;
Ewds();
}

// Erases all memory locations. Valid only at VCC = 4.5V to 5.5V.
void Eral(void) {
unsigned char temp,InData;
Ewen();
CS=0;
SK=0;
CS=1;
InData=0x90; // 10010XXXX
for(temp=9;temp!=0;temp--) { // 9
DI=InData&0x80;
SK=1; SK=0;
InData<<=1;
}
CS=0; DO=1;
CS=1; SK=1;
while(DO==0) {
SK=0; SK=1;
}
SK=0; CS=0;
Ewds();
}

// Writes all memory locations. Valid only at VCC = 4.5V to 5.5V.
void Wral(unsigned int InData) {
unsigned char temp,address;
Ewen();
CS=0;
SK=0;
CS=1;
address=0x88; // 10001XXXX
for(temp=9;temp!=0;temp--) { // 9
DI=address&0x80;
SK=1; SK=0;
address<<=1;
}
for(temp=16;temp!=0;temp--) { // 16
DI=InData&0x8000;
SK=1; SK=0;
InData<<=1;
}
CS=0; DO=1;
CS=1; SK=1;
while(DO==0) {
SK=0; SK=1;
}
SK=0; CS=0;
Ewds();
}

*/

unsigned char ReadChar(unsigned char address) {

[1] [2]  下一页


Tag:单片机学习单片机开发,单片机原理,单片机教程单片机学习

《93c46读写程序》相关文章

分类导航
最新更新
热门排行