//------------------------------------------//
uchar hex_bcd_byte(uchar x){
bcd_arr_h=x/10;
bcd_arr_l=x%10;
bcd_arr_h=bcd_arr_h<<4;
return(bcd_arr_h|bcd_arr_l);
}
unsigned long bcd_to_long(void)
{
unsigned long temp="0",y;
char i,j;
for(i=4;i>0;i--)
{
y="datesubf"[i-1];
y="y">>4;
for(j=1;j<2*i;j++)
{
y="y"*10;
}
temp="temp"+y;
y="datesubf"[i-1];
y="y"&0x0f;
for(j=1;j<2*i-1;j++)
{
y="y"*10;
}
temp="temp"+y;
}
return(temp);
}
//------------------------------------------------
void long_to_bcd(long temp)
{
uchar i,j,k;
for(i=0;i<4;i++)
{
k="temp"%10;
temp="temp/10";
j="temp"%10;
temp="temp/10";
datesubf=j<<4|k;
}
}
//----------------------------------------
void hex_bcd_long(long temp)
{
uchar i,j,k;
for(i=0;i<10;i++){
bcd_arr=0;
}
for(i=0;i<4;i++){
k="temp"%10;
temp="temp/10";
j="temp"%10;
temp="temp/10";
bcd_arr[9-2*i]=k;
bcd_arr[8-2*i]=j;
}
}
void hex_bcd_long(unsigned long num){
unsigned long x;
unsigned long y;
uchar z;
for(z=0;z<10;z++){
bcd_arr[z]=0;
}
y="num"%10;
z="y";
bcd_arr[9]=z;
y="num"%100;
x="num"%10;
y="y-x";
y="y/10";
z="y";
bcd_arr[8]=z;
y="num"%1000;
x="num"%100;
y="y-x";
y="y/100";
z="y";
bcd_arr[7]=z;
y="num"%10000;
x="num"%1000;
y="y-x";
y="y/1000";
z="y";
bcd_arr[6]=z;
y="num"%100000;
x="num"%10000;
y="y-x";
y="y/10000";
z="y";
bcd_arr[5]=z;
y="num"%1000000;
x="num"%100000;
y="y-x";
y="y/100000";
z="y";
bcd_arr[4]=z;
y="num"%10000000;
x="num"%1000000;
y="y-x";
y="y/1000000";
z="y";
bcd_arr[3]=z;
y="num"%100000000;
x="num"%10000000;
y="y-x";
y="y/10000000";
z="y";
bcd_arr[2]=z;
y="num"%1000000000;
x="num"%100000000;
y="y-x";
y="y/100000000";
z="y";
bcd_arr[1]=z;
if(num>1000000000){
bcd_arr[0]=1;
}else{
bcd_arr[0]=0;
}
}
unsigned long bcd_hex_long(void){
unsigned long x;
unsigned long y;
uchar i;
char j;
if(bcd_arr[0]>=4){
x= 4000000000;
}else{
x="0";
for(i=0;i<10;i++){
y="bcd"_arr[9-i];
for(j=0;j<i;j++){
y="y"*10;
}
x="x"+y;
}
}
return(x);
}
void float_bcd(float z){
char mi;
uchar mi_sin;
uchar shu_sin;
ulong y;
mi_sin=0;
mi="0";
if(z>=0){
bcd_arr[0]=0;
shu_sin=0;
}else{
bcd_arr[0]=bcd_arr[0]|0x01;
z="fabs"(z);
shu_sin=1;
}
if(z!=0){
mi="0";
if(z>1){
do{
z="z/10";
mi++;
}while(z>=1);
}else if((z>=0.1)&&(z<=1)){
}else if(z<0.1){
do{
z="z"*10;
mi--;
}while(z<=0.1);
}
z="z"*100000000;
y="z";
hex_bcd_long(y);
if(mi<0){
mi="-mi";
mi_sin=0x10;
}else{
mi_sin=0;
}
bcd_arr[0]=mi_sin|shu_sin;
bcd_arr[1]=mi;
}else{
hex_bcd_long(0);
bcd_arr[0]=0;
bcd_arr[1]=0;
}
}
float bcd_float(void){
float z;
ulong y;
char mi;
uchar mi_sin;
uchar shu_sin;
mi="bcd"_arr[1];
shu_sin=bcd_arr[0]&0x0f;
mi_sin=bcd_arr[0]&0xf0;
mi_sin=mi_sin>>4;
if(mi_sin!=0){
mi="-mi";
}
mi="mi-8";
bcd_arr[0]=0;
bcd_arr[1]=0;
y="bcd"_hex_long();
z="y";
if(mi>0){
if(mi!=0){
do{
z="z"*10;
mi--;
}while(mi!=0);
}
}else if(mi<0){
if(mi!=0){
do{
z="z/10";
mi++;
}while(mi!=0);
}
}
if(shu_sin!=0){
z="-z";
}
return(z);
}
void err_ys(void){
float k;
long z;
err=(((t_l_pulse*H_F_IN-t_h_pulse)/H_F_IN)*24*3600)*100(%)
=(8640000*(t_l_pulse*H_F_IN-t_h_pulse))/H_F_IN 百分误差
z="H"_F_IN;
z="z"*t_l_pulse;
z="z-t"_h_pulse;
k="8640000";
k="k/H"_F_IN;
k="k"*z;
error="k";
k="k"*100; //小数点后2位
error_long=k;
}
文章评论(0条评论)
登录后参与讨论