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

📄 ex3.bak

📁 工业控制,模拟量,数字量转化,采集数据,有模拟量,有数字量
💻 BAK
📖 第 1 页 / 共 2 页
字号:
#include "5510drv.h"
#include "adam5090.h"
#include "string.h"
#include "stdio.h"
#include "exchange.h"
#define INTR 0x0c

char cod_y,cod_m,cod_d,cod_h,cod_mi,cod_s,cod_state=0,flow_state=1,hz_cod;
char ph_v;
unsigned char cishu;
int timer_cod,timer_coddelay,timer_startcod,
	timer_flow,timer_flowdelay,timer_flowadd,timer_checktime,
	timer_outXA,timer_exa,timer_detmo,timer_sendstate;
unsigned int CanAskmo=0,CanStartcod=0,jgtime=0;
float cod_v,flow_v;
void sendstate(unsigned char *mobil,char bsf);
void sendcoddata(char bsf,char pk,char y,char m,char d,char h,char mi,char se,
		  int what,float value,float flow,char *mobil);


void init_all(void)
{
	char firstmo[30], secondmo[30],chls;
	unsigned int inls;
	com_install(1);
	com_set_format(8,0,1);
	com_set_speed((unsigned long)9600);
	cur_record(&chls,&inls,&cod_v,&flow_v,&cod_y,&cod_m,&cod_d,&cod_h,&cod_mi,&cod_s);
	/*com_pgm_install();
	com_pgm_set_format(8,0,1);
	com_pgm_set_speed((unsigned long)9600);*/
	LED_init();
	Timer_Init();
	timer_cod=Timer_Set(1000);
	timer_startcod=Timer_Set(60000);
	timer_flow=Timer_Set(1000);
	timer_flowadd=Timer_Set(10000);
	timer_coddelay=Timer_Set(60000);
	timer_flowdelay=Timer_Set(60000);
	timer_outXA=Timer_Set(30000);
	timer_exa=Timer_Set(3000);
	timer_detmo=Timer_Set(20000);
	timer_sendstate=Timer_Set(30000);
	flow_v=readdkflow();
	loadmobil(firstmo,0);
	loadmobil(secondmo,1);
	if (streql("",firstmo)) savemobil(" 13813815421",0);
	if (streql("",secondmo)) savemobil(" 13062547329",1);
	LED_OFF(PWR);
	WDT_enable();
}

char clearport(int portno)
{
char a;
if (portno==1) while (com_rx_ready()) a=com_rx();
else while (com_485_ready()) a=com_485_rx();
return a;
}

char dlc_t_si(char *string,int posit)
{
 unsigned char returnchar,*midpoint;
 unsigned char midstring[10];
 short midint;
 midpoint=string+posit;
 //printf("%s\n",midpoint);
 midstring[0]=*midpoint;
 midpoint++;
 midstring[1]=*midpoint;
 midstring[2]=0;
 //printf("int is %s\n",midstring);
 sscanf(midstring,"%d",&midint);
 returnchar=midint;
 return returnchar;
}

float dlc_t_f(char *string,int posit)
{
long returnlong;
float returnfloat;
unsigned char midstring[10],*midpoint;
midpoint=string+posit;
midstring[0]=*(midpoint+6);
midstring[1]=*(midpoint+7);
midstring[2]=*(midpoint+4);
midstring[3]=*(midpoint+5);
midstring[4]=*(midpoint+2);
midstring[5]=*(midpoint+3);
midstring[6]=*midpoint;
midstring[7]=*(midpoint+1);
midstring[8]=0;
//printf("cod value is %s\n",midstring);
sscanf(midstring,"%ld\n",&returnlong);
returnfloat=returnlong;
return returnfloat;
}

void ask_codv(void)
{
	unsigned char portin[100];
	int portlen=0;
	//old data
	unsigned char pk,y,m,d,h,mi,s;unsigned int what;float value,flow;
	clearport(2);
	com_485_tx_string("%01#RDD0152101525**\x0d");
	ADAMdelay(100);
	while (com_485_rx_ready(11))
	{
	 portin[portlen++]=com_485_rx(11);
	 portin[portlen]=0;
	}
	//printf("%s\n",portin);
	if ((portin[3]=='$') && (portlen==29) && (portin[28]==13))
	{
	 cod_y=dlc_t_si(portin,16);
	 cod_m=dlc_t_si(portin,14);
	 cod_d=dlc_t_si(portin,12);
	 cod_h=dlc_t_si(portin,10);
	 cod_mi=dlc_t_si(portin,8);
	 cod_s=dlc_t_si(portin,6);
	 cod_v=dlc_t_f(portin,18);
	 //printf("%d %d %d %d %d %d %f\n",cod_y,cod_m,cod_d,cod_h,cod_mi,cod_s,cod_v);
	}
	 cur_record(&pk,&what,&value,&flow,&y,&m,&d,&h,&mi,&s);
	 if ((cod_y==y) && (cod_m==m) && (cod_d==d) && (cod_h==h) && (cod_mi==mi) && (cod_s==s)) printf("no new data\n");
	 else
	 {
	 flow=readkeepflow();
	 writekeepflow(0);
	 record_add(1,316,cod_v,flow,cod_y,cod_m,cod_d,cod_h,cod_mi,cod_s);
	 if (cishu);
	 }
	 Timer_Reset(timer_coddelay);
}

void ask_codstate(void)
{
	char portin[100],*midpoint;
	int portlen=0;
	clearport(2);
	com_485_tx_string("%01#RDD0016000160**\x0d");
	ADAMdelay(100);
	while (com_485_rx_ready())
	{
	 portin[portlen++]=com_485_rx();
	 portin[portlen]=0;
	}
	//printf("%s\n",portin);
	if ((portin[3]=='$') && (portlen==13) && (portin[12]==13))
	{
	 cod_state=dlc_t_si(portin,6)+dlc_t_si(portin,8);
	 //printf("state is %d\n",cod_state);
	 Timer_Reset(timer_coddelay);
	}
	if ((CanStartcod) && (cod_state!=0)) CanStartcod=0;
}

void ask_codtime(void)
{
/*	char portin[100],*midpoint,midbytechar[20];
	int portlen=0;
	char se,mi,h,d,m,y;
	port_select(11);
	port_enable_fifo(11);
	clearport(11);
	port_tx_string(11,"%01#RDD9005490056**\x0d");
	ADAMdelay(100);
	while (port_rx_ready(11))
	{
	 portin[portlen++]=port_rx(11);
	 portin[portlen]=0;
	}
	printf("%s\n",portin);
	if ((portin[3]=='$') && (portlen==21) && (portin[20]==13))
	{
	 Timer_Reset(timer_coddelay);
	 printf("time first check passed!,y%d m%d d%d\n",dlc_t_si(portin,16),dlc_t_si(portin,14),dlc_t_si(portin,12));
	 if ((GetRTCtime(RTC_year)==dlc_t_si(portin,16)) &&
		   (GetRTCtime(RTC_month)==dlc_t_si(portin,14)) &&
		   (GetRTCtime(RTC_day)==dlc_t_si(portin,12)) &&
		   (GetRTCtime(RTC_hour)==dlc_t_si(portin,10)) &&
		   (GetRTCtime(RTC_min)==dlc_t_si(portin,8)) &&
		   (GetRTCtime(RTC_sec)==dlc_t_si(portin,6)));
	 else
	 {
		printf("begin change time\n");
		port_tx_string(11,"%01#WDD9005490056");
		//printf("%d %d %d\n",GetRTCtime(RTC_sec),GetRTCtime(RTC_min),GetRTCtime(RTC_hour));
		se=GetRTCtime(RTC_sec);
		mi=GetRTCtime(RTC_min);
		h=GetRTCtime(RTC_hour);
		printf("%2d:%2d:%2d",se,mi,h);
		/*if (GetRTCtime(RTC_sec)<16)  sprintf(midbytechar,"0%d",GetRTCtime(RTC_sec));
		else sprintf(midbytechar,"%d",GetRTCtime(RTC_sec));
		printf("%s ",midbytechar);
		port_tx_string(11,midbytechar);
		if (GetRTCtime(RTC_min)<16)  sprintf(midbytechar,"0%d",GetRTCtime(RTC_min));
		else sprintf(midbytechar,"%d",GetRTCtime(RTC_min));
		printf("%s ",midbytechar);
		port_tx_string(11,midbytechar);
		if (GetRTCtime(RTC_hour)<16)  sprintf(midbytechar,"0%d",GetRTCtime(RTC_hour));
		else sprintf(midbytechar,"%d",GetRTCtime(RTC_hour));
		printf("%s ",midbytechar);
		port_tx_string(11,midbytechar);
		if (GetRTCtime(RTC_day)<16)  sprintf(midbytechar,"0%d",GetRTCtime(RTC_day));
		else sprintf(midbytechar,"%d",GetRTCtime(RTC_day));
		printf("%s ",midbytechar);
		port_tx_string(11,midbytechar);
		if (GetRTCtime(RTC_month)<16)  sprintf(midbytechar,"0%d",GetRTCtime(RTC_month));
		else sprintf(midbytechar,"%d",GetRTCtime(RTC_month));
		printf("%s ",midbytechar);
		port_tx_string(11,midbytechar);
		if (GetRTCtime(RTC_year)<16)  sprintf(midbytechar,"0%d",GetRTCtime(RTC_year));
		else sprintf(midbytechar,"%d",GetRTCtime(RTC_year));
		printf("%s \n",midbytechar);*/
		/*Uport_tx_string(11,midbytechar);
		port_tx_string(11,"00**\x0d");
	 }
   }
*/
}

void ask_flow(void)
{
   char ch[500];
   int len=0;
   clearport(2);
   com_485_tx_string("%01#RDD0152701527**\x0d");
   ADAMdelay(100);
   WDT_clear();
   while (com_485_rx_ready())
	{
	 ch[len++]=com_485_rx();
	 ch[len]=0;
	}
	printf("%s\n",ch);
	if ((ch[3]=='$') && (len==13) && (ch[12]==13))
	{
	flow_v=((dlc_t_si(ch,8)*10.0)+(dlc_t_si(ch,6)*0.1));
	writedkflow(flow_v);
	flow_state=1;
	LED_ON(COMM);
	Timer_Reset(timer_flowdelay);
	}
	else LED_OFF(COMM);
	clearport(2);
	com_485_tx_string("%01#RDD0152601526**\x0d");
	len=0;
	ADAMdelay(100);
	WDT_clear();
	while (com_485_rx_ready())
	{
	 ch[len++]=com_485_rx();
	 ch[len]=0;
	}
	printf("%s\n",ch);
	if ((ch[3]=='$') && (len==13) && (ch[12]==13))
	{
	ph_v=dlc_t_si(ch,6);
	LED_ON(COMM);
	Timer_Reset(timer_flowdelay);
	}
	else LED_OFF(COMM);
}

void chzhouqi(char *zhouqi)
{
   char *jj, lschar[10],hourchar[10];
   int ty;
   jj=zhouqi;
   jj++;
   ty=c_t_i(jj);
   sprintf(lschar,"%d",ty);
   if (lschar[4]==0)
   {
	  hourchar[0]=lschar[2];
	  hourchar[1]=lschar[3];
	  hourchar[2]=lschar[0];
	  hourchar[3]=lschar[1];
   }
   if (lschar[3]==0)
   {
	hourchar[0]=lschar[1];
	hourchar[1]=lschar[2];
	hourchar[2]=0x30;
	hourchar[3]=lschar[0];
   }
   if (lschar[2]==0)
   {
	hourchar[0]=lschar[0];
	hourchar[1]=lschar[1];
	hourchar[2]=0x30;
	hourchar[3]=0x30;
   }
   if (lschar[1]==0)
   {
	 hourchar[0]=0x30;
	 hourchar[1]=lschar[0];
	 hourchar[2]=0x30 ;
	 hourchar[3]=0x30;
   }
   hourchar[4]=0;
   printf("send string is %s\n",hourchar);
   WDT_clear();
   ADAMdelay(100);
   com_485_tx_string("%01#WDD0093900939");
   com_485_tx_string(hourchar);
   com_485_tx_string("**\x0d");
   WDT_clear();
   ADAMdelay(100);
   com_485_tx_string("%01#WDD0093900939");
   com_485_tx_string(hourchar);
   com_485_tx_string("**\x0d");
   WDT_clear();
   ADAMdelay(100);
   com_485_tx_string("%01#WDD0093900939");
   com_485_tx_string(hourchar);
   com_485_tx_string("**\x0d");
   WDT_clear();
}

void get_msg(void)
{
   char data[100],mobil[20],firstmo[20],secondmo[20];
   char com1in[360],checkchar[360];
   unsigned char pk,y,m,d,h,mi,s;
   float value,flow;
   unsigned int what;
   int i=0,len;
   static char msgno=0;
   char *charread,*charjll,*charok,*getchar,*getzhouqi;
   char firsts[10],seconds[10],msgnochar[10];
   msgno=(msgno+1)%30;
   strcpy(com1in,"");
   len=0;
   WDT_clear();
   strcpy(com1in,"");
   len=0;
   ADAMdelay(100);
   clearport(1);
   com_tx_string("at+cmgr=");
   sprintf(msgnochar,"%d",msgno);
   com_tx_string(msgnochar);

⌨️ 快捷键说明

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