//#pragma src
#include "reg52.H"
#include "intrins.h"
//#include "math.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 P27=P2^7;
sbit P24=P2^4;
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;
//extern void delay( dd);
void feed_copy(void);
void pal_copy0(uchar hi_add,uchar lo_add, uint pal_count11,uchar leng);
uchar leijia_read(uchar ad);
extern uchar scanf(void );
void re_copy (uchar hi_add,uchar lo_add,uchar leng);
extern void disp_select(uchar);
void leijia(void);
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();