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

📄 at45db161._c

📁 该程序是医院用的CPCR记录仪的终端控制程序
💻 _C
字号:
#include <d:\gkdoor\chensoft\main.h>
#include <d:\gkdoor\chensoft\at45db161.h>
#include <iom128v.h>
#include <macros.h>
unsigned char read_byte(void)
{
 	unsigned char i,data=0;
	SET_45IO();
    for (i=0;i<8;i++)
    {
	    SET_45SCK();
		data<<=1;
        if((PIND&0x20)==0x20)   // sda bit input data.
		data|=1;
		CLEAR_45SCK();
    }
    return data; 
}
void write_byte(unsigned char data1)
{
 	unsigned char i;
	for(i=0;i<8;i++)
	{
     if (data1&0x80)	 
     SET_45IO();    	  
     else 
     CLEAR_45IO();
	 CLOCK1();
	 data1<<=1;
     }
}
void CLOCK1(void)
{ 
     SET_45SCK();
     DELAY();
     CLEAR_45SCK();
}
void DELAY(void)
{
     unsigned char i;
     for (i=0;i<2;i++);
}
unsigned char read_status(void)
{
 	 unsigned char temp2;
	 CLEAR_45CS();
	 CLEAR_45SCK();
	 SET_45IO();
	 write_byte(0x57);
	 CLOCK1();
	 NOP();
	 temp2=read_byte();
	 SET_45CS();
	 return temp2;
}
void write_buffer1(unsigned int bitnum,unsigned char *pt)
{
 	 unsigned int i;
	 CLEAR_45CS();
	 CLEAR_45SCK();
	 SET_45IO();
	 write_byte(0x84);
	 write_byte(0x00);
	 i=bitnum>>8;
	 write_byte((unsigned char)i);
	 write_byte((unsigned char)bitnum);
	 for(i=0;i<528;i++)
	 write_byte(*pt++);
	 DELAY();
	 SET_45CS();
}
void write_mainmemory(unsigned int pagenum,unsigned char *pt)
{
 	 unsigned int i;
	 CLEAR_45CS();
	 SET_45IO();
	 CLEAR_45SCK();
	 write_byte(0x82);
	 i=pagenum>>6;
	 write_byte((unsigned char)i);
	 i=pagenum<<2;
	 write_byte((unsigned char)i);
	 write_byte(0x00);
	 for(i=0;i<528;i++)
	 write_byte(*pt++);
	 NOP();
	 SET_45IO();
	 CLEAR_45SCK();
	 SET_45CS();
	 for(i=0;i<50000;i++);
}
void write_buffer2(unsigned int bitnum,unsigned char *pt)
{
 	 unsigned int i;
	 CLEAR_45CS();
	 DELAY();
	 write_byte(0x87);
	 write_byte(0x00);
	 i=bitnum>>8;
	 write_byte((unsigned char)i);
	 write_byte((unsigned char)bitnum);
	 for(i=0;i<528;i++)
	 write_byte(*pt++);
	 SET_45CS();
}
void write_buffer1mainmemory(unsigned int pagenum)
{
 	 unsigned int i;
 	 unsigned char flag;
//	 write_buffer1(chip_cs,0,yyj02);
	 while(1)
	 {
	 flag=read_status();
	 if((flag&0x80)==0x80)
	 break;
	 }
	 CLEAR_45CS();
	 CLEAR_45SCK();
	 SET_45IO();
	 DELAY();
	 write_byte(0x83);
	 i=pagenum>>6;
	 write_byte((unsigned char)i);
	 i=pagenum<<2;
	 write_byte((unsigned char)i);
	 write_byte(0x00);
	 DELAY();
	 SET_45CS();
}	 
void write_buffer2mainmemory(unsigned int pagenum)
{
 	 unsigned int i;
 	 unsigned char flag;
//	 write_buffer2(chip_cs,0,yyj02);
	 while(1)
	 {
	 flag=read_status();
	 if((flag&0x80)==0x80)
	 break;
	 }
	 CLEAR_45CS();
	 CLEAR_45SCK();
	 SET_45IO();
	 DELAY();
	 write_byte(0x86);
	 i=pagenum>>6;
	 write_byte((unsigned char)i);
	 i=pagenum<<2;
	 write_byte((unsigned char)i);
	 write_byte(0x00);
	 DELAY();
	 SET_45CS();
}	 
unsigned char read_mainmemory(unsigned int pagenum,unsigned int bits)
{
 	 unsigned char flag,temp1;
	 unsigned int byte1,i;
	 while(1)
	 {
	 flag=read_status();
	 if(flag&0x80)
	 break;
	 }
	 CLEAR_45CS();
	 SET_45IO();
	 CLEAR_45SCK();
	 DELAY();
	 write_byte(0x52);
	 i=pagenum>>6;
	 write_byte((unsigned char)i);
	 i=pagenum<<2;
	 byte1=bits>>8;
	 i=(unsigned char)i+(unsigned char)byte1;
	 write_byte((unsigned char)i);
	 write_byte((unsigned char)bits);
	 write_byte(0x00);
	 write_byte(0x00);
	 write_byte(0x00);
	 write_byte(0x00);
//	 SET_45IO();
	 CLOCK1();
	 NOP();
	 temp1=read_byte();
	 SET_45CS();
	 return temp1;
}
void read_startarry(unsigned int pagenum,unsigned int bitnum,
                    unsigned char *pt,unsigned int len)
{
 	unsigned int i;
	unsigned char flag;
	while(1)
	 {
	 flag=read_status();
	 if(flag&0x80)
	 break;
	 }
	 CLEAR_45CS();
	 SET_45IO();
	 CLEAR_45SCK();
	 DELAY();
	 write_byte(0x68);
	 i=pagenum>>6;
	 write_byte((unsigned char)i);
	 i=pagenum<<2+bitnum>>8;
	 write_byte((unsigned char)i);
	 write_byte((unsigned char)bitnum);
	 write_byte(0x00);
	 write_byte(0x00);
	 write_byte(0x00);
	 write_byte(0x00);
	 CLOCK1();
	 for(i=0;i<len;i++)
	 *pt++=read_byte();
	 SET_45CS();
}	
void compare_buffer1page(unsigned int pagenum)
{
 	 unsigned int i;
 	 unsigned char flag;
	 while(1)
	 {
	 flag=read_status();
	 if(flag&0x80)
	 break;
	 }
	 CLEAR_45CS();
	 SET_45IO();
	 CLEAR_45SCK();
	 DELAY();
	 write_byte(0x60);
	 i=pagenum>>6;
	 write_byte((unsigned char)i);
	 i=pagenum<<2;
	 write_byte((unsigned char)i);
	 write_byte(0x00);
	 SET_45CS();
}				

⌨️ 快捷键说明

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