4.4.2_プログラムリスト(BATCONTROL2_User.c)
修正箇所(自動生成ファイルに記述追加)は、以下の青色の箇所です。
#include "D:\\WIZ_C\\Ver12\\Projects\\BATTCONTROL2\\BATTCONTROL2_Auto.h"
#include <Strings.h> #include <Delays.h> #__config _CONFIG1H, 0x02 #__config _CONFIG1L, 0x00 #__config _CONFIG2H, 0x0E #__config _CONFIG2L, 0x0E #__config _CONFIG3H, 0x01 #__config _CONFIG3L, 0x00 #__config _CONFIG4H, 0x00 #__config _CONFIG4L, 0x81 unsigned char out_str1[17], out_str2[17], out_str3[5]; unsigned long BV_15v, BV_PV; unsigned long BV_PV_Work, BV_PV_Work1, BV_PV_Work2; unsigned long AllCount, AllSecCount, SecCount, MinCount, HourCount; WORD BV_HH_V, BV_H_V, BV_M_V, BV_L_V, BV_LL_V, BV_ChargeON_V, BV_ChargeOFF_V; WORD BV_Work1, BV_Work2, EE_Work1; BYTE dt1, dt2; bit EE_SetMode, EE_Check; bit BV_Charge; bit SW_Timer,SW_Timer1,SW_Timer2,SW_Timer3,SW_Timer4; bit Timer_Reset1,Timer_Reset2; bit LED_Work1,LED_Work2,LED_Work3; void TimerCount(); void Timer_GB(); void Timer_G(); void Timer_YB(); void Timer_Y(); void Timer_RB(); void Timer_R(); void Timer_GBYBRB(); // // This file includes all user definable routines. It may be changed at will as // it will not be regenerated once the application has been generated for the // first time. // //******************************************************************************* // // Insert your interrupt handling code if required here. // Note quick interrupts are used so code must be simple // See the manual for details of quick interrupts. // void UserInterrupt() { // Insert your code here #asmline goto UserIntReturn ; PIC Assembler - go back to interrupt routine } //******************************************************************************* // // Insert your initialisation code if required here. // Note that when this routine is called Interrupts will not be enabled - the // Application Designer will enable them before the main loop // void UserInitialise() { BV_15v = 727; //15V standard a/d value dt1 = ReadEEData(0); dt2 = ReadEEData(1); EE_Work1 = (WORD)dt2 << 8; BV_HH_V = EE_Work1 | dt1; dt1 = ReadEEData(2); dt2 = ReadEEData(3); EE_Work1 = (WORD)dt2 << 8; BV_H_V = EE_Work1 | dt1; dt1 = ReadEEData(4); dt2 = ReadEEData(5); EE_Work1 = (WORD)dt2 << 8; BV_M_V = EE_Work1 | dt1; dt1 = ReadEEData(6); dt2 = ReadEEData(7); EE_Work1 = (WORD)dt2 << 8; BV_L_V = EE_Work1 | dt1; dt1 = ReadEEData(8); dt2 = ReadEEData(9); EE_Work1 = (WORD)dt2 << 8; BV_LL_V = EE_Work1 | dt1; dt1 = ReadEEData(10); dt2 = ReadEEData(11); EE_Work1 = (WORD)dt2 << 8; BV_ChargeON_V = EE_Work1 | dt1; dt1 = ReadEEData(12); dt2 = ReadEEData(13); EE_Work1 = (WORD)dt2 << 8; BV_ChargeOFF_V = EE_Work1 | dt1; if(BV_HH_V < 105) EE_Check = 1; if(BV_HH_V > 155) EE_Check = 1; if(BV_H_V < 105) EE_Check = 1; if(BV_H_V > 155) EE_Check = 1; if(BV_M_V < 105) EE_Check = 1; if(BV_M_V > 155) EE_Check = 1; if(BV_L_V < 105) EE_Check = 1; if(BV_L_V > 155) EE_Check = 1; if(BV_LL_V < 105) EE_Check = 1; if(BV_LL_V > 155) EE_Check = 1; if(BV_H_V >= BV_HH_V) EE_Check = 1; if(BV_M_V >= BV_H_V) EE_Check = 1; if(BV_L_V >= BV_M_V) EE_Check = 1; if(BV_LL_V >= BV_L_V) EE_Check = 1; if(BV_ChargeON_V < 105) EE_Check = 1; if(BV_ChargeON_V > 155) EE_Check = 1; if(BV_ChargeOFF_V < 105) EE_Check = 1; if(BV_ChargeOFF_V > 155) EE_Check = 1; if(BV_ChargeOFF_V <= BV_ChargeON_V) EE_Check = 1; if(EE_Check) { //INITIAL SET VALUE BV_HH_V = 144; //14.4V BV_H_V = 126; //12.6V BV_M_V = 122; //12.2V BV_L_V = 118; //11.8V BV_LL_V = 114; //11.4V BV_ChargeON_V = 112; //11.2V BV_ChargeOFF_V = 122; //12.2V } LCDClear(); if(EE_Check) sprintf(out_str1,"SET VALUE FALSE "); else sprintf(out_str1,"INITIALIZE "); BV_Work1 = BV_HH_V / 10; BV_Work2 = BV_HH_V % 10; sprintf(out_str2,"BV_HH:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,0); LCDString(out_str1); LCDPrintAt(0,1); LCDString(out_str2); Wait(3000); BV_Work1 = BV_H_V / 10; BV_Work2 = BV_H_V % 10; sprintf(out_str2,"BV_H:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); Wait(3000); BV_Work1 = BV_M_V / 10; BV_Work2 = BV_M_V % 10; sprintf(out_str2,"BV_M:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); Wait(3000); BV_Work1 = BV_L_V / 10; BV_Work2 = BV_L_V % 10; sprintf(out_str2,"BV_L:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); Wait(3000); BV_Work1 = BV_LL_V / 10; BV_Work2 = BV_LL_V % 10; sprintf(out_str2,"BV_LL:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); Wait(3000); BV_Work1 = BV_ChargeON_V / 10; BV_Work2 = BV_ChargeON_V % 10; sprintf(out_str2,"ChON_V:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); Wait(3000); BV_Work1 = BV_ChargeOFF_V / 10; BV_Work2 = BV_ChargeOFF_V % 10; sprintf(out_str2,"ChOFF_V:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); Wait(3000); LCDClear(); ADCON0 |= (1<<GO); } //******************************************************************************* // // Insert your main loop code if required here. This routine will be called // as part of the main loop code // void UserLoop() { if(!PC.B0) EE_SetMode = 1; if(EE_SetMode) { PD.B6 = 0; PD.B7 = 0; PC.B7 = 0; LCDClear(); sprintf(out_str1,"SETTING MODE "); LCDPrintAt(0,0); LCDString(out_str1); Wait(2000); //BV_HH SETTING BV_Work1 = BV_HH_V / 10; BV_Work2 = BV_HH_V % 10; sprintf(out_str2,"BV_HH:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); while(PC.B0) { if(!PC.B1) { BV_HH_V = BV_HH_V + 1; if(BV_HH_V > 155) BV_HH_V = 155; BV_Work1 = BV_HH_V / 10; BV_Work2 = BV_HH_V % 10; sprintf(out_str2,"BV_HH:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); Wait(1000); } if(!PC.B2) { BV_HH_V = BV_HH_V - 1; if(BV_HH_V < 105) BV_HH_V = 105; BV_Work1 = BV_HH_V / 10; BV_Work2 = BV_HH_V % 10; sprintf(out_str2,"BV_HH:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); Wait(1000); } } sprintf(out_str2,"BV_HH:WRITING. "); LCDPrintAt(0,1); LCDString(out_str2); dt1 = BV_HH_V & 0x00FF; dt2 = BV_HH_V >> 8; WriteEEData(0,dt1); Wait(500); WriteEEData(1,dt2); Wait(1000); //BV_H SETTING BV_Work1 = BV_H_V / 10; BV_Work2 = BV_H_V % 10; sprintf(out_str2,"BV_H:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); while(PC.B0) { if(!PC.B1) { BV_H_V = BV_H_V + 1; if(BV_H_V > 155) BV_H_V = 155; BV_Work1 = BV_H_V / 10; BV_Work2 = BV_H_V % 10; sprintf(out_str2,"BV_H:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); Wait(1000); } if(!PC.B2) { BV_H_V = BV_H_V - 1; if(BV_H_V < 105) BV_H_V = 105; BV_Work1 = BV_H_V / 10; BV_Work2 = BV_H_V % 10; sprintf(out_str2,"BV_H:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); Wait(1000); } } sprintf(out_str2,"BV_H:WRITING. "); LCDPrintAt(0,1); LCDString(out_str2); dt1 = BV_H_V & 0x00FF; dt2 = BV_H_V >> 8; WriteEEData(2,dt1); Wait(500); WriteEEData(3,dt2); Wait(1000); //BV_M SETTING BV_Work1 = BV_M_V / 10; BV_Work2 = BV_M_V % 10; sprintf(out_str2,"BV_M:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); while(PC.B0) { if(!PC.B1) { BV_M_V = BV_M_V + 1; if(BV_M_V > 155) BV_M_V = 155; BV_Work1 = BV_M_V / 10; BV_Work2 = BV_M_V % 10; sprintf(out_str2,"BV_M:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); Wait(1000); } if(!PC.B2) { BV_M_V = BV_M_V - 1; if(BV_M_V < 105) BV_M_V = 105; BV_Work1 = BV_M_V / 10; BV_Work2 = BV_M_V % 10; sprintf(out_str2,"BV_M:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); Wait(1000); } } sprintf(out_str2,"BV_M:WRITING. "); LCDPrintAt(0,1); LCDString(out_str2); dt1 = BV_M_V & 0x00FF; dt2 = BV_M_V >> 8; WriteEEData(4,dt1); Wait(500); WriteEEData(5,dt2); Wait(1000); //BV_L SETTING BV_Work1 = BV_L_V / 10; BV_Work2 = BV_L_V % 10; sprintf(out_str2,"BV_L:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); while(PC.B0) { if(!PC.B1) { BV_L_V = BV_L_V + 1; if(BV_L_V > 155) BV_L_V = 155; BV_Work1 = BV_L_V / 10; BV_Work2 = BV_L_V % 10; sprintf(out_str2,"BV_L:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); Wait(1000); } if(!PC.B2) { BV_L_V = BV_L_V - 1; if(BV_L_V < 105) BV_L_V = 105; BV_Work1 = BV_L_V / 10; BV_Work2 = BV_L_V % 10; sprintf(out_str2,"BV_L:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); Wait(1000); } } sprintf(out_str2,"BV_L:WRITING. "); LCDPrintAt(0,1); LCDString(out_str2); dt1 = BV_L_V & 0x00FF; dt2 = BV_L_V >> 8; WriteEEData(6,dt1); Wait(500); WriteEEData(7,dt2); Wait(1000); //BV_LL SETTING BV_Work1 = BV_LL_V / 10; BV_Work2 = BV_LL_V % 10; sprintf(out_str2,"BV_LL:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); while(PC.B0) { if(!PC.B1) { BV_LL_V = BV_LL_V + 1; if(BV_LL_V > 155) BV_LL_V = 155; BV_Work1 = BV_LL_V / 10; BV_Work2 = BV_LL_V % 10; sprintf(out_str2,"BV_LL:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); Wait(1000); } if(!PC.B2) { BV_LL_V = BV_LL_V - 1; if(BV_LL_V < 105) BV_LL_V = 105; BV_Work1 = BV_LL_V / 10; BV_Work2 = BV_LL_V % 10; sprintf(out_str2,"BV_LL:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); Wait(1000); } } sprintf(out_str2,"BV_LL:WRITING. "); LCDPrintAt(0,1); LCDString(out_str2); dt1 = BV_LL_V & 0x00FF; dt2 = BV_LL_V >> 8; WriteEEData(8,dt1); Wait(500); WriteEEData(9,dt2); Wait(1000); //ChON_V SETTING BV_Work1 = BV_ChargeON_V / 10; BV_Work2 = BV_ChargeON_V % 10; sprintf(out_str2,"ChON_V:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); while(PC.B0) { if(!PC.B1) { BV_ChargeON_V = BV_ChargeON_V + 1; if(BV_ChargeON_V > 155) BV_ChargeON_V = 155; BV_Work1 = BV_ChargeON_V / 10; BV_Work2 = BV_ChargeON_V % 10; sprintf(out_str2,"ChON_V:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); Wait(1000); } if(!PC.B2) { BV_ChargeON_V = BV_ChargeON_V - 1; if(BV_ChargeON_V < 105) BV_ChargeON_V = 105; BV_Work1 = BV_ChargeON_V / 10; BV_Work2 = BV_ChargeON_V % 10; sprintf(out_str2,"ChON_V:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); Wait(1000); } } sprintf(out_str2,"ChON_V:WRITING. "); LCDPrintAt(0,1); LCDString(out_str2); dt1 = BV_ChargeON_V & 0x00FF; dt2 = BV_ChargeON_V >> 8; WriteEEData(10,dt1); Wait(500); WriteEEData(11,dt2); Wait(1000); //ChOFF_V SETTING BV_Work1 = BV_ChargeOFF_V / 10; BV_Work2 = BV_ChargeOFF_V % 10; sprintf(out_str2,"ChOFF_V:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); while(PC.B0) { if(!PC.B1) { BV_ChargeOFF_V = BV_ChargeOFF_V + 1; if(BV_ChargeOFF_V > 155) BV_ChargeOFF_V = 155; BV_Work1 = BV_ChargeOFF_V / 10; BV_Work2 = BV_ChargeOFF_V % 10; sprintf(out_str2,"ChOFF_V:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); Wait(1000); } if(!PC.B2) { BV_ChargeOFF_V = BV_ChargeOFF_V - 1; if(BV_ChargeOFF_V < 105) BV_ChargeOFF_V = 105; BV_Work1 = BV_ChargeOFF_V / 10; BV_Work2 = BV_ChargeOFF_V % 10; sprintf(out_str2,"ChOFF_V:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); Wait(1000); } } sprintf(out_str2,"ChOFF_V:WRITING."); LCDPrintAt(0,1); LCDString(out_str2); dt1 = BV_ChargeOFF_V & 0x00FF; dt2 = BV_ChargeOFF_V >> 8; WriteEEData(12,dt1); Wait(500); WriteEEData(13,dt2); Wait(1000); sprintf(out_str2,"PREASE RESET!! "); LCDPrintAt(0,1); LCDString(out_str2); while(EE_SetMode){} //process interrupt } else { if(!PD.B0) { strcpy(out_str3,"(1H)"); SW_Timer = 1; SW_Timer1 = 1; SW_Timer2 = 0; SW_Timer3 = 0; SW_Timer4 = 0; Timer_Reset1 = 1; } if(!PD.B1) { strcpy(out_str3,"(2H)"); SW_Timer = 1; SW_Timer1 = 0; SW_Timer2 = 1; SW_Timer3 = 0; SW_Timer4 = 0; Timer_Reset1 = 1; } if(!PD.B2) { strcpy(out_str3,"(3H)"); SW_Timer = 1; SW_Timer1 = 0; SW_Timer2 = 0; SW_Timer3 = 1; SW_Timer4 = 0; Timer_Reset1 = 1; } if(!PD.B3) { strcpy(out_str3,"(4H)"); SW_Timer = 1; SW_Timer1 = 0; SW_Timer2 = 0; SW_Timer3 = 0; SW_Timer4 = 1; Timer_Reset1 = 1; } if(Timer_Reset1) { Timer_Reset1 = 0; AllCount = 0; AllSecCount = 0; SecCount = 0; MinCount = 0; HourCount = 0; } if(!PD.B4) Timer_Reset2 = 1; if(SW_Timer1) if(HourCount == 1) Timer_Reset2 = 1; if(SW_Timer2) if(HourCount == 2) Timer_Reset2 = 1; if(SW_Timer3) if(HourCount == 3) Timer_Reset2 = 1; if(SW_Timer4) if(HourCount == 4) Timer_Reset2 = 1; if(BV_PV > BV_HH_V) Timer_Reset2 = 1; if(Timer_Reset2) { Timer_Reset2 = 0; SW_Timer = 0; SW_Timer1 = 0; SW_Timer2 = 0; SW_Timer3 = 0; SW_Timer4 = 0; BV_Charge = 0; } BV_PV_Work1 = BV_PV / 10; BV_PV_Work2 = BV_PV % 10; sprintf(out_str1,"BATT VOLT:%ld.%ldV ",BV_PV_Work1,BV_PV_Work2); if(SW_Timer) sprintf(out_str2,"TIMER%s:%02ld:%02ld",out_str3,HourCount,MinCount); else { sprintf(out_str2," "); AllCount = 0; AllSecCount = 0; SecCount = 0; MinCount = 0; HourCount = 0; } LCDPrintAt(0,0); LCDString(out_str1); LCDPrintAt(0,1); LCDString(out_str2); if(SW_Timer) BV_Charge = 1; else { if(BV_PV >= BV_ChargeOFF_V) BV_Charge = 0; if(BV_PV > 0) if(!BV_Charge) if(BV_PV <= BV_ChargeON_V) BV_Charge = 1; } if(BV_Charge) { PD.B5 = 1; Timer_GBYBRB(); } else { PD.B5 = 0; if(BV_PV > BV_HH_V) Timer_GB(); if(BV_PV <= BV_HH_V) if(BV_PV >= BV_H_V) Timer_G(); if(BV_PV < BV_H_V) if(BV_PV >= BV_M_V) Timer_YB(); if(BV_PV < BV_M_V) if(BV_PV >= BV_L_V) Timer_Y(); if(BV_PV < BV_L_V) if(BV_PV >= BV_LL_V) Timer_RB(); if(BV_PV < BV_LL_V) Timer_R(); } TimerCount(); } } // // User occurrence code // void TimerCount() { AllCount = AllCount + 1; AllSecCount = AllCount / 2; HourCount = AllSecCount / 3600; MinCount = AllSecCount / 60; MinCount = MinCount % 60; SecCount = AllSecCount % 60; } void Timer_GB() { PD.B6 = 0; PC.B7 = 0; if(LED_Work1) { PD.B7 = 1; LED_Work1 = 0; } else { PD.B7 = 0; LED_Work1 = 1; } Wait(500); } void Timer_G() { PD.B6 = 0; PD.B7 = 1; PC.B7 = 0; Wait(500); } void Timer_YB() { PD.B6 = 0; PD.B7 = 0; if(LED_Work2) { PC.B7 = 1; LED_Work2 = 0; } else { PC.B7 = 0; LED_Work2 = 1; } Wait(500); } void Timer_Y() { PD.B6 = 0; PD.B7 = 0; PC.B7 = 1; Wait(500); } void Timer_RB() { PD.B7 = 0; PC.B7 = 0; if(LED_Work3) { PD.B6 = 1; LED_Work3 = 0; } else { PD.B6 = 0; LED_Work3 = 1; } Wait(500); } void Timer_R() { PD.B6 = 1; PD.B7 = 0; PC.B7 = 0; Wait(500); } void Timer_GBYBRB() { PD.B6 = 1; PD.B7 = 1; PC.B7 = 1; Wait(63); PD.B6 = 0; PD.B7 = 0; PC.B7 = 0; Wait(62); PD.B6 = 1; PD.B7 = 1; PC.B7 = 1; Wait(63); PD.B6 = 0; PD.B7 = 0; PC.B7 = 0; Wait(62); PD.B6 = 1; PD.B7 = 1; PC.B7 = 1; Wait(63); PD.B6 = 0; PD.B7 = 0; PC.B7 = 0; Wait(62); PD.B6 = 1; PD.B7 = 1; PC.B7 = 1; Wait(63); PD.B6 = 0; PD.B7 = 0; PC.B7 = 0; Wait(62); } // // Occurrence - A/D Conversion complete // void ad_data_v() { BV_PV_Work = (unsigned long)ADRESH << 8; BV_PV_Work = BV_PV_Work | ADRESL; BV_PV = BV_PV_Work * 150 / BV_15v; ADCON0 |= (1<<GO); } トップページヘもどる |