?? bb.c
字號:
#include <stdio.h>
#include <stdlib.h>
#include <5510drv.h>
#include <string.h>
#include <conio.h>
#include <dos.h>
typedef unsigned int word;
typedef unsigned long dword;
word wBaseAddr;
#define uchar unsigned char
#define uint unsigned int
#define false 0
#define true 1
#define SIZE 300
//-----------------------------------------------------------
uchar SMCCode[23]={"AT+CSCA=+8613800931500"};
//-----------------------------------------------------------------------------
uint num=0;
uint oldzdzdate[3][5],oldzxzdate[3][5];
//------------------------------------------------------------------------------------------------------------------------
void getdata(uint *outdata,uchar *indata)
{
char i,j,m,n;
int Slot5017=0,ch[8]={0,1,2,3,4,5,6,7};
uint t,str[3][20],aiv,zpianca,y,z;
dword x=0;
uchar pian[5];
//adv_printf(" cai ji kai shi\n");
for(i=0;i<20;i++)
{
//adv_printf(" di %d lun cai ji\n",i+1);
for(j=0;j<3;j++) /*讀5017數據*/
{
WDT_clear();
while(AiUpdate(Slot5017,&ch[j])!=0);
//adv_printf("de dao yi lu shu ju\n");
Get501718(Slot5017,ch[j],&aiv);
str[j][i]=aiv;
//ADAMdelay(200);
}
}
//adv_printf(" cai ji wan bi\n");
for(j=0;j<3;j++)
{
for(i=0;i<19;i++)
{
m=i;
n=1;
WDT_clear();
while(m>=0&&n)
{ if(str[j][m]>str[j][m+1]) /*數據處理*/
{
t=str[j][m];str[j][m]=str[j][m+1];str[j][m+1]=t;
}
else
n=0;m=m-1;
}
}
}
//adv_printf(" shu ju pai xu\n");
for(j=0;j<3;j++)
{ WDT_clear();
for(i=2;i<18;i++)
x=x+str[j][i];
y=x/16;
x=0;
if(y<4050) /*pan duan shi fou jie chuan gan qi*/
z=0;
else
{ WDT_clear();
if(y>4050)
{
strcpy(pian,indata);
zpianca=(pian[0]-48)*1000+(pian[1]-48)*100+(pian[2]-48)*10+(pian[3]-48);
ADAMdelay(5);
z=(5000*(y-4000))/16000+zpianca;
ADAMdelay(5);
}
}
outdata[j]=z/10;
//adv_printf("%d\n",outdata[j]);
}
}
//-----------------------------------------------------------------------------------------------------------------
void GetSysTime(uint *outdata)
{
outdata[0]=2000+GetRTCtime(RTC_year); /*du qu xi tong shi jian*/
outdata[1]=GetRTCtime(RTC_month);
outdata[2]=GetRTCtime(RTC_day);
outdata[3]=GetRTCtime(RTC_hour);
outdata[4]=GetRTCtime(RTC_min);
}
//-----------------------------------------------------------------------------------------------------------------------
void dabao(uint *para1,uint *para2,uint *para3,uint *para4,uint outdata[4][14])//para1:dang qian zhi,para2:jiu ping ju zhi,para3,jiu zui da zhi,para4:jiu zui xiao zhi
{
int i,j,b;
uint pjz,zdz,zxz,zdzdate[5],zxzdate[5];
uchar ppc[4],ttm[4];
dword CRC_value;
char string[100],temp;
for(i=0;i<4;i++)
{
if(i==0)
{
outdata[0][0]=3;//站號值
for(b=5;b<10;b++)
ppc[b-5]=Get_SysMem(b);//從系統內存中取出偏差值
outdata[0][1]=((ppc[0]-48)*1000+(ppc[1]-48)*100+(ppc[2]-48)*10+(ppc[3]-48)-1)/10;
for(b=10;b<15;b++)
ttm[b-10]=Get_SysMem(b);//從系統內存中取出時間值
outdata[0][2]=(ttm[0]-48)*1000+(ttm[1]-48)*100+(ttm[2]-48)*10+(ttm[3]-48)-1;
outdata[0][3]=0;
outdata[0][4]=0;
outdata[0][5]=0;
outdata[0][6]=0;
outdata[0][7]=0;
outdata[0][8]=0;
outdata[0][9]=0;
outdata[0][10]=0;
outdata[0][11]=0;
outdata[0][12]=0;
outdata[0][13]=0;
}
else
{
pjz=(para2[i-1]*num+para1[i-1])/(num+1);
para2[i-1]=pjz;
// adv_printf("cai ji le %dci,ping jun zhi:%d\n",num,pjz);
zdzdate[0]=oldzdzdate[i-1][0];
zdzdate[1]=oldzdzdate[i-1][1];
zdzdate[2]=oldzdzdate[i-1][2];
zdzdate[3]=oldzdzdate[i-1][3];
zdzdate[4]=oldzdzdate[i-1][4];
zdz=para3[i-1];
if(para1[i-1]>para3[i-1])
{
GetSysTime(zdzdate);
zdz=para1[i-1];
para3[i-1]=zdz;
}
//adv_printf("zui da zhi:%d\n",zdz);
zxzdate[0]=oldzxzdate[i-1][0];
zxzdate[1]=oldzxzdate[i-1][1];
zxzdate[2]=oldzxzdate[i-1][2];
zxzdate[3]=oldzxzdate[i-1][3];
zxzdate[4]=oldzxzdate[i-1][4];
zxz=para4[i-1];
if(para1[i-1]<para4[i-1])
{
GetSysTime(zxzdate);
zxz=para1[i-1];
para4[i-1]=zxz;
}
//adv_printf("zui xiao zhi:%d\n",zxz);
outdata[i][0]=para1[i-1];
outdata[i][1]=pjz;
outdata[i][2]=zdz;
outdata[i][3]=zdzdate[0];
outdata[i][4]=zdzdate[1];
outdata[i][5]=zdzdate[2];
outdata[i][6]=zdzdate[3];
outdata[i][7]=zdzdate[4];
outdata[i][8]=zxz;
outdata[i][9]=zxzdate[0];
outdata[i][10]=zxzdate[1];
outdata[i][11]=zxzdate[2];
outdata[i][12]=zxzdate[3];
outdata[i][13]=zxzdate[4];
}
//adv_printf("danqianzhi:%d,pingjunzhi:%d,zuidazhi:%d,%d %d %d %d:%d,zuixiaozhi:%d,%d %d %d %d:%d\n",outdata[i][0],outdata[i][1],outdata[i][2],outdata[i][3],outdata[i][4],outdata[i][5],outdata[i][6],outdata[i][7],outdata[i][8],outdata[i][9],outdata[i][10],outdata[i][11],outdata[i][12],outdata[i][13]);
}
//adv_printf("da bao cheng gong\n");
num++;
if(num==30000)
{
num=0;
}
}
//--------------------------------------------------------------------------------------------
int check(char *buf)
{
long i;
int index;
unsigned char c;
index=0;
for(i=0;i<50;i++)
{
ADAMdelay(1);
if(com_485_rx_empty()==0)
{
while(com_485_rx_empty()==0)
{
c=com_485_rx();
buf[index++]=c;
}
return(1);
}
}
return(0);
}
//------------------------------------------------------------------------------------------
void send(uint indata[4][14])
{
int i,j,flag,cishu;
uchar string[100],temp,MD204[100];
uint CRC_value;
for(i=0;i<4;i++)
{
//adv_printf("fa song di %d tiao!!!\n",i+1);
temp=95+16*i;
CRC_value=temp;
string[0]=0x01;
string[1]=0x57;
string[2]=16*i;
string[3]=0x07;
for(j=0;j<7;j++)
{
WDT_clear();
temp=indata[i][j]/256;
string[4+j*2]=temp;
CRC_value=CRC_value+temp;
temp=indata[i][j]%256;
string[5+j*2]=temp;
CRC_value=CRC_value+temp;
//adv_printf("%d\n",j);
}
temp=CRC_value%256;
string[18]=temp;
flag=1;cishu=0;
while(flag==1)
{ com_485_flush_tx();
com_485_flush_rx();
for(j=0;j<19;j++)
{
com_485_tx(string[j]);ADAMdelay(2);
}
if(check(MD204)==1)
{
if(MD204[1]==0)
flag=0;
}
cishu++;
//adv_printf("fa song le %d ci",cishu);
if(cishu==10)
{flag=0;}
}
temp=102+16*i;
CRC_value=temp;
string[0]=0x01;
string[1]=0x57;
string[2]=16*i+7;
string[3]=0x07;
for(j=0;j<7;j++)
{
WDT_clear();
temp=indata[i][j+7]/256;
string[4+j*2]=temp;
CRC_value=CRC_value+temp;
temp=indata[i][j+7]%256;
string[5+j*2]=temp;
CRC_value=CRC_value+temp;
//adv_printf("%d\n",j);
}
temp=CRC_value%256;
string[18]=temp;
flag=1;
cishu=0;
while(flag==1)
{
com_485_flush_tx();
com_485_flush_rx();
for(j=0;j<19;j++)
{
com_485_tx(string[j]);ADAMdelay(2);
}
if(check(MD204)==1)
{
if(MD204[1]==0)
flag=0;
}
cishu++;
//adv_printf("fa song le %d ci",cishu);
if(cishu==10)
{flag=0;}
}
}
}
//========================================================================================================================
void heb(uchar *buf0,uchar *buf)
{ uchar year,month,day,hour,min;
uchar yearbuf[80],monthbuf[2],daybuf[2],hourbuf[2],minbuf[2];
uchar fxg[2]="/",mh[2]=":",kg[2]=" ";
uchar yearb[4],monthb[2],dayb[2],hourb[2],minb[2],zero[10]="0",f1y[10];
uchar fy[4]="200",fy1[3]="20",fm[2],fd[2],fh[2],fmin[2];
uchar ad[100],Bdata1,Bdata2;
uchar Bdata;
uchar AD[90]={"AD0003"};
WDT_clear();
year=GetRTCtime(RTC_year); /*du qu xi tong shi jian*/
month=GetRTCtime(RTC_month);
day=GetRTCtime(RTC_day);
hour=GetRTCtime(RTC_hour);
min=GetRTCtime(RTC_min);
adv_printf("200%d/%d/%d/%d:%d",year,month,day,hour,min);
sprintf(yearb,"%d",year); /*zhuan hua wei zi fu chuan*/
WDT_clear();
if(strlen(yearb)==1)
{WDT_clear();
strcpy(f1y,fy);
strcat(f1y,yearb);
strcpy(yearb,0);
strcpy(yearbuf,f1y);
strcpy(f1y,0);
}
else
{
WDT_clear();
strcpy(f1y,fy1);
strcat(f1y,yearb);
strcpy(yearb,0);
strcpy(yearbuf,f1y);
strcpy(f1y,0);
}
sprintf(monthb,"%d",month);
if(strlen(monthb)==1)
{
WDT_clear();
strcpy(fm,zero);
strcat(fm,monthb);
strcpy(monthb,0);
strcpy(monthbuf,fm);
strcpy(fm,0);
}
else
{
WDT_clear();
strcpy(monthbuf,monthb);
strcpy(monthb,0);
}
WDT_clear();
strcat(yearbuf,fxg);
strcat(yearbuf,monthbuf);
strcpy(monthbuf,0);
sprintf(dayb,"%d",day);
if(strlen(dayb)==1)
{WDT_clear();
strcpy(fd,zero);
strcat(fd,dayb);
strcpy(dayb,0);
strcpy(daybuf,fd);
strcpy(fd,0);
}
else
{WDT_clear();
strcpy(daybuf,dayb);
strcpy(dayb,0);
}
WDT_clear();
strcat(yearbuf,fxg);
strcat(yearbuf,daybuf);
strcpy(daybuf,0);
sprintf(hourb,"%d",hour);
if(strlen(hourb)==1)
{strcpy(fh,zero);
strcat(fh,hourb);
strcpy(hourb,0);
strcpy(hourbuf,fh);
strcpy(fh,0);
WDT_clear();
}
else
{strcpy(hourbuf,hourb);
strcpy(hourb,0);
}
WDT_clear();
strcat(yearbuf,kg);
strcat(yearbuf,hourbuf);
strcpy(hourbuf,0);
sprintf(minb,"%d",min);
if(strlen(minb)==1)
{strcpy(fmin,zero);
strcat(fmin,minb);
strcpy(minb,0);
strcpy(minbuf,fmin);
strcpy(fmin,0);
WDT_clear();
}
else
{ strcpy(minbuf,minb);
strcpy(minb,0);
}
WDT_clear();
strcat(yearbuf,mh);
strcat(yearbuf,minbuf);
strcpy(minbuf,0);
strcpy(ad,AD);
strcat(ad,kg);
strcat(ad,yearbuf);
strcpy(yearbuf,0);
strcat(ad,kg);
strcat(ad,buf0);
strcpy(buf,ad);
strcpy(ad,0);
adv_printf("\n%s\n",buf);
WDT_clear();
}
void shuju(uchar *buf,uchar *pca)
{ uchar buf0[68]={'\0'},buf1[6],buf2[5],jw[8]={'A','B','C','D','E','F','G','H'};
int i,j,m,n,t,aiv,Slot5017=0,ch[8]={0,1,2,3,4,5,6,7};
uchar kg[2]=" ";
int str[8][20];
long x=0,z,shu[8],y;
unsigned long vv=0,l,uu;
uchar s[5],s1[4]="000",s2[3]="00",s3[2]="0",buf22[5]="0";
uchar sss[5],mm[5]={'\0'},mmm[5],dmm[5],buff22[5]="0",s4[5]="0000";
uchar jldz[2],xdcz[2],cgqz[2];
uchar ad[100],Bdata1,Bdata2;
uchar Bdata,buff[120];
uchar z0[2]="0",z1[2]="1";
uchar pian[5];
int zpianca,b;
for(i=0;i<20;i++)
{
for(j=0;j<8;j++) /*du 5017 shu ju*/
{
WDT_clear();
while(AiUpdate(Slot5017,&ch[j])!=0);
Get501718(Slot5017,ch[j],&aiv);
str[j][i]=aiv;
ADAMdelay(50);
Bdata=1;
Set5050(&Bdata,1,3,ABit);
WDT_clear();
ADAMdelay(50); /*yan chi 100ms*/
Bdata=0;
Set5050(&Bdata,1,3,ABit);
}
}
for(j=0;j<8;j++)
{ for(i=0;i<19;i++)
{ m=i;
n=1;
WDT_clear();
while(m>=0&&n)
{ if(str[j][m]>str[j][m+1]) /*shu ju chu li*/
{t=str[j][m];str[j][m]=str[j][m+1];str[j][m+1]=t;
}
else
n=0;m=m-1;
}
}
}
for(j=0;j<8;j++)
{ WDT_clear();
for(i=2;i<18;i++)
x=x+str[j][i];
y=x/16;
x=0;
if(y<3999) /*pan duan shi fou jie chuan gan qi*/
z=0;
else
{ if(y>3999)
{WDT_clear();
strcpy(pian,pca);
zpianca=(pian[0]-48)*1000+(pian[1]-48)*100+(pian[2]-48)*10+(pian[3]-48);
z=(5000*(y-4000))/16000+zpianca;
ADAMdelay(10);
}
}
shu[j]=z; /*de dao suo xu shu ju*/
ADAMdelay(15);
sprintf(buf22,"%d",shu[j]);
WDT_clear();
if(strlen(buf22)==1)
{ WDT_clear();
strcpy(s,s1);
strcat(s,buf22);
strcpy(buf2,s);
strcpy(s,0);
}
else
{if(strlen(buf22)==2)
{ WDT_clear();
strcpy(s,s2);
strcat(s,buf22);
strcpy(buf2,s);
strcpy(s,0);
}
else
{if(strlen(buf22)==3)
{WDT_clear();
strcpy(s,s3);
strcat(s,buf22);
strcpy(buf2,s);
strcpy(s,0);
}
else
{strcpy(buf2,buf22);
}
}
}
WDT_clear();
sprintf(buf1,"%c",jw[j]);
strcat(buf1,buf2);
strcpy(buf2,0);
strcat(buf0,buf1);
strcpy(buf1,0);
adv_printf("%s\n",buf0);
}
if(shu[0]==0||shu[1]==0||shu[2]==0)
{strcpy(cgqz,z1);
}
else
{strcpy(cgqz,z0);
}
WDT_clear();
Get5050(1,1,ABit,&Bdata1); /*pan duan jiao liu dian shi fou zheng chang*/
Get5050(1,2,ABit,&Bdata2); /*pan duan xu dian chi shi fou you dian*/
if(Bdata1==1)
{WDT_clear();
if(Bdata2==1)
{strcpy(jldz,z0);
strcpy(xdcz,z1);
}
else
{strcpy(jldz,z0);
strcpy(xdcz,z0);
}
}
else
{WDT_clear();
if(Bdata2==1)
{strcpy(jldz,z1);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -