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

📄 stc89c58_eeprom.c

📁 基于AT89s51的温湿度检测报警程序
💻 C
字号:
//********************************
//   stc89c51 eeprom program
//   2007.9.26
//   lp
//********************************
#include <at89x52.h>
#include "stc89c58_eeprom.h"			
#define uchar unsigned char
#define uint unsigned int
sfr  isp_data  = 0xe2;
sfr  isp_addrh = 0xe3;
sfr  isp_addrl = 0xe4;
sfr  isp_cmd   = 0xe5;
sfr  isp_trig  = 0xe6;
sfr  isp_contr = 0xe7;				
bit  temp;										
//********************************
//fun: eeprom start
//********************************
static void eeprom_start()
{
	temp=EA;						// save EA
	EA=0;
	isp_contr=0x81;
	isp_trig=0x46;
	isp_trig=0xb9;
}
//********************************
//fun: eeprom_end
//********************************
static void eeprom_stop()
{
	isp_contr=0;
	isp_cmd=0;
	isp_trig=0;
	isp_addrh=0;
	isp_addrl=0;
	EA=temp;
}
//********************************
//fun:read eeprom subprogram
//********************************		
char read_eeprom(int addr)
{
	uchar byte_data;                                           

	isp_addrh=addr>>8;				
	isp_addrl=addr&0xff;	
	isp_cmd=1;	
	eeprom_start();
//	null();	
	eeprom_stop();
	byte_data=isp_data;
	return(byte_data);
}
//********************************
//fun:write eeprom subprogram
//********************************		
void write_eeprom(int addr,char byte_data)
{

	isp_data=byte_data;	
	isp_addrh=addr>>8;				
	isp_addrl=addr&0xff;	
	isp_cmd=2;
	eeprom_start();
//	null();	
	eeprom_stop();
}
//********************************
//fun:wipe eeprom subprogram
//********************************		
void wipe_eeprom(int addr)
{
	
	isp_addrh=addr>>8;				
	isp_addrl=addr&0xff;		
	isp_cmd=3 ;
	eeprom_start();
//	null();	
	eeprom_stop();
}
//********************************
/*
main_loop()
{
	wipe_eeprom(0x8000);
	write_eeprom(0x8000,0xf9);
	TI=0;
	SBUF=read_eeprom(0x8000);
	while(!TI);
	TI=0;
	for(;;)
	{
		
	}
}
*/

⌨️ 快捷键说明

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