⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 x5325.c

📁 51单片机C语言常用模块与综合系统设计实例精讲
💻 C
字号:
#include <./Atmel/at89x52.h>
#include <stdio.h>
#include "source.h"
#include <intrins.h>
#include  <absacc.h>
#define	DELAY	_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_()
#define	WREN	0x06
#define	SFLB	0x00
#define	WRDI	0x04
#define	RSDR	0x05
#define	WRSR	0x01
#define	READ	0x03
#define	WRITE	0x02
void	x5325_write_byte(unsigned char  ch)
{
	unsigned char 	i=8;
	while(i--){
		EEPROMSCK=0;_nop_();
		if(ch&0x80)
			EEPROMSI=1;
		else
			EEPROMSI=0;
		ch<<=1;DELAY;
		EEPROMSCK=1;DELAY;
	}
	EEPROMSCK=0;
}

unsigned char x5325_read_byte(void)
{
	unsigned char	i=8;
	unsigned char 	ddata=0;
	while (i--){
		ddata<<=1 ;
		EEPROMSCK=0;DELAY;
		EEPROMSCK=1;DELAY;
		ddata|=EEPROMSO;
	}
	EEPROMSCK=0;
	return ddata;
}
void	x5325_write_enable(){
	EEPROMCSN=0;
	x5325_write_byte(WREN);
	EEPROMCSN=1;
	DELAY;
}
void	x5325_write( struct x5324_page *p){
	unsigned char i;
	EEPROMWPN=1;
	x5325_write_enable();
	EEPROMCSN=0;
	x5325_write_byte(WRITE);
	x5325_write_byte(p->add.ar[0]); //addres high ;
	x5325_write_byte(p->add.ar[1]);//address l;
	//write_debug(" ",NULL);
	//write_debug("%d",(unsigned char *)&(p->add.nt));
	for(i=0;i<p->counter;i++)
		x5325_write_byte(p->dat[i]);
	EEPROMCSN=1;
}
void	x5325_read( struct x5324_page *p){
	unsigned char i;
	EEPROMCSN=0;
	x5325_write_byte(READ);
	x5325_write_byte(p->add.ar[0]);
	x5325_write_byte(p->add.ar[1]);
	for(i=0;i<p->counter;i++)
		p->dat[i]=x5325_read_byte();
	EEPROMCSN=1;
}
#undef  DELAY

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -