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

📄 main.c

📁 集中数据采集系统中
💻 C
📖 第 1 页 / 共 5 页
字号:
//************************************************************************
//file   : main.c
//author : luogx_qianhui
//time   : 2004/07/30	
//************************************************************************

/* includes */
#include "..\inc\option.h"
#include "..\inc\def.h"
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\structs.h"

/* functions */
void (*restart)(void)=(void (*)(void))0x0;
void PrintBanner_main(void) ;
void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);      
void HaltDabort(void);
void Uart0_RxInt_boot(void);
/* globals */
volatile  unsigned short int err=0;
volatile unsigned char *downPt;
volatile unsigned char conf_run;

void Uart0_RxInt_boot(void)
{
    rI_ISPC=BIT_URXD0 ;   //clear uart0 receive pending bits,Default value=0x0000000
    *downPt++=RdURXH0();
}

void HaltUndef(void)
{
    Uart_Printf("Undefined instruction exception!!!\n");
    while(1);
}
void HaltSwi(void)
{
    Uart_Printf("SWI exception!!!\n");
    while(1);
}

void HaltPabort(void)
{
    Uart_Printf("Pabort exception!!!\n");
    while(1);
}

void HaltDabort(void)
{
    Uart_Printf("Dabort exception!!!\n");
    while(1);
}

/* includes */
#include "..\inc\44b.h"    //
#include "..\inc\option.h" //
#include "..\inc\def.h"    //
#include "..\inc\44blib.h" //针对44b0开发板
#include "..\inc\isr.h"    //
#include "..\inc\structs.h"
#include <STRING.H>

/* functions */
void Isr_Init(void);
void initsys(void);
void in8250_2(void);

/* globals */
//test add
U8 led=0xff;
U8 ledcon;
//test add
U8 h_time,d_time;
U8 datak_ok;
U8 zb5_i;
U8 datrxd;
U8 carr_svr_name[2]={0x40,0x05};//集中器编号
U8 carr_svr_ver[7]={'V','E','R','1','.','0','5'};
U8 r_old;
U8 miyao[5];
U8 mima[9];
U8 led_data;
U32 ystxd,ysrxd, yszb;
U8 r_day,r_hour,r_int;
U8 loop_l; 
U8 loop_l_up; 
U8 loop_z;
U8 c_zbpo;
U8 ipo;
U8 minx;
U8 time_x,time_y;
U16 c_zb;               	// 电表抄表计数
U16 c_zb1,c_zb2,c_zb3,c_zb4;
U16 meter_num;
U8 led;

typedef struct
{	U8 i,j,c,d,a,x;
 	U16  uc6;
    U16  uc7;
	U32  lc0;
	U32  lc1;     } hhint;
hhint *p;

U8 rd_82502(void)
{
	U8 ch;
	ysrxd=100;
  	while((rUTRSTAT1 & 0x01) != 0x01)
  	{
  		if(ysrxd==0)
  			{datrxd=0;return;} 
  	}
  	datrxd=1; 
  	ch = rURXH1;
	return(ch);  	
}

U8 wr_82502(U8 data)
{
	ystxd = 100;
 	while(!(rUTRSTAT1 & 0x2))
 	{ if(ystxd==0) return(0); } //Wait until THR is empty.
 	
	WrUTXH1(data); //发送数据	

	ystxd = 100;
 	while(!(rUTRSTAT1 & 0x2))
 	{ if(ystxd==0) return(0); } //Wait until THR is empty.
 	
	return(1);//ok
}

void write_dallas(U8 rtc_add,U8 ch)   // 时钟芯片
{
    rRTCCON = 0x01;	// R/W enable, 1/32768, Normal(merge), No reset
    switch(rtc_add)
    {
    	case 0x80: rBCDSEC =ch; break;
    	case 0x82: rBCDMIN =ch; break;
    	case 0x84: rBCDHOUR=ch; break;
    	case 0x86: rBCDDAY =ch; break;
    	case 0x88: rBCDMON =ch; break;
    	case 0x8a: rBCDDATE=ch; break;
    	case 0x8c: rBCDYEAR=ch; break;
    	default  : break;
    }  	
    rRTCCON = 0x00;	
}

void txdbyte(U8 dachar)
{
    ystxd=10;                   //设定500毫秒计时器 	
    while(!(rUTRSTAT0 & 0x2))	//等待上一步发送结束
    { if(ystxd==0) return; }	
    
    WrUTXH0(dachar);			//发送数据
    
    ystxd=10;                   //设定500毫秒计时器 	
    while(!(rUTRSTAT0 & 0x2))	//等待发送结束
  	{ if(ystxd==0) return; }	
}

void ledstm(U8 ledat)
{
    *((U8*)0xa000000) = ledat & 0x0f ; 	//qh led 
}

void ys(U8 yx)
{
	//uchar data i,j,h;
  	U8 i,j,h;
  	for (h=0;h<yx;h++)
	{
    	for (i=0;i<0xff;i++)
     		for(j=0;j<0xff;j++);
   	//qwe
   	//	P1=0xf4;P1=0xff;
	}
}

uchar get_sno(unsigned char *snp)
{
//	DAT_ITEM xdata *dat_ptr1;
	DAT_ITEM *dat_ptr1;
// 	uint data c1,dat_len;
    U16 c1,dat_len;
    
// 	jzq_ptr=(JZQ_HEAD xdata *)JZQ_ADD;
//	dat_ptr1=(DAT_ITEM xdata *)(JZQ_ADD+DAT_ADD);
 	jzq_ptr  = (JZQ_HEAD *)JZQ_ADD;
	dat_ptr1 = (DAT_ITEM *)(JZQ_ADD+DAT_ADD);


//y	P1=0xf1;                              /*  SIO=1; ram_page=0;  */

  	dat_len=jzq_ptr->meter_num;    // 集中器总表数
//	if(dat_len<448)
  	if(dat_len<1342)//qh yzhi
	{
		for(c1=1;c1<=dat_len;c1++)
		{
			ysrxd=40;
	 		//////////////////////////............. 比较地址(表号)是否相等
	   		if(dat_ptr1->s_no[0]==snp[0] && dat_ptr1->s_no[1]==snp[1]&&dat_ptr1->s_no[2]==snp[2]) //=====
	      	{
//y	      		P1=0xf1;
	      		return(c1);
	      	}
	   			dat_ptr1++;
	   			//qwe
		}
	}
// 	P1=0xf1;                              /*  SIO=1; ram_page=1;  */
 	c1=0;                                 // 为 0 时 不在数据库中
  	return(c1);
}

void zbdatpc(uchar ys)
{
	U8 i,j,t,w,sp1;
  	yszb=ys;
  	i=0;
  	j=0;
  	buf_ptr  = (HBUF *)BUF_ADD;
	while (yszb)
	{
		w=rd_82502();
	   	if(w=='D')
		{
			datrxd=0;
	       	buf_ptr->buf0[0]=w; break;
		}
	   	datrxd=0;
//	   	sp1=P1;P1=0xf4;P1=sp1;  // 清狗
		//qwe
		if(yszb==0) break;
	}
	j=1;
	if(w=='D')
	{
		yszb=20;
	   	while(yszb)
	    {
			w=rd_82502();
	      	if(datrxd==1)
			{
				datrxd=0;
		  		buf_ptr->buf0[j]=w;j++;
		  		if(j==4)t=buf_ptr->buf0[3];
		  		if(j>4)
		    	{
					t--;
		      		if(t==0){return;}  // 设置显示状态
		    	}
	       	}
			if(yszb==0)break;
		}
	}
}

U16 comp(U16 c_zbxx)
{
  	return(c_zbxx);
}

void fsnd(void)
{
	U8 i;
  	for(i=0;i<3;i++) if (wr_82502(0xff)) break ;
  	for(i=0;i<3;i++) if (wr_82502('S')) break ;
  	for(i=0;i<3;i++) if (wr_82502('N')) break ;
  	for(i=0;i<3;i++) if (wr_82502('D')) break ;
}

U8 PLM_snd_rcv1()
{
	U8 a012[15];
	U8 ac[20];
	U8 a123[3];
    U16 see;
	U16 c;
    unsigned char i,j,bb,h,tt,t2;
//  	if(int2==0)
//    {
		yszb=8;
      	while(1)
        {
			if(yszb==0) break;
//          	P1=0xf4;P1=0xff;
		//qwe
		}
  	dat_ptr=(DAT_ITEM *)JZQ_ADD;				// 电表数据库地址
//   	buf_ptr=(HBUF xdata *)BUF_ADD;					// 接收、发送缓存区 起始地址
   	buf_ptr=(HBUF *)BUF_ADD;					// 接收、发送缓存区 起始地址
  
   	j=0;
  	tt = buf_ptr->buf0[0];
	t2 = buf_ptr->buf0[15];
	h  = buf_ptr->buf0[15];
  	a123[0] = buf_ptr->buf0[11];
	a123[1] = buf_ptr->buf0[12];
	a123[2] = buf_ptr->buf0[13];
  	a012[9] = buf_ptr->buf0[11];
	a012[10]= buf_ptr->buf0[12];
	a012[11]= buf_ptr->buf0[13];  // 存目的电表地址
  	a012[12]= buf_ptr->buf0[18];
	a012[13]= buf_ptr->buf0[19];
	a012[14]= buf_ptr->buf0[20];  // 存集中器地址
  	c=get_sno(&buf_ptr->buf0[11]);
  	if(c==0) goto PLMEND;
//  	c=comp1(c);
//  	dat_ptr=(DAT_ITEM xdata *)JZQ_ADD;
	dat_ptr=(DAT_ITEM *)JZQ_ADD;
   	if(dat_ptr[c].s_xh)
    {
		j++;
      	c=dat_ptr[c].s_xh;
//     	c=comp1(c);
      	buf_ptr->buf0[11]=dat_ptr[c].s_no[0];
      	a012[6]=buf_ptr->buf0[11];  // 一级中继 00
      	buf_ptr->buf0[12]=dat_ptr[c].s_no[1];
      	a012[7]=buf_ptr->buf0[12];
      	buf_ptr->buf0[13]=dat_ptr[c].s_no[2];
      	a012[8]=buf_ptr->buf0[13];
      	buf_ptr->buf0[14]=(buf_ptr->buf0[14]&0x0f)+0x40;
	}
    else {buf_ptr->buf0[14]=buf_ptr->buf0[14]&0x0f;goto cqq; }  		// 变成无中继
  	c=get_sno(&buf_ptr->buf0[11]);//P1=0xf1;
//  	c=comp1(c);
  	if(dat_ptr[c].s_xh)
    {
		j++;
      	c=dat_ptr[c].s_xh;
//      	c=comp1(c);
      	buf_ptr->buf0[11]=dat_ptr[c].s_no[0];a012[3]=buf_ptr->buf0[11];  // 二级中继   01
      	buf_ptr->buf0[12]=dat_ptr[c].s_no[1];a012[4]=buf_ptr->buf0[12];
      	buf_ptr->buf0[13]=dat_ptr[c].s_no[2];a012[5]=buf_ptr->buf0[13];
      	buf_ptr->buf0[14]=(buf_ptr->buf0[14]&0x0f)+0x50;
    }
    else { buf_ptr->buf0[14]=(buf_ptr->buf0[14] &0x0f)+0x40; goto DZZZ; }   // 变成一级中继
  	c=get_sno(&buf_ptr->buf0[11]);  //P1=0xf1;
//  	c=comp1(c);
  	if(dat_ptr[c].s_xh)
    {
		j++;
      	c=dat_ptr[c].s_xh;
//      	c=comp1(c);
      	buf_ptr->buf0[11]=dat_ptr[c].s_no[0];    a012[0]=buf_ptr->buf0[11];  // 三级中继   10
      	buf_ptr->buf0[12]=dat_ptr[c].s_no[1];    a012[1]=buf_ptr->buf0[12];
      	buf_ptr->buf0[13]=dat_ptr[c].s_no[2];    a012[2]=buf_ptr->buf0[13];
      	buf_ptr->buf0[14]=(buf_ptr->buf0[14]&0x0f)+0x60;
    }
    else { buf_ptr->buf0[14]=(buf_ptr->buf0[14]&0x5f)+0x50; goto DZZZ; }   	// 变成二级中继
  	c=get_sno(&buf_ptr->buf0[11]); // P1=0xf1;
// 	c=comp1(c);
  	if(dat_ptr[c].s_xh)
    {
		j++;
      	c=dat_ptr[c].s_xh;
//      	c=comp1(c);
      	buf_ptr->buf0[11]=dat_ptr[c].s_no[0];                   // 四级中继      11
      	buf_ptr->buf0[12]=dat_ptr[c].s_no[1];
      	buf_ptr->buf0[13]=dat_ptr[c].s_no[2];
      	buf_ptr->buf0[14]=(buf_ptr->buf0[14]&0x0f)+0x70;
    }
    else buf_ptr->buf0[14]=(buf_ptr->buf0[14]&0x0f)+0x6f;        // 变成三级中继
DZZZ:
	if(j==4){j=0;t2=t2+12;goto czzz;}
	if(j==3){j=3;t2=t2+9;goto czzz;}
	if(j==2){j=6;t2=t2+6;goto czzz;}
	if(j==1){j=9;t2=t2+3;goto czzz;}
	if(j==0){j=12;t2=t2;}
czzz:
	i=17;buf_ptr->buf0[15]=t2;
	bb=0;
	while(1)
    {
		if(i>19)
	    {ac[bb]=buf_ptr->buf0[i];bb++;}
	  	if(j<15){buf_ptr->buf0[i]=a012[j];i++;j++;}
	  	if(j==15){h=h-5;bb=0;j=16;}
	  	if(j==16)
	    while (h!=0)
		{
			buf_ptr->buf0[i]=ac[bb];
		 	bb++;i++;h--;
		}
	  	if((j==16)&&(h==0)) break;
	}
	buf_ptr->buf0[15]=t2;
//  P1=0xf1;
    see=0;                                    /*  SIO=2; ram_page=1;  */
    for(i=10;i<t2+5+10;i++)
	{see=see+buf_ptr->buf0[i];}
    buf_ptr->buf0[i]=(uchar)see;  i++; buf_ptr->buf0[i]=(uchar)(see>>8);
//    P1=0xf1;
   	fsnd();
  	for(i=0;i<3;i++) if(wr_82502(t2+15)) break ;      //  后面所有的长度
   	for(j=0;j<t2+15;j++)
	{
		for(i=0;i<3;i++)
	  		if(wr_82502(buf_ptr->buf0[j+3])) break ;
	}
   	for(i=0;i<3;i++) if(wr_82502(0)) break ;
   	goto cww;
cqq:
//  	P1=0xf1;
  	fsnd();
//  	buf_ptr = (HBUF xdata *)BUF_ADD;
	buf_ptr = (HBUF *)BUF_ADD;
  	buf_ptr->buf0[0] = buf_ptr->buf0[0]-4;
  	for(i=0;i<3;i++) if(wr_82502(buf_ptr->buf0[0])) break ;
  	for(j=0;j<buf_ptr->buf0[0];j++)
	{
		for(i=0;i<3;i++)
	  		if(wr_82502(buf_ptr->buf0[j+3])) break ;
	}
  	for(i=0;i<3;i++) if(wr_82502(0)) break ;

⌨️ 快捷键说明

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