C51写的93C46的读写程序

来源:本站
导读:目前正在解读《C51写的93C46的读写程序》的相关信息,《C51写的93C46的读写程序》是由用户自行发布的知识型内容!下面请观看由(电工技术网 - www.9ddd.net)用户发布《C51写的93C46的读写程序》的详细说明。
简介:本文主要介绍了c51写的93C46的读写程序

#include<reg52.h>

sbitCS=P2^7;

sbitSK=P2^6;

sbitDI=P2^5;

sbitDO=P2^4;

/*

externunsignedcharReadChar(unsignedcharaddress);

externvoidWriteChar(unsignedcharaddress,unsignedcharInData);

externvoidReadString(unsignedchardata*RamAddress,unsignedcharRomAddress,unsignedcharNumber);

externvoidWriteString(unsignedchardata*RamAddress,unsignedcharRomAddress,unsignedcharNumber);

*/

//Writeenablemustprecedeallprogrammingmodes.

voidEwen(void){

unsignedchartemp,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;

}

//Disablesallprogramminginstructions.

voidEwds(void){

unsignedchartemp,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;

}

//Readsdatastoredinmemory,atspecifiedaddress.

unsignedintRead(unsignedcharaddress){

unsignedchartemp;

unsignedintresult;

Ewen();

SK=0;DI=1;//110A5-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);

}

//WritesmemorylocationAn-A0.

voidWrite(unsignedcharaddress,unsignedintInData){

unsignedchartemp;

Ewen();

SK=0;DI=1;//101A5-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){//busytest

SK=0;SK=1;

}

SK=0;CS=0;

Ewds();

}

/*

//ErasememorylocationAn-A0.

voidErase(unsignedcharaddress){

unsignedchartemp;

Ewen();

SK=0;DI=1;//111A5-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();

}

//Erasesallmemorylocations.ValidonlyatVCC=4.5Vto5.5V.

voidEral(void){

unsignedchartemp,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();

}

//Writesallmemorylocations.ValidonlyatVCC=4.5Vto5.5V.

voidWral(unsignedintInData){

unsignedchartemp,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();

}

*/

unsignedcharReadChar(unsignedcharaddress){

unsignedchartemp=address>>1;

if(address&0x01)return((unsignedchar)(Read(temp)>>8));

elsereturn((unsignedchar)(Read(temp)));

}

voidWriteChar(unsignedcharaddress,unsignedcharInData){

unsignedchartemp=address>>1;

if(address&0x01)Write(temp,(unsignedint)(Read(temp)&0x00ff|(InData<<8)));

elseWrite(temp,(unsignedint)(Read(temp)&0xff00|InData));

}

voidReadString(unsignedchardata*RamAddress,unsignedcharRomAddress,unsignedcharNumber){

while(Number!=0){

*RamAddress=ReadChar(RomAddress);

RamAddress++;

RomAddress++;

Number--;

}

}

voidWriteString(unsignedchardata*RamAddress,unsignedcharRomAddress,unsignedcharNumber){

unsignedinttemp;

if(Number==0)return;

if(RomAddress&0x01){

WriteChar(RomAddress,*RamAddress);

RamAddress++;

RomAddress++;

Number--;

}

if(Number==0)return;

while(Number>>1){

temp=*RamAddress;

RamAddress++;

temp=temp|(*RamAddress)<<8;

RamAddress++;

Write(RomAddress>>1,temp);

RomAddress++;

RomAddress++;

Number--;

Number--;

}

if(Number)WriteChar(RomAddress,*RamAddress);

}

提醒:《C51写的93C46的读写程序》最后刷新时间 2024-03-14 01:02:52,本站为公益型个人网站,仅供个人学习和记录信息,不进行任何商业性质的盈利。如果内容、图片资源失效或内容涉及侵权,请反馈至,我们会及时处理。本站只保证内容的可读性,无法保证真实性,《C51写的93C46的读写程序》该内容的真实性请自行鉴别。