首 页文章中心下载中心图文中心访客留言安防论坛产品推荐繁體中文
设为首页
加入收藏
联系我们
您当前的位置:金辉安防同盟 -> 文章中心 -> 一卡通 -> 文章内容 退出登录 用户管理
栏目导航
· 弱电基础 · 视频监控
· 电子防盗 · 楼宇对讲
· 一卡通 · 电脑网络
· 智能系统 · 视频会议
· 综合布线 · 公共广播
· 电缆电线 · 工程设计
· 工程施工 · 工程维护
· 实用工具 · 企业管理
· 营销分析 · 精英人物
· 安防法规 · 交易平台
· 招聘求职 · 新闻频道
热门文章
· [组图] 学会使用万用表
· [图文] 汽车加油加气站设计...
· PICO2000常见问题解...
· 工程施工规范样本
· 晶体管手册
· [图文] 监控系统结构图
· 英文版的施工组织计...
· [组图] 监控系统施工线路图...
· 安全防范工程费用概...
· [推荐] 部分监控专用摄像机...
相关文章
93c46读写程序
作者:不详  来源:转载  发布时间:2006-7-19 10:13:35  发布人:老斑鸠

减小字体 增大字体

93c46读写程序
#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) {
unsigned char temp=address>>1;
if(address&0x01) return((unsigned char)(Read(temp)>>8));
else return((unsigned char)(Read(temp)));
}

void WriteChar(unsigned char address,unsigned char InData) {
unsigned char temp=address>>1;
if(address&0x01) Write(temp,(unsigned int)(Read(temp)&0x00ff|(InData<<8)));
else Write(temp,(unsigned int)(Read(temp)&0xff00|InData));
}

void ReadString(unsigned char data *RamAddress,unsigned char RomAddress,
unsigned char Number) {
while(Number!=0) {
*RamAddress=ReadChar(RomAddress);
RamAddress++;
RomAddress++;
Number--;
}
}

void WriteString(unsigned char data *RamAddress,unsigned char RomAddress,
unsigned char Number) {
unsigned int temp;
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);
}
[] [返回上一页] [打 印] [收 藏]
下一篇文章:智能卡内部文件系统
∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论...]
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 管理登录
Copyright © 2004~2008 Jhsafe.Com. All Rights Reserved .