void mcp3301Task(void *p_arg){ uint16_t v; uint16_t temp; uint32_t i,j; char ch; (void)p_arg; // mcp3301Init(64,0x43,0x50,0); /// wrong use, spiInit should be called only once!!! m25p40Init(32,0x43,0x50,0); dinInit(); doutInit(); wfx40Init(); //rs485 水位计 AD1_Init(); getDin16(&wdin);/// get Din; rtc_pause_count = 0; //m25p40Init(32,0x43,0x90,0); // m25p40Init(64,0x43,0x90,0); /* pcfTime.year = 10; pcfTime.mon = 5; pcfTime.day = 0x25; pcfTime.hour = 0x17; pcfTime.min = 0x19; pcfTime.sec = 0x00; pcf8563SetTime(); */ ///////////////////////////// fix it!////////////////////////////////////////////////// // m25p40EraseCmd(0); // m25p40EraseCmd(SECTOR_BYTES); OSTimeDly(500); // waiting for GPRS ready pcf8563Init(); //RTC trigger_minutes = 0; //启动后发送数据 //////此处增加参数初始化// fixed_sendtime1 = 0xffff; //需要改为从at24中读取 fixed_sent = 0; m25p40ParaInit(); m25_add = m25sector.start_addr; pcf8563GetTime(); m25p40Write(m25_add,"reset:",6); m25_add+=6; m25p40Write(m25_add,(uint8_t *)&pcfTime,6); m25_add+=6; pre_minutes = BCD2char(pcfTime.hour)*60 + BCD2char(pcfTime.min); stop_check_minutes = pre_minutes; ////////循环开始 //////////////////////////////////////////// req_sample = 0; rtc_pause_count = 0; raingaugebak = raingauge; /* while((0 == gprsIPdone) &&(0 == SMSdone)){ OSTimeDly(100); } */ while(1){ pcf8563GetTime(); current_minutes = BCD2char(pcfTime.hour)*60 + BCD2char(pcfTime.min); if(current_minutes - pre_minutes >= para_send_gap_min){ req_sample = 1; req_send = 1; pre_minutes = current_minutes; } if(fixed_sendtime1 == current_minutes){ if(0 == fixed_sent){ req_send = 1; fixed_sent = 1; } } if(current_minutes > fixed_sendtime1 ){ fixed_sent = 0; //恢复 } //判断PCF8536是否正常 if(rtc_pause_count > 15){ //大于一分钟却没有变化 if(stop_check_minutes == current_minutes){ if(rtc_pause_count > 10*para_send_gap_min){ req_sample = 1; req_send = 1; rtc_pause_count = 0; } }else{ stop_check_minutes = current_minutes; rtc_pause_count = 0; } } rtc_pause_count++; //每个循环6秒钟 // req_sample = 1; if(req_sample){ //翻斗式雨量计 /**** 雨量采集 ****/ if(raingaugebak != raingauge){ raingaugebak = raingauge; ch = '#'; sc16puts(&ch,1); configParaSet(PARA_RAIN,&raingauge,2); //只在雨量有变化才存贮 } //数字量采集 getDin16(&wdin);/// get Din; ///模拟量采集 for(i=0;i<6;i++){ adAverage[i] = 0; } for(i=0;i<3;i++){ AD1_Measure(1); AD1_GetValue16(adValues); for(j=0;j<6;j++){ adAverage[j] += (adValues[j]>>4); } } for(j=0;j<6;j++){ adAverage[j] /= 3; } for(j=0;j<4;j++){ ch = adAverage[2]>>((3-j)*4)&0x0f; ch += '0'; sc16puts(&ch,1); } sc16puts(" ",1); //485采集 /* */ setDout(0); //打开电源 OSTimeDly(200); wfx40Write(); // OSTimeDly(100); if(TRUE == wfx40Data(&waterlevel)){ sc16puts(&waterlevel,2); } OSTimeDly(100); clrDout(0); //关闭电源 protocolConstruct(); m25p40Write(m25_add,(uint8_t *)&rtufile,rtufile.len*2+4); m25_add+= rtufile.len*2+4; if(1 == req_send ){ if((1 ==gprsIPdone )&& (0== gprsLock)) { gprsSendData((uint8_t *)&rtufile,rtufile.len*2+2+2); // head + crc pro_in.no_received++; }else if((1 == SMSdone)&&(0== gprsLock)){ msgProtocolSend("13910996917",&rtufile); } req_send = 0; } for(j=0;j<4;j++){ ch = rtufile.time[2]>>((3-j)*4)&0x0f; ch += '0'; sc16puts(&ch,1); } sc16puts(" ",1); req_sample = 0; } if(udp_download){ i = timegap_end-timegap_start ; time_add = timegap_start; while(i){ if(i>80){ for(temp=0;temp<80;temp++){ m25p40RD(time_add,&frame_buffer[temp],1); time_add++; } gprsSendData(frame_buffer,80); i-=80; }else{ for(temp=0;temp<i;temp++){ m25p40RD(time_add,&frame_buffer[temp],1); time_add++; } gprsSendData(frame_buffer,i); i=0; } } udp_download = 0; } OSTimeDly(300); msgGetList(); OSTimeDly(300); } }
/* ** =================================================================== ** Method : PE_low_level_init (component MKL25Z128LK4) ** ** Description : ** Initializes beans and provides common register initialization. ** The method is called automatically as a part of the ** application initialization code. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ void PE_low_level_init(void) { #ifdef PEX_RTOS_INIT PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */ #endif /* Initialization of the SIM module */ /* PORTA_PCR4: ISF=0,MUX=7 */ PORTA_PCR4 = (uint32_t)((PORTA_PCR4 & (uint32_t)~(uint32_t)( PORT_PCR_ISF_MASK )) | (uint32_t)( PORT_PCR_MUX(0x07) )); /* Initialization of the RCM module */ /* RCM_RPFW: RSTFLTSEL=0 */ RCM_RPFW &= (uint8_t)~(uint8_t)(RCM_RPFW_RSTFLTSEL(0x1F)); /* RCM_RPFC: RSTFLTSS=0,RSTFLTSRW=0 */ RCM_RPFC &= (uint8_t)~(uint8_t)( RCM_RPFC_RSTFLTSS_MASK | RCM_RPFC_RSTFLTSRW(0x03) ); /* Initialization of the PMC module */ /* PMC_LVDSC1: LVDACK=1,LVDIE=0,LVDRE=1,LVDV=0 */ PMC_LVDSC1 = (uint8_t)((PMC_LVDSC1 & (uint8_t)~(uint8_t)( PMC_LVDSC1_LVDIE_MASK | PMC_LVDSC1_LVDV(0x03) )) | (uint8_t)( PMC_LVDSC1_LVDACK_MASK | PMC_LVDSC1_LVDRE_MASK )); /* PMC_LVDSC2: LVWACK=1,LVWIE=0,LVWV=0 */ PMC_LVDSC2 = (uint8_t)((PMC_LVDSC2 & (uint8_t)~(uint8_t)( PMC_LVDSC2_LVWIE_MASK | PMC_LVDSC2_LVWV(0x03) )) | (uint8_t)( PMC_LVDSC2_LVWACK_MASK )); /* PMC_REGSC: BGEN=0,ACKISO=0,BGBE=0 */ PMC_REGSC &= (uint8_t)~(uint8_t)( PMC_REGSC_BGEN_MASK | PMC_REGSC_ACKISO_MASK | PMC_REGSC_BGBE_MASK ); /* SMC_PMPROT: ??=0,??=0,AVLP=0,??=0,ALLS=0,??=0,AVLLS=0,??=0 */ SMC_PMPROT = 0x00U; /* Setup Power mode protection register */ /* Common initialization of the CPU registers */ /* PORTA_PCR20: ISF=0,MUX=7 */ PORTA_PCR20 = (uint32_t)((PORTA_PCR20 & (uint32_t)~(uint32_t)( PORT_PCR_ISF_MASK )) | (uint32_t)( PORT_PCR_MUX(0x07) )); /* NVIC_IPR1: PRI_6=0 */ NVIC_IPR1 &= (uint32_t)~(uint32_t)(NVIC_IP_PRI_6(0xFF)); /* ### Serial_LDD "IO1" component auto initialization. Auto initialization feature can be disabled by component property "Auto initialization". */ (void)IO1_Init(NULL); /* ### BitIO_LDD "BitIoLdd1" component auto initialization. Auto initialization feature can be disabled by component property "Auto initialization". */ (void)BitIoLdd1_Init(NULL); /* ### LED "LEDgreen" init code ... */ LEDgreen_Init(); /* initializes the driver */ /* ### BitIO_LDD "BitIoLdd2" component auto initialization. Auto initialization feature can be disabled by component property "Auto initialization". */ (void)BitIoLdd2_Init(NULL); /* ### LED "LEDred" init code ... */ LEDred_Init(); /* initializes the driver */ /* ### ADC "AD1" init code ... */ AD1_Init(); __EI(); }
void mcp3301Task(void *p_arg){ uint16_t v; uint16_t temp; uint32_t i; uint16_t j; char ch; (void)p_arg; rtcInit(); // mcp3301Init(64,0x43,0x50,0); /// wrong use, spiInit should be called only once!!! m25p40Init(32,0x43,0x50,0); AD1_Init(); dinInit(); doutInit(); // wfx40Init(); //rs485 水位计 YSIInit(); // RS485Init(); // TUFInit(); at24Init(); //参数初始化 configParaInit(); getDin16(&wdin);/// get Din; rtc_pause_count = 0; mcu_time_count = 0; //m25p40Init(32,0x43,0x90,0); // m25p40Init(64,0x43,0x90,0); ///////////////////////////// fix it!////////////////////////////////////////////////// /*********************************** m25p40EraseCmd(0); m25p40EraseCmd(SECTOR_BYTES); m25p40EraseCmd(SECTOR_BYTES*2); m25p40EraseCmd(SECTOR_BYTES*3); m25p40EraseCmd(SECTOR_BYTES*4); m25p40EraseCmd(SECTOR_BYTES*5); m25p40EraseCmd(SECTOR_BYTES*6); m25p40EraseCmd(SECTOR_BYTES*7);*******************/ OSTimeDly(500); // waiting for GPRS ready pcf8563Init(); //RTC trigger_minutes = 0; //启动后发送数据 //////此处增加参数初始化// fixed_sendtime1 = 0xffff; //需要改为从at24中读取 fixed_sent = 0; m25p40ParaInit(); m25_add = m25sector.start_addr; pcf8563GetTime(); m25p40Write(m25_add,"reset:",6); m25_add+=6; m25p40Write(m25_add,(uint8_t *)&pcfTime,6); m25_add+=6; pre_minutes = BCD2char(pcfTime.hour)*60 + BCD2char(pcfTime.min); stop_check_minutes = pre_minutes; ////////循环开始 //////////////////////////////////////////// req_sample = 0; rtc_pause_count = 0; mcu_time_count = 0; raingaugebak = raingauge; OSTimeDly(3500); // waiting for GPRS ready while(1){ pcf8563GetTime(); current_minutes = BCD2char(pcfTime.hour)*60 + BCD2char(pcfTime.min); /* if(current_minutes - pre_minutes >= para_send_gap_min){ req_sample = 1; req_send = 1; pre_minutes = current_minutes; } */ //需要修改,防止一分钟内重复进入 if((TRUE == triggerTime(current_minutes))&&(current_minutes != pre_minutes)){ req_sample = 1; req_send = 1; pre_minutes = current_minutes; } if(fixed_sendtime1 == current_minutes){ if(0 == fixed_sent){ req_send = 1; fixed_sent = 1; } } if(current_minutes > fixed_sendtime1 ){ fixed_sent = 0; //恢复 } if((TRUE == triggerSample(current_minutes))&&(current_minutes != pre_minutes)){ req_sample = 1; pre_minutes = current_minutes; } //判断PCF8536是否正常 if(rtc_pause_count > 15){ //大于一分钟却没有变化 if(stop_check_minutes == current_minutes){ if(mcu_time_count > 60*para_send_gap_min){ req_sample = 1; req_send = 1; mcu_time_count = 0; } }else{ stop_check_minutes = current_minutes; rtc_pause_count = 0; mcu_time_count = 0; } } rtc_pause_count++; //每个循环6秒钟 mcu_time_count++; //翻斗式雨量计 /**** 雨量采集 ****/ /** 实时采集,有降雨就发送 **/ if(raingaugebak != raingauge){ if(raingauge - raingaugebak>= RAIN_TRIGGER){ req_sample = 1; req_send = 1; } raingaugebak = raingauge; ch = '#'; sc16puts(&ch,1); configParaSet(PARA_RAIN,&raingauge,2); //只在雨量有变化才存贮 if(0 ==(raingauge%para_rain_cont)){ req_sample = 1; req_send = 1; } } if(reUDPsend){ //需要重发 ch = '$'; sc16puts(&ch,1); req_sample = 1; req_send = 1; reUDPsend = 0; } // req_sample = 1; if(req_sample){ //数字量采集 getDin16(&wdin);/// get Din; ///模拟量采集 for(i=0;i<9;i++){ adAverage[i] = 0; } for(i=0;i<3;i++){ AD1_Measure(1); AD1_GetValue16(adValues); for(j=0;j<9;j++){ adAverage[j] += (adValues[j]>>4); } } for(j=0;j<9;j++){ adAverage[j] /= 3; } for(j=0;j<4;j++){ ch = adAverage[8]>>((3-j)*4)&0x0f; ch += '0'; sc16puts(&ch,1); } sc16puts(" ",1); //485采集 /* */ #if WFX_485 setDout(0); //打开电源 OSTimeDly(200); wfx40Write(); // OSTimeDly(100); if(TRUE == wfx40Data(&waterlevel)){ sc16puts(&waterlevel,2); } /*判断界限**/ if(waterlevel > para_water_high){ req_send = 1; } OSTimeDly(100); clrDout(0); //关闭电源 #endif YSIWeekup(); OSTimeDly(50); YSITwipeb(); OSTimeDly(50); YSIWrite(); OSTimeDly(10); YSIClr(); OSTimeDly(700); YSIRead(); OSTimeDly(50); YSISleep(); /* TUFRead(); TUFWrite(); OSTimeDly(3); // TUFCSRxd(); TUFRead(); */ protocolConstruct(); m25p40Write(m25_add,(uint8_t *)&rtufile,rtufile.len*2+4); m25_add+= rtufile.len*2+4; ///以下代码根据阀值判断是否需要发送 /* if((waterlevel > high) ||(waterlevel < low)){ req_send = 1; } */ if(1 == req_send ){ if(0 == gprsIPdone){ rebootflag = 1; //重新配置gprs标志 task_active[TASKACTIVE_SAMPLE]++; gprsPrepare(); task_active[TASKACTIVE_SAMPLE]++; rebootflag = 0; } if((1 ==gprsIPdone) && (0== gprsLock)) { pro_in.no_received++; //先增加,避免在3秒时间内收到数据而统计错误 gprsSendData((uint8_t *)&rtufile,rtufile.len*2+2+2); // head + crc for(j=0;j<3;j++){ if(1 == gprsStnDone[j]){ OSTimeDly(500); gprsData(j+2,(uint8_t *)&rtufile,rtufile.len*2+2+2 + 5); // head + crc } } // pro_in.no_received++; noUDPrec = rtc_pause_count; //记录发送时间,六秒为单位 } /*else if((1 == SMSdone)&&(0== gprsLock)){ msgProtocolSend("13910996917",&rtufile); myReset(); } */ req_send = 0; OSTimeDly(300); msgGetList(); //短信列表 OSTimeDly(300); gprsShutdown(); clrDout(1); gprsIPdone =0; }else{ //增加心跳包 } for(j=0;j<4;j++){ ch = rtufile.time[2]>>((3-j)*4)&0x0f; ch += '0'; sc16puts(&ch,1); } sc16puts(" ",1); req_sample = 0; } if(0 == task_active[TASKACTIVE_SAMPLE]&0x0f){ msgGetList(); //短信列表 } if(udp_download){ //召测 i = timegap_end-timegap_start ; time_add = timegap_start; frame_buffer[0] = 'Z'; frame_buffer[1] = 'C'; j = 0; while(i){ if(i>80){ for(temp=0;temp<80;temp++){ m25p40RD(time_add,&frame_buffer[temp+2],1); time_add++; } frame_buffer[82]= j>>8; frame_buffer[83]= j&0xff; gprsSendData(frame_buffer,84); i-=80; }else{ for(temp=0;temp<i;temp++){ m25p40RD(time_add,&frame_buffer[temp+2],1); time_add++; } frame_buffer[temp+2]= 0xE5; frame_buffer[temp+3]= 0xE5; //最后一帧 gprsSendData(frame_buffer,i+4); i=0; } j++; task_active[TASKACTIVE_SAMPLE]++; } udp_download = 0; } OSTimeDly(300); task_active[TASKACTIVE_SAMPLE]++; OSTimeDly(300); }