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

📄 copy.c

📁 EEPROM局部抄写软件,可以任意设置地址,抄写一段数据,数据由母片提供.
💻 C
📖 第 1 页 / 共 3 页
字号:
#include "reg52.H"
#include "intrins.h"

#define uchar unsigned char
#define uint unsigned int
#define _Nop() _nop_()
sbit LED2=P1^7;
sbit SPEAKE=P1^5;
sbit CONTR=P1^4;
sbit SDA2=P1^3;
sbit SDA9=P1^2;
sbit SDA1=P1^1;
sbit SCL=P1^0;
sbit WORK=P3^7;
sbit CONTR1=P1^6;
uchar  bb, feed_space;
bit ack,ALM;
extern bit work_start0;
bit work_start,start,ok;
uchar code  SEG[19]={ 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xBF,0xff,0xF7};
uchar pal_hi_add,pal_lo_add,pal_leng;
uchar ntsc_hi_add,ntsc_lo_add,ntsc_leng;
uchar quxian_hi_add,quxian_lo_add,quxian_leng;
uchar satus1;
uchar MODE1,HIH,HIL,LOH,LOL,LENG_HI,LENG_LO;
 uchar jiyi_buffer[13];
extern  uchar scanf(void );
extern void  disp_select(uchar);
extern  bit  JIYI_RS16K ( uchar sla, uchar suba, uchar *s, uchar no );
extern void set_select(uchar  i);
extern   bit JIYI_SendStr16K( uchar sla, uchar suba, uchar *s, uchar no );

/////////////////////////////////////////
/*bit  delay1(uint dd)
{uchar m1=0xff,m2=0x02;
do{  m2=0x02;m1=0xff;
  do{
     do{  m1--;}while(m1!=0);
		m2--;
   	}while(m2!=0);
		dd--;
  }while(dd!=0);
  return(1);
}*/
/////////////////////bit  delay1(uint dd)
bit  delay2(uint dd)
{uchar m1=0x7f,m2=0x01;
do{  m2=0x01;m1=0x7f;
  do{
     do{  m1--;}while(m1!=0);
		m2--;
   	}while(m2!=0);
		dd--;
  }while(dd!=0);
  return(1);
}
/////////////////////////////
void  delay( dd)
{uchar m1=0xff,m2=0x02;
/*do{  m2=0x02;m1=0xff;
  do{
     do{  m1--;}while(m1!=0);
		m2--;
   	}while(m2!=0);
		dd--;
  }while(dd!=0);*/
#pragma asm
 
  //MOV R5,#0XF8
DELAY2:  MOV R4,#0X02
DELAY1:mov r5,#0xf8
DELAY0:DJNZ R5,DELAY0
       NOP
       DJNZ R4,DELAY1
       DJNZ R7,DELAY2
       MOV R7,#0XFF
       MOV A,R6
       MOV 67H,A
       JZ OUT
       DEC R6
       MOV A,R6
       CJNE A,67H,DELAY2
      OUT: RET
#pragma endasm


}
//uchar idata test _at_ 0x30; 
void jubuStartI2c( )
{

        SDA1 = 1;
	_Nop();
	_Nop();
	_Nop();
	SCL = 1;
	_Nop();    //  after stop must wait > 4.7 can to new start
       _Nop();
       _Nop();
	_Nop();
	_Nop();
	_Nop();
	_Nop();
	SDA1 = 0;
	_Nop();    //  the start signal keep up to > 4.0
	_Nop();
	_Nop();
	_Nop();
       _Nop();
	_Nop();
	_Nop();
        SCL = 0;
	_Nop();    // T_low > 4.7
	_Nop();
       _Nop();
	_Nop();
       _Nop();
	_Nop();
	_Nop();

}


void jubuStopI2c()
{
	SDA1 = 0;
	_Nop();
	_Nop();
    SCL = 1;
	_Nop();
	_Nop();
	_Nop();
	_Nop();
    	_Nop();
    	_Nop();
	_Nop();
	SDA1 = 1;
	_Nop();
	_Nop();
	_Nop();
	_Nop();
	_Nop();
}

void jubuSend_byte( uchar c )
{
	uchar BitCnt;
	for( BitCnt = 0; BitCnt < 8; BitCnt ++ )
	{
		if((c << BitCnt) & 0x80) SDA1 = 1;
		else SDA1 = 0;
		_Nop();
		_Nop();
		_Nop();
		SCL = 1;
   	    	_Nop();
		_Nop();
		_Nop();
        	_Nop();
        	_Nop();
		_Nop();
		_Nop();
		SCL = 0;
		_Nop();
		_Nop();
               _Nop();
	}
	_Nop();
	_Nop();
	_Nop();
   	SDA1 = 1;
	_Nop();
       _Nop();
	_Nop();
	SCL = 1;
	_Nop();
	_Nop();
       _Nop();
	_Nop();
	_Nop();
       _Nop();
	if (SDA1 == 1) ack =0;
	else ack = 1;
	SCL = 0;
	_Nop();
	_Nop();
	_Nop();
    	_Nop();
}
///////////////
uchar jubuRcv_byte()
{
	uchar retc;
	uchar BitCnt;

	retc = 0;
	SDA1 = 1;
	for( BitCnt = 0 ; BitCnt < 8; BitCnt ++)
	{
		_Nop();
		_Nop();
		_Nop();
		SCL = 0;
		_Nop();
		_Nop();
		_Nop();
		_Nop();
        	_Nop();
		_Nop();
		_Nop();
        	SCL = 1;
		_Nop();
		_Nop();
		_Nop();
		_Nop();
		_Nop();
		_Nop();
		_Nop();
		retc = retc << 1;
		if (SDA1 == 1) retc= retc +1;
		_Nop();
		_Nop();
		_Nop();
		_Nop();
    }
	SCL = 0;
	_Nop();
	_Nop();
	_Nop();
	_Nop();
   return(retc);
}
void jubuAckI2c( bit a )
{
	if ( a == 0) SDA1 = 0;
	else SDA1 = 1;
	_Nop();
	_Nop();
	_Nop();
	_Nop();
	_Nop();
    SCL = 1;
	_Nop();
	_Nop();
	_Nop();
    	_Nop();
    	_Nop();
	_Nop();
	SCL = 0;
	_Nop();
	_Nop();
	_Nop();
}
///////////////////////////////////
bit jubu_RS16K ( uchar sla, uchar suba, uchar *s, uchar no )
{
	uchar i;
	jubuStartI2c ();
	jubuSend_byte (sla);
    	if( ack == 0 ) return (0);
	jubuSend_byte (suba);
		if (ack == 0 ) return (0);
        jubuStartI2c();
	jubuSend_byte(sla + 1);
		if ( ack == 0) return ( 0 );
	for(i =0;i< no -1; i++)
		{
		*s = jubuRcv_byte();
		jubuAckI2c(0);
		s++;
		}
	*s = jubuRcv_byte();
	jubuAckI2c(1);
	jubuStopI2c();
	return(1);
}
bit jubu_RS32K ( uchar sla, uint suba, uchar *s, uchar no )
{
	uchar i;
	jubuStartI2c ();
 	jubuSend_byte (sla);
    	if( ack == 0 ) return (0);
	jubuSend_byte (suba / 256);       // the high byte address
		if (ack == 0 ) return (0);
        jubuSend_byte (suba % 256);       // the low byte address
		if (ack == 0 ) return (0);
	jubuStartI2c();
	jubuSend_byte(sla + 1);
		if ( ack == 0) return ( 0 );
	for(i =0;i< no -1; i++)
		{
		*s = jubuRcv_byte();
		jubuAckI2c(0);
		s++;
		}
	*s = jubuRcv_byte();
	jubuAckI2c(1);
	jubuStopI2c();
	return(1);
}
////////////////////////////////
   bit jubuSendStr16K( uchar sla, uchar suba, uchar *s, uchar no )
{
        uchar i;
        jubuStartI2c();
        jubuSend_byte(sla);
        if(ack == 0)return (0);
        jubuSend_byte(suba);
           if(ack == 0)return (0);
        for( i = 0; i < no ;i ++)
        {
                jubuSend_byte(*s);
                if(ack == 0)return (0);
                s++;
         }
         jubuStopI2c();
         return (1);
}
bit jubuSendStr32K( uchar sla, uint suba, uchar *s, uchar no )
{
        uchar i;
        jubuStartI2c();
        jubuSend_byte(sla);
        if(ack == 0)return (0);
        jubuSend_byte(suba / 256);  // the high byte address
        if(ack == 0)return (0);
        jubuSend_byte(suba % 256);   // the low byte address
        if(ack == 0)return (0);
        for( i = 0; i < no-1 ;i ++)
        {
                   jubuSend_byte(*s);
                if(ack == 0)return (0);
                s++;
         }
		  jubuSend_byte(*s);
         jubuStopI2c();

         return (1);
}
//////////////////////////////////////////////
void feedStartI2c( )
{

        SDA9 = 1;
	_Nop();
	_Nop();
	_Nop();
	SCL = 1;
	_Nop();    //  after stop must wait > 4.7 can to new start
       _Nop();
       _Nop();
	_Nop();
	_Nop();
	_Nop();
	_Nop();
	SDA9 = 0;
	_Nop();    //  the start signal keep up to > 4.0
	_Nop();
	_Nop();
	_Nop();
       _Nop();
	_Nop();
	_Nop();
        SCL = 0;
	_Nop();    // T_low > 4.7
	_Nop();
       _Nop();
	_Nop();
       _Nop();
	_Nop();
	_Nop();

}

void feedStopI2c()
{
	SDA9 = 0;
	_Nop();
	_Nop();
    SCL = 1;
	_Nop();
	_Nop();
	_Nop();
	_Nop();
    	_Nop();
    	_Nop();
	_Nop();
	SDA9 = 1;
	_Nop();
	_Nop();
	_Nop();
	_Nop();
	_Nop();
}

void feedSend_byte( uchar c )
{
	uchar BitCnt;
	for( BitCnt = 0; BitCnt < 8; BitCnt ++ )
	{
		if((c << BitCnt) & 0x80) SDA9 = 1;
		else SDA9 = 0;
		_Nop();
		_Nop();
		_Nop();
		SCL = 1;
   	    	_Nop();
		_Nop();
		_Nop();
        	_Nop();
        	_Nop();
		_Nop();
		_Nop();
		SCL = 0;
		_Nop();
		_Nop();
               _Nop();
	}
	_Nop();
	_Nop();
	_Nop();
   	SDA9 = 1;
	_Nop();
       _Nop();
	_Nop();
	SCL = 1;
	_Nop();
	_Nop();
       _Nop();
	_Nop();
	_Nop();
       _Nop();
	if (SDA9 == 1) ack =0;
	else ack = 1;
	SCL = 0;
	_Nop();
	_Nop();
	_Nop();
    	_Nop();
}

uchar feedRcv_byte()
{
	uchar retc;
	uchar BitCnt;

	retc = 0;
	SDA9 = 1;
	for( BitCnt = 0 ; BitCnt < 8; BitCnt ++)
	{
		_Nop();
		_Nop();
		_Nop();
		SCL = 0;
		_Nop();
		_Nop();
		_Nop();
		_Nop();
        	_Nop();
		_Nop();
		_Nop();
        	SCL = 1;
		_Nop();
		_Nop();
		_Nop();
		_Nop();
		_Nop();
		_Nop();
		_Nop();
		retc = retc << 1;
		if (SDA9 == 1) retc= retc +1;
		_Nop();
		_Nop();
		_Nop();
		_Nop();
    }
	SCL = 0;
	_Nop();
	_Nop();
	_Nop();
	_Nop();

⌨️ 快捷键说明

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