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

📄 sram.c

📁 指纹识别源代码,用于智能门紧,还有配合MF800卡使用
💻 C
字号:
#include "reg58.h"
#include "intrins.h"
#define _SRAM_C_
#include "sram.h"

#include "event.h"
#include "define.h"
#include "setup.h"
#include "system.h"
#include "user.h"

#include "373.h"

#define	MAXFUNCTIONS	4

/////////////////////////////////////////////////////////////////////////
unsigned char ram_readp0(unsigned char posi)
{
	unsigned char tempdata;
	SRAMA16=0;
	SRAMA17=0;
	SRAMA18=0;

	DATAPORT=posi;
	SEL573L=1;
	_nop_();
	SEL573L=0;
	
	DATAPORT=0;
	SEL573H=1;
	_nop_();
	SEL573H=0;
	
	DATAPORT=0XFF;

	SELK6=0;
	RD=0;
	_nop_();
	tempdata=DATAPORT;
	RD=1;
	SELK6=1;
	return tempdata;

}
/////////////////////////////////////////////////////////////////////////
void ram_writep0(unsigned char posi,unsigned char writechar)
{
	SRAMA16=0;
	SRAMA17=0;
	SRAMA18=0;

	DATAPORT=posi;
	SEL573L=1;
	_nop_();
	SEL573L=0;
	
	DATAPORT=0;
	SEL573H=1;
	_nop_();
	SEL573H=0;

	DATAPORT=writechar;
	SELK6=0;
	WR=0;
	_nop_();
	WR=1;
	SELK6=1;
}
/////////////////////////////////////////////////////////////////////////
unsigned char ram_read(unsigned short low16posi,unsigned char high3posi)
{
	//unsigned char tempdata;
	//t/empdata=position>>8;
	unsigned char tempdata;

	SRAMA16=0;
	SRAMA17=0;
	SRAMA18=0;
	ACC=high3posi;

	if(ACC&1)SRAMA16=1;
	if(ACC&2)SRAMA17=1;
	if(ACC&4)SRAMA18=1;
	//if(high3posi&1)SRAMA16=1;
	//if(high3posi&2)SRAMA17=1;
	//if(high3posi&4)SRAMA18=1;

	//tempdata=position>>16;
	DATAPORT=low16posi;
	SEL573L=1;
	_nop_();
	SEL573L=0;
	
	DATAPORT=low16posi>>8;
	SEL573H=1;
	_nop_();
	SEL573H=0;
	
	DATAPORT=0XFF;

	SELK6=0;
	RD=0;
	_nop_();
	tempdata=DATAPORT;
	RD=1;
	SELK6=1;
	return tempdata;
}
/////////////////////////////////////////////////////////////////////////
void ram_write(unsigned short low16posi,unsigned char high3posi,unsigned char writechar)
{
	//unsigned char tempdata;
	SRAMA16=0;
	SRAMA17=0;
	SRAMA18=0;

	ACC=high3posi;

	if(ACC&1)SRAMA16=1;
	if(ACC&2)SRAMA17=1;
	if(ACC&4)SRAMA18=1;

	//if(high3posi&1)SRAMA16=1;
	//if(high3posi&2)SRAMA17=1;
	//if(high3posi&4)SRAMA18=1;

	//tempdata=position>>16;
	DATAPORT=low16posi;
	SEL573L=1;
	_nop_();
	SEL573L=0;
	
	DATAPORT=low16posi>>8;
	SEL573H=1;
	_nop_();
	SEL573H=0;

	DATAPORT=writechar;
	SELK6=0;
	WR=0;
	_nop_();
	WR=1;
	SELK6=1;
	//WR=1;
}
/////////////////////////////////////////////////////////////////////////
void ram_read16(unsigned char ramitem8,unsigned char ramitem16)
{

	

	SRAMA16=0;
	SRAMA17=0;
	SRAMA18=0;

	ACC=ramitem16;
	if(ACC&0X10)SRAMA16=1;
	if(ACC&0X20)SRAMA17=1;
	if(ACC&0X40)SRAMA18=1;

	//if(ramitem16&0x10)SRAMA16=1;
	//if(ramitem16&0x20)SRAMA17=1;
	//if(ramitem16&0x40)SRAMA18=1;


	ramitem16=(ramitem16<<4)|(ramitem8>>4);
	ramitem8<<=4;

	DATAPORT=ramitem16;
	SEL573H=1;
	_nop_();
	SEL573H=0;


	//for(;(ramitem8&0xf)!=0xf;ramitem8++)
	//{
	do{
		DATAPORT=ramitem8;
		SEL573L=1;
		_nop_();
		SEL573L=0;
	
		DATAPORT=0XFF;

		SELK6=0;
		RD=0;
		_nop_();
		tempbuff[ramitem8&0xf]=DATAPORT;
		RD=1;
		SELK6=1;
		ramitem8++;
	}while(ramitem8&0xf);
}
/////////////////////////////////////////////////////////////////////////
//write data in tempbuff into sram
void ram_write16(unsigned char ramitem8,unsigned char ramitem16)
{
	
	SRAMA16=0;
	SRAMA17=0;
	SRAMA18=0;


	//if(ramitem16&0x10)SRAMA16=1;
	//if(ramitem16&0x20)SRAMA17=1;
	//if(ramitem16&0x40)SRAMA18=1;
	ACC=ramitem16;
	if(ACC&0X10)SRAMA16=1;
	if(ACC&0X20)SRAMA17=1;
	if(ACC&0X40)SRAMA18=1;


	ramitem16=(ramitem16<<4)|(ramitem8>>4);
	ramitem8<<=4;

	DATAPORT=ramitem16;
	SEL573H=1;
	_nop_();
	SEL573H=0;

	//for(;(ramitem8&0xf)!=0xf;ramitem8++)
	do
	{
		DATAPORT=ramitem8;
		SEL573L=1;
		_nop_();
		SEL573L=0;
	

		DATAPORT=tempbuff[ramitem8&0xf];
		SELK6=0;
		WR=0;
		_nop_();
		WR=1;
		SELK6=1;
		ramitem8++;
	}while(ramitem8&0xf);
}
/////////////////////////////////////////////////////////////////////////
//read 8 bytes' data in sram and copy to tempbuff
void ram_read8(unsigned char ramitem8,unsigned char ramitem16)
{


	SRAMA16=0;
	SRAMA17=0;
	SRAMA18=0;

	ramitem16=(ramitem16<<3)|(ramitem8>>5);
	ramitem8<<=3;

	DATAPORT=ramitem16;
	SEL573H=1;
	_nop_();
	SEL573H=0;

	//for(;(ramitem8&0x7)!=0x7;ramitem8++)
	do
	{
		DATAPORT=ramitem8;
		SEL573L=1;
		_nop_();
		SEL573L=0;
	
		DATAPORT=0XFF;

		SELK6=0;
		RD=0;
		_nop_();
		tempbuff[8+(ramitem8&0x7)]=DATAPORT;
		RD=1;
		SELK6=1;
		ramitem8++;
	}while(ramitem8&0x7);
}
/////////////////////////////////////////////////////////////////////////
void ram_write8(unsigned char ramitem8,unsigned char ramitem16)
{
	SRAMA16=0;
	SRAMA17=0;
	SRAMA18=0;

	ramitem16=(ramitem16<<3)|(ramitem8>>5);
	ramitem8<<=3;


	DATAPORT=ramitem16;
	SEL573H=1;
	_nop_();
	SEL573H=0;

	//for(;(ramitem8&0x7)!=0x7;ramitem8++)
	do
	{
		DATAPORT=ramitem8;
		SEL573L=1;
		_nop_();
		SEL573L=0;
	

		DATAPORT=tempbuff[ramitem8&0x7];
		SELK6=0;
		WR=0;
		_nop_();
		WR=1;
		SELK6=1;
		ramitem8++;
	}while(ramitem8&0x7);
}
/////////////////////////////////////////////////////////////////////////
void init_sram()
{
	//unsigned char tempdata;
	
	//deletealluser();
	
	//sramtest();
	//ram_read16(128,0);
	//ram_read16(0,0);
	
	
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
unsigned short sramgetshort(unsigned char address)
{
	unsigned short tempcount;
	//tempcount=(ram_readp0(address+1)<<8)|ram_readp0(address);
	tempcount=ram_readp0(address+1)<<8;
	tempcount|=ram_readp0(address);
	//tempcount=ram_readp0(address);
	//tempcount+=ram_readp0(address+1)<<8;
	return tempcount;
	
}
/////////////////////////////////////////////////////////////////////////
unsigned char readsecumode()
{
	unsigned char tempdata;
	tempdata=ram_readp0(SECUMODE);
	if(tempdata>=MAXSETMODESEL)
	{
		ram_writep0(SECUMODE,0);
		tempdata=0;
	}
	return tempdata;
}
/////////////////////////////////////////////////////////////////////////
unsigned char readapbmode()
{
	unsigned char tempdata;
	tempdata=ram_readp0(APBMODE);
	if(tempdata>=MAXSETAPBSEL)
	{
		ram_writep0(APBMODE,0);
		tempdata=0;
	}
	return tempdata;
}
/////////////////////////////////////////////////////////////////////////
unsigned char readcommid()
{
	unsigned char tempdata;
	tempdata=ram_readp0(COMMID);
	if(tempdata>=MAXCOMMID)
	{
		ram_writep0(COMMID,0);
		tempdata=0;
	}
	return tempdata;
}
/////////////////////////////////////////////////////////////////////////
unsigned char readduress()
{
	unsigned char tempdata;
	tempdata=ram_readp0(DURESSMODE);
	if(tempdata>=MAXDURESSSEL)
	{
		ram_writep0(DURESSMODE,0);
		tempdata=0;
	}
	return tempdata;
}
/////////////////////////////////////////////////////////////////////////
unsigned char readduresspw()
{
	unsigned char tempdata;
	tempdata=ram_readp0(DURESSPW);
	if(tempdata>=100)
	{
		ram_writep0(DURESSMODE,0);
		tempdata=0;
	}
	return tempdata;
}
/////////////////////////////////////////////////////////////////////////
unsigned char readbaudrate()
{
	unsigned char tempdata;
	tempdata=ram_readp0(BAUDRATE);
	if(tempdata>=MAXBAUDRATESEL)
	{
		ram_writep0(BAUDRATE,0);
		tempdata=0;
	}
	return tempdata;
}
/////////////////////////////////////////////////////////////////////////
unsigned char readpinkeyin()
{
	unsigned char tempdata;
	tempdata=ram_readp0(PINKEYIN);
	if(tempdata>=MAXPINKEYINSEL)
	{
		ram_writep0(PINKEYIN,1);
		tempdata=1;
	}
	return tempdata;
}
/////////////////////////////////////////////////////////////////////////
unsigned char readmodeindex()
{
	unsigned char tempdata;
	tempdata=ram_readp0(MODEINDEX);
	if(tempdata>=MAXMODEINDEX)
	{
		ram_writep0(MODEINDEX,0);
		tempdata=0;
	}
	return tempdata;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
unsigned char readfpmode()
{
	unsigned char tempdata;
	tempdata=ram_readp0(FPMODE);
	if(tempdata>=MAXFPMODESEL)
	{
		ram_writep0(FPMODE,0);
		tempdata=0;
	}
	return tempdata;
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
unsigned char readFunctions()
{
	unsigned char tempdata;
	tempdata=ram_readp0(FUNCTIONS);
	if(tempdata>=MAXFUNCTIONS)
	{
		ram_writep0(FUNCTIONS,0);
		tempdata=0;
	}
	return tempdata;
}
/////////////////////////////////////////////////////////////////////////
unsigned char readmasterchange()
{
	unsigned char tempdata;
	tempdata=ram_readp0(MASTERCHANGED);
	if(tempdata>=MAXMASTERCHANGED)
	{
		ram_writep0(MASTERCHANGED,0);
		tempdata=0;
	}
	return tempdata;
}
/////////////////////////////////////////////////////////////////////////
unsigned short readeventstart()
{
	unsigned short eventstart;

	eventstart=ram_readp0(EVENTSTART);
	eventstart+=ram_readp0(EVENTSTART+1)<<8;

	if(eventstart>=MAXEVENTNUM)
	{
		eventstart=0;
		ram_writep0(EVENTSTART,0);
		ram_writep0(EVENTSTART+1,0);
	}
	return eventstart;
}
/////////////////////////////////////////////////////////////////////////
unsigned short readeventstop()
{
	unsigned short recordstop;

	recordstop=ram_readp0(EVENTSTOP+1)<<8;
	recordstop+=ram_readp0(EVENTSTOP);

	if(recordstop>=MAXEVENTNUM)
	{
		recordstop=0;
		ram_writep0(EVENTSTOP,0);
		ram_writep0(EVENTSTOP+1,0);
	}
	return recordstop;
}
/////////////////////////////////////////////////////////////////////////
unsigned char readholindex(unsigned char tsindex)
{
	unsigned char tempdata;
	tempdata=ram_readp0(TSHOLINDEXSTART+tsindex);
	if(tempdata>=MAXTSHOLINDEX)
	{
		ram_writep0(TSHOLINDEXSTART+tsindex,0);
		tempdata=0;
	}
	return tempdata;
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
/*unsigned char readtype()
{
	unsigned char tempdata;
	tempdata=ram_read(TYPE,0);
	if(tempdata>=MAXSETTYPESEL)
	{
		ram_write(TYPE,0,0);
		tempdata=0;
	}
	return tempdata;
}*/
/////////////////////////////////////////////////////////////////////////
bit sramtest()
{
	unsigned char testbank;	//0~127
	unsigned char testgroup,i;
	
	for(testbank=0;testbank<128;testbank++)
	{
		displaymessage(LMRAMTESTBANK,LINE1);
		displayshort(testbank,3,9);
		testgroup=0;
		do
		{
			ram_read16(testgroup,testbank);
			idata2idata(tempbuff,dispbuff[LINE1],16);
			for(i=0;i<16;i++)tempbuff[i]=0x55;
			ram_write16(testgroup,testbank);
			ram_read16(testgroup,testbank);
			for(i=0;i<16;i++)
			{
				if(tempbuff[i]!=0x55)return FALSE;
			}
					
			for(i=0;i<16;i++)tempbuff[i]=0xaa;
			ram_write16(testgroup,testbank);
			ram_read16(testgroup,testbank);
			for(i=0;i<16;i++)
			{
				if(tempbuff[i]!=0xaa)return FALSE;
			}
			
			idata2idata(dispbuff[LINE1],tempbuff,16);
			ram_write16(testgroup,testbank);
			
			testgroup++;
		}while(testgroup);
	}
	return TRUE;
}
/////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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