📄 ade7758p.h
字号:
unsigned char status_5460_0;// zhuang tai zi
unsigned char status_5460_1;// zhuang tai zi
unsigned char r7758ok;
unsigned char check_value7758;
unsigned int time_2s_7758;
unsigned char time_one_ms_7758;
//add 2004-4-14
unsigned char low_v_a;
unsigned char low_v_b;
unsigned char low_v_c;
//add 2004-4-6
unsigned char r7758mode_ok;
unsigned int pulse_delaysecond_7758;
struct bit_spi5460 {
unsigned char b0:1;
unsigned char b1:1;
unsigned char b2:1;
unsigned char b3:1;
unsigned char b4:1;
unsigned char b5:1;
unsigned char b6:1;
unsigned char b7:1;
};
union byte_spi5460{
struct bit_spi5460 bit;
unsigned char byte;
};
unsigned char spi_status;
void spi_cs5460bytwait () //delay 30us
{unsigned char f;
for (f=0;f<9;f++)//l20
{;}
}
void spi_cs5460clkwait () //delay 10us
{unsigned char f,l;
for (f=0;f<3;f++) ////l7 15
{;}
}
void spi_cs5460ready ()
{
spi_dcs=1; //out
spi_dsdi=0; //in
spi_dsdo=1; //out
spi_dclk=1; //out
spi_clk=0;
spi_cs=1;
spi_cs5460bytwait ();
spi_cs5460bytwait ();
spi_cs=0; //chip select
spi_cs5460bytwait (); //wait 100us
}
spi_7758wrbyte(unsigned char a) //write a byte
{unsigned char i;
union byte_spi5460 sdo_byte;
sdo_byte.byte=a;
for (i=0;i<8;i++)
{
spi_clk=0;
spi_cs5460clkwait ();
spi_clk=1;
spi_sdo=sdo_byte.bit.b7;
spi_cs5460clkwait ();
spi_clk=0;
sdo_byte.byte=sdo_byte.byte<<1;
}
spi_clk=0;
spi_cs5460clkwait();
}
unsigned char spi_7758rebyte() //recave a byte
{unsigned char i;
union byte_spi5460 sdi_byte;
for (i=0;i<8;i++)
{
spi_clk=0;//v0
spi_cs5460clkwait ();
spi_clk=1;//v1
spi_cs5460clkwait ();
sdi_byte.byte=sdi_byte.byte<<1;
sdi_byte.bit.b0=spi_sdi;
}
spi_clk=0;
spi_cs5460clkwait ();
return sdi_byte.byte;
}
//l2004-2-14 7758 add
void write7758(addr,num)
unsigned char addr,num;
{unsigned char l;
spi_cs5460ready();
spi_7758wrbyte(0x80|addr);
for(l=0;l<num;l++)
{
spi_cs5460clkwait();
spi_7758wrbyte(wr_data[l]);
}
spi_cs=1;
}
const unsigned char table_use7758[]={1,2,4,0x8,0x10,0x20,0x40,0x80};
unsigned char num_one(unsigned char value)
{unsigned char l,m;
m=0;
for(l=0;l<8;l++)
if((table_use7758[l]&value)!=0)
m=m+1;
return m;
}
void read7758(addr,num)
unsigned char addr;
unsigned char num;
{unsigned char l,m;
spi_cs5460ready();
spi_7758wrbyte(0x7f&addr);
for(l=0;l<num;l++)
{
spi_cs5460clkwait();
wr_data[l]=spi_7758rebyte();
}
spi_cs=1;
m=0;
for(l=0;l<num;l++)
m=m+num_one(wr_data[l]);
spi_cs5460ready();
spi_7758wrbyte(0x7e);
spi_cs5460clkwait();
l=spi_7758rebyte();
spi_cs=1;
if(l==m)
r7758ok=1;
else
r7758ok=0;
}
const unsigned char table_7758[]=
{
1,//OPMODE 13H
1,//MMODE 14H
1,//WAVMODE 15H
1,//COMPMODE 16H
1,//LCYCMODE 17H
0,//MASK 18H
0,//STATUS19H
0,//RSTATUS1AH
2,//ZXTOUT1BH
2,//LINCYC1CH
1,//L1DH
1,//L1EH
1,//L1FH
0,//L20H
0,//L21H
0,//L22
0,//L23 1
2,//L24
2,//L25
2,//L26
2,//L27
2,//L28
2,//L29
2,//L2A
2,//L2B
2,//L2C
2,//L2D
2,//L2E
2,//L2F
2,//L30
2,//L31
2,//L32
2,//L33
2,//L34
2,//L35
2,//L36
2,//L37
2,//L38
2,//L39
2,//L3A
2,//L3B
2,//L3C
2,//L3D
2,//L3E
1,//L3F
1,//L40
1,//L41
1,//L42
1,//L43
1,//L 44
0,//L45 2
2,//L46
0,//L47 2
2//L48
};
const unsigned char table_7758_check[]=
{
0,//OPMODE 13H 0---all 1---if 1byte 7bit 2---if 2 byte 12bit
3,//MMODE 14H 0
0,//WAVMODE 15H
3,//COMPMODE 16H
3,//LCYCMODE 17H 0
0,//MASK 18H
0,//STATUS19H
0,//RSTATUS1AH
0,//ZXTOUT1BH
0,//LINCYC1CH
0,//L1DH
0,//L1EH
0,//L1FH
0,//L20H
0,//L21H
0,//L22
0,//L23 1
2,//L24
2,//L25
2,//L26
2,//L27
2,//L28
2,//L29
3,//L2A
3,//L2B
3,//L2C
2,//L2D
2,//L2E
2,//L2F
2,//L30
2,//L31
2,//L32
2,//L33
2,//L34
2,//L35
2,//L36
2,//L37
2,//L38
2,//L39
2,//L3A
2,//L3B
2,//L3C
2,//L3D
2,//L3E
3,//L3F
3,//L40
3,//L41
0,//L42
0,//L43
0,//L 44
0,//L45
2,//L46
0,//L47
2//L48
};
//unsigned int f_all;
void init_7758()
{unsigned char i,l;
low_v_a=0;
low_v_b=0;
low_v_c=0;
//f_all=0;
r7758mode_ok=0;
status_5460_0=0;
status_5460_1=0;
spi_status=0;
wr_data[0]=0;
check_value7758=0;
pulse_delaysecond_7758=0;
data_addr.addri=EPLOCK_7758+4*(0x23-0x13);
if(0==read(EPLOCK,4))
{
data_addr.addri=EP1_7758+4*(0x23-0x13);
read(EP1,4);
}
write7758(0x23,1);
for(i=0x14;i<0x49;i++)//e 13
{
if(table_7758[i-0x13]!=0)
{
data_addr.addri=EPLOCK_7758+4*(i-0x13);
if(0==read(EPLOCK,4))
{
data_addr.addri=EP1_7758+4*(i-0x13);
read(EP1,4);
}
if(RAM[R_KWHMODE_F]==0)
if(i==0x16)
wr_data[0]=wr_data[0]|0x20;
write7758(i,table_7758[i-0x13]);
}
}
data_addr.addri=EPLOCK_7758;
if(0==read(EPLOCK,4))
{
data_addr.addri=EP1_7758;
read(EP1,4);
}
write7758(0x13,1);
}
unsigned char check7758()
{unsigned char l,value,m,h,g,a[10];
unsigned char mk,l1;
//add 2004-08-17----------------->start
read7758(0x7d,2);
if(r7758ok==1)
{
if((0!=wr_data[0])||(0xf7!=wr_data[1]))
{
wr_data[0]=0;
wr_data[1]=0xf7;
write7758(0x7d,2);
}
}
//add2004-08-17------------------>end
value=1;
if(check_value7758>5)
check_value7758=0;//l5
for(l=0;l<9;l++)
{
l1=9*check_value7758+l;
m=table_7758[l1];
if(m!=0)
{
read7758(0x13+l1, m);
if(0==r7758ok)
value=0;
if(1==value)
{
for(h=0;h<m;h++)
a[h]=wr_data[h];
data_addr.addri=EPLOCK_7758+4*l1;
if(0==read(EPLOCK,m))
{
data_addr.addri=EP1_7758+4*l1;
read(EP1,m);
}
// add-----------------start
if(RAM[R_KWHMODE_F]==0)
// changed by zhanglong ---->Start
if((l1+0x13)==0x16)
mk=3;
//wr_data[0]=wr_data[0]|0x20;
// changed by zhanglong ---->end
//add end--------------->end
mk=table_7758_check[l1];
if(mk==1)
{
wr_data[0]=0x7f&wr_data[0];
a[0]=a[0]&0x7f;
}
else
if(mk==2)
{
wr_data[0]=0xf&wr_data[0];
a[0]=a[0]&0xf;
}
if(mk!=3)//add
for(g=0;g<m;g++)//m
{
if(wr_data[g]!=a[g])
{
value=0;
}
}
}
}
}
if(1==value)
{
check_value7758=check_value7758+1;
if(check_value7758>5)
check_value7758=0;
return 0;
}
return 1;
}
void long_to_8bcd(value,point)
unsigned long value;
unsigned char *point;
{unsigned long l1;
unsigned char m,m1,m2;
l1=value;
for(m2=0;m2<4;m2++)
{
m=l1%10;
m1=(l1%100)/10;
*(point+m2)=(m1<<4)+m;
l1=l1/100;
}
}
void cos_from_kw_kva(ukw,ukva,point)
unsigned long ukw,ukva;
unsigned char *point;
{unsigned long l,lkw,lkva;
unsigned long a[2];
lkw=ukw;
lkva=ukva;
if(lkva<10)
{
lkva=1;
lkw=1;
}
else
if(lkw>=lkva)
lkw=lkva;
if(lkw<=lkva)
{
a[0]=(100*lkw)/lkva;
l=(100*lkw)%lkva;
a[1]=(10000*l)/lkva;
a[0]=10000*a[0]+a[1];
long_to_8bcd(a[0],point);
}
}
unsigned long sqrt_xy(x,y)
unsigned long x,y;
{unsigned int z_max,z_min,z;
unsigned char l;
unsigned long value1,value2;
z_max=0xffff;
z_min=0;
z=0x8000;
value1=x;
value1=value1*value1;
value2=(CK_KW*y)/CK_KVAR;
value2=value2*value2;
value1=value1+value2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -