没有合适的资源?快使用搜索试试~ 我知道了~
AT45DB041存储芯片读写
需积分: 33 11 下载量 129 浏览量
2011-10-23
17:28:21
上传
评论
收藏 9KB TXT 举报
温馨提示
试读
8页
这个程序原本是从论坛上下载的,但是用到51单片机中不能使用,只能一次写一个字节, 经过高手的修改,已经能够用在51中。
资源推荐
资源详情
资源评论
/******************************************************************************
这个程序原本是从论坛上下载的,但是用到51单片机中不能使用,只能一次写一个字节,
经过高手的修改,已经能够用在51中。
2011.07.27
******************************************************************************/
/******************************************************************************/
/*正常操作电压为2.7~3.6V,实验中发现当电压超过4.25V后读出的状态字节为9A(正常 */
/*的状态字节值为9D),并且读写数据均不准确,所以应当保证卡片的供电电压不超过 */
/*4.25V。 */
/*SPI规范:Data is always clocked into the device on the rising edge of SCK a-*/
/* nd clocked out of the device on the falling edge of SCK.All instruction-*/
/* s,addresses and data are transferred with the most significant bit(MSB) */
/* first. */
/* 2005-06-02*/
/******************************************************************************/
#include <reg52.h>
#include <string.h>
#include <intrins.h>
#include <main.h>
#define UCHAR unsigned char
#define UINT unsigned int
//===================
sfr P4 = 0xe8;
//===================
sbit SPI_CS = P4^1;
sbit SPI_SCK = P4^0;
sbit SPI_SO = P4^3;
sbit SPI_SI = P4^2;
这个程序原本是从论坛上下载的,但是用到51单片机中不能使用,只能一次写一个字节,
经过高手的修改,已经能够用在51中。
2011.07.27
******************************************************************************/
/******************************************************************************/
/*正常操作电压为2.7~3.6V,实验中发现当电压超过4.25V后读出的状态字节为9A(正常 */
/*的状态字节值为9D),并且读写数据均不准确,所以应当保证卡片的供电电压不超过 */
/*4.25V。 */
/*SPI规范:Data is always clocked into the device on the rising edge of SCK a-*/
/* nd clocked out of the device on the falling edge of SCK.All instruction-*/
/* s,addresses and data are transferred with the most significant bit(MSB) */
/* first. */
/* 2005-06-02*/
/******************************************************************************/
#include <reg52.h>
#include <string.h>
#include <intrins.h>
#include <main.h>
#define UCHAR unsigned char
#define UINT unsigned int
//===================
sfr P4 = 0xe8;
//===================
sbit SPI_CS = P4^1;
sbit SPI_SCK = P4^0;
sbit SPI_SO = P4^3;
sbit SPI_SI = P4^2;
unsigned char aaa;
void dyms20(void)
{unsigned char i;
for(i=0;i<30;i++) i++;
}
unsigned char SPI_HostReadByte(void)
{
unsigned char i,rByte=0;
for(i=0;i<8;i++)
{
SPI_SCK=0;
dyms20();
SPI_SCK=1;
rByte<<=1;
if(SPI_SO) rByte |= 0x01;
else rByte &= ~0x01;
}
return rByte;
}
void SPI_HostWriteByte(unsigned char wByte)
{
unsigned char i;
for(i=0;i<8;i++)
{
if((wByte<<i)&0x80){SPI_SI=1;}
void dyms20(void)
{unsigned char i;
for(i=0;i<30;i++) i++;
}
unsigned char SPI_HostReadByte(void)
{
unsigned char i,rByte=0;
for(i=0;i<8;i++)
{
SPI_SCK=0;
dyms20();
SPI_SCK=1;
rByte<<=1;
if(SPI_SO) rByte |= 0x01;
else rByte &= ~0x01;
}
return rByte;
}
void SPI_HostWriteByte(unsigned char wByte)
{
unsigned char i;
for(i=0;i<8;i++)
{
if((wByte<<i)&0x80){SPI_SI=1;}
剩余7页未读,继续阅读
资源评论
zlsu27
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功