3.5.4_プログラムリスト(BATTERYVOLTMONITOR_User.c)
修正箇所(自動生成ファイルに記述追加)は、以下の青色の箇所です。
#include "C:\\WIZ_C\\Ver17\\Projects\\BATTERYVOLTMONITOR\\BATTERYVOLTMONITOR_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 bit Flag100mSec, Flag250mSec, EE_Check, EE_15v_Check; bit LeftKey, RightKey, UpKey, DownKey, DispModeKey, SetModeKey, SetKey; BYTE out_str1[17], out_str2[17]; BYTE TimerCount1, TimerCount2, SetModeNo, cursorNo_Set, dt1, dt2; BYTE LedBlinkMode, LedBlinkModePrev, LedBlinkCount; WORD BV_15v, BV_HH_V, BV_H_V, BV_M_V, BV_L_V, BV_LL_V, BV_LLL_V; WORD BV_HH_V_Work, BV_H_V_Work, BV_M_V_Work, BV_L_V_Work, BV_LL_V_Work, BV_LLL_V_Work; WORD BV_15v_Work, BV_Work1, BV_Work2, EE_Work1; ulong BV_PV, BV_PV_Work, BV_PV_Work1, BV_PV_Work2; // // 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 if(PIR1 & (1<<CCP1IF)) { PIR1 &= ~(1<<CCP1IF); TimerCount1 = TimerCount1 + 1; TimerCount2 = TimerCount2 + 1; if(TimerCount1 == 10) { Flag100mSec = 1; TimerCount1 = 0; } if(TimerCount2 == 25) { Flag250mSec = 1; TimerCount2 = 0; } PIE1 |= 1<<CCP1IE; } #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() { 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_LLL_V = EE_Work1 | dt1; dt1 = ReadEEData(12); dt2 = ReadEEData(13); EE_Work1 = (WORD)dt2 << 8; BV_15v = 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_LLL_V < 105) EE_Check = 1; if(BV_LLL_V > 155) 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_LLL_V = 110; //11.0V } if(BV_15v < 500) EE_15v_Check = 1; if(BV_15v >1000) EE_15v_Check = 1; if(EE_15v_Check) { //INITIAL A/D VALUE BV_15v = 730; } 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(1500); 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(1500); 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(1500); 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(1500); 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(1500); BV_Work1 = BV_LLL_V / 10; BV_Work2 = BV_LLL_V % 10; sprintf(out_str2,"BV_LLL:%d.%dV ",BV_Work1,BV_Work2); LCDPrintAt(0,1); LCDString(out_str2); Wait(1500); LCDClear(); LedBlinkMode = 0; INTCON |= 1<<PEIE; PIE1 |= 1<<CCP1IE; 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(!PD.B6) //AD_Adjust15v { UpKey = 0; DownKey = 0; LeftKey = 0; RightKey = 0; DispModeKey = 0; SetModeKey = 0; BV_15v_Work = (WORD)BV_PV_Work; sprintf(out_str1,"READY 15V!(%d)",BV_15v_Work); sprintf(out_str2,"PUSH! SET KEY. "); LCDPrintAt(0,0); LCDString(out_str1); LCDPrintAt(0,1); LCDString(out_str2); if(SetKey ) { EE_15v_Check = 0; if(BV_15v_Work < 500) EE_15v_Check = 1; if(BV_15v_Work >1000) EE_15v_Check = 1; if(!EE_15v_Check) { LCDClear(); sprintf(out_str1,"15V A/D VAL. "); sprintf(out_str2,"WRITING. "); LCDPrintAt(0,0); LCDString(out_str1); LCDPrintAt(0,1); LCDString(out_str2); dt1 = BV_15v_Work & 0x00FF; dt2 = BV_15v_Work >> 8; WriteEEData(12,dt1); Wait(20); WriteEEData(13,dt2); Wait(2000); LCDClear(); sprintf(out_str1,"15V A/D SET OK!"); sprintf(out_str2," "); LCDPrintAt(0,0); LCDString(out_str1); LCDPrintAt(0,1); LCDString(out_str2); Wait(2000); BV_15v = BV_15v_Work; } SetKey = 0; } } else { if(Flag250mSec) { Flag250mSec = 0; if(SetModeNo == 0) { BV_PV_Work1 = BV_PV / 10; BV_PV_Work2 = BV_PV % 10; sprintf(out_str1,"BATTERY VOLTAGE "); sprintf(out_str2," %ld.%ldV ",BV_PV_Work1,BV_PV_Work2); } if(SetModeNo == 1) { //LCD display sprintf(out_str1,"SETTING MODE "); switch(cursorNo_Set) { case 0: BV_Work1 = BV_HH_V_Work / 10; BV_Work2 = BV_HH_V_Work % 10; sprintf(out_str2,"BV_HH : %2d.%dV ",BV_Work1,BV_Work2); break; case 1: BV_Work1 = BV_H_V_Work / 10; BV_Work2 = BV_H_V_Work % 10; sprintf(out_str2,"BV_H : %2d.%dV ",BV_Work1,BV_Work2); break; case 2: BV_Work1 = BV_M_V_Work / 10; BV_Work2 = BV_M_V_Work % 10; sprintf(out_str2,"BV_M : %2d.%dV ",BV_Work1,BV_Work2); break; case 3: BV_Work1 = BV_L_V_Work / 10; BV_Work2 = BV_L_V_Work % 10; sprintf(out_str2,"BV_L : %2d.%dV ",BV_Work1,BV_Work2); break; case 4: BV_Work1 = BV_LL_V_Work / 10; BV_Work2 = BV_LL_V_Work % 10; sprintf(out_str2,"BV_LL : %2d.%dV ",BV_Work1,BV_Work2); break; case 5: BV_Work1 = BV_LLL_V_Work / 10; BV_Work2 = BV_LLL_V_Work % 10; sprintf(out_str2,"BV_LLL: %2d.%dV ",BV_Work1,BV_Work2); } } LCDPrintAt(0,0); LCDString(out_str1); LCDPrintAt(0,1); LCDString(out_str2); if(SetModeNo == 1) { LCDPrintAt(9, 1); LCDOnOff(1, 0, 1); } } if(DispModeKey) { DispModeKey = 0; SetModeNo = 0; } if(SetModeKey) { SetModeKey = 0; SetModeNo = 1; BV_HH_V_Work = BV_HH_V; BV_H_V_Work = BV_H_V; BV_M_V_Work = BV_M_V; BV_L_V_Work = BV_L_V; BV_LL_V_Work = BV_LL_V; BV_LLL_V_Work = BV_LLL_V; cursorNo_Set = 0; LCDClear(); } if(SetModeNo == 0) { UpKey = 0; DownKey = 0; LeftKey = 0; RightKey = 0; SetKey = 0; } if(SetModeNo == 1) { if(UpKey) { UpKey = 0; switch(cursorNo_Set) { case 0: if(BV_HH_V_Work > 155) BV_HH_V_Work = 0; else BV_HH_V_Work = BV_HH_V_Work + 1; break; case 1: if(BV_H_V_Work > 155) BV_H_V_Work = 0; else BV_H_V_Work = BV_H_V_Work + 1; break; case 2: if(BV_M_V_Work > 155) BV_M_V_Work = 0; else BV_M_V_Work = BV_M_V_Work + 1; break; case 3: if(BV_L_V_Work > 155) BV_L_V_Work = 0; else BV_L_V_Work = BV_L_V_Work + 1; break; case 4: if(BV_LL_V_Work > 155) BV_LL_V_Work = 0; else BV_LL_V_Work = BV_LL_V_Work + 1; break; case 5: if(BV_LLL_V_Work > 155) BV_LLL_V_Work = 0; else BV_LLL_V_Work = BV_LLL_V_Work + 1; break; } } if(DownKey) { DownKey = 0; switch(cursorNo_Set) { case 0: if(BV_HH_V_Work < 106) BV_HH_V_Work = 105; else BV_HH_V_Work = BV_HH_V_Work - 1; break; case 1: if(BV_H_V_Work < 106) BV_H_V_Work = 105; else BV_H_V_Work = BV_H_V_Work - 1; break; case 2: if(BV_M_V_Work < 106) BV_M_V_Work = 105; else BV_M_V_Work = BV_M_V_Work - 1; break; case 3: if(BV_L_V_Work < 106) BV_L_V_Work = 105; else BV_L_V_Work = BV_L_V_Work - 1; break; case 4: if(BV_LL_V_Work < 106) BV_LL_V_Work = 105; else BV_LL_V_Work = BV_LL_V_Work - 1; break; case 5: if(BV_LLL_V_Work < 106) BV_LLL_V_Work = 105; else BV_LLL_V_Work = BV_LLL_V_Work - 1; break; } } if(LeftKey) { LeftKey = 0; if(cursorNo_Set == 0) cursorNo_Set = 5; else cursorNo_Set = cursorNo_Set - 1; } if(RightKey) { RightKey = 0; if(cursorNo_Set == 5) cursorNo_Set = 0; else cursorNo_Set = cursorNo_Set + 1; } if(SetKey) { dt1 = BV_HH_V_Work & 0x00FF; dt2 = BV_HH_V_Work >> 8; BV_HH_V = BV_HH_V_Work; WriteEEData(0,dt1); Wait(20); WriteEEData(1,dt2); Wait(20); dt1 = BV_H_V_Work & 0x00FF; dt2 = BV_H_V_Work >> 8; BV_H_V = BV_H_V_Work; WriteEEData(2,dt1); Wait(20); WriteEEData(3,dt2); Wait(20); dt1 = BV_M_V_Work & 0x00FF; dt2 = BV_M_V_Work >> 8; BV_M_V = BV_M_V_Work; WriteEEData(4,dt1); Wait(20); WriteEEData(5,dt2); Wait(20); dt1 = BV_L_V_Work & 0x00FF; dt2 = BV_L_V_Work >> 8; BV_L_V = BV_L_V_Work; WriteEEData(6,dt1); Wait(20); WriteEEData(7,dt2); Wait(20); dt1 = BV_LL_V_Work & 0x00FF; dt2 = BV_LL_V_Work >> 8; BV_LL_V = BV_LL_V_Work; WriteEEData(8,dt1); Wait(20); WriteEEData(9,dt2); Wait(20); dt1 = BV_LLL_V_Work & 0x00FF; dt2 = BV_LLL_V_Work >> 8; BV_LLL_V = BV_LLL_V_Work; WriteEEData(10,dt1); Wait(20); WriteEEData(11,dt2); Wait(1000); SetModeNo = 0; SetKey = 0; } } } if(Flag100mSec) { Flag100mSec = 0; LedBlinkMode = 0; //1:GB, 2:G, 3:YB, 4:Y, 5:RB, 6:R, 7:GBYBRB if(BV_PV > BV_HH_V) LedBlinkMode = 1; if(BV_PV <= BV_HH_V) if(BV_PV > BV_H_V) LedBlinkMode = 2; if(BV_PV <= BV_H_V) if(BV_PV > BV_M_V) LedBlinkMode = 3; if(BV_PV <= BV_M_V) if(BV_PV > BV_L_V) LedBlinkMode = 4; if(BV_PV <= BV_L_V) if(BV_PV > BV_LL_V) LedBlinkMode = 5; if(BV_PV <= BV_LL_V) if(BV_PV > BV_LLL_V) LedBlinkMode = 6; if(BV_PV <= BV_LLL_V) LedBlinkMode = 7; if(!PD.B6) //AD_Adjust15v LedBlinkMode = 8; if(LedBlinkMode != LedBlinkModePrev) { LedBlinkModePrev = LedBlinkMode; LedBlinkCount = 0; PORTC &= 0x0F; //PC.B4 = 0, PC.B5 = 0, PC.B6 = 0, PC.B7 = 0 } if(LedBlinkMode == 2) //LedBlinkMode:G PC.B5 = 1; if(LedBlinkMode == 4) //LedBlinkMode:Y PC.B6 = 1; if(LedBlinkMode == 6) //LedBlinkMode:R PC.B7 = 1; if(LedBlinkMode == 1) //LedBlinkMode:GB { if(LedBlinkCount == 0 || LedBlinkCount == 1 || LedBlinkCount == 2 || LedBlinkCount == 3 || LedBlinkCount == 4) PC.B5 = 1; if(LedBlinkCount == 5 || LedBlinkCount == 6 || LedBlinkCount == 7 || LedBlinkCount == 8 || LedBlinkCount == 9) PC.B5 = 0; } if(LedBlinkMode == 3) //LedBlinkMode:YB { if(LedBlinkCount == 0 || LedBlinkCount == 1 || LedBlinkCount == 2 || LedBlinkCount == 3 || LedBlinkCount == 4) PC.B6 = 1; if(LedBlinkCount == 5 || LedBlinkCount == 6 || LedBlinkCount == 7 || LedBlinkCount == 8 || LedBlinkCount == 9) PC.B6 = 0; } if(LedBlinkMode == 5) //LedBlinkMode:RB { if(LedBlinkCount == 0 || LedBlinkCount == 1 || LedBlinkCount == 2 || LedBlinkCount == 3 || LedBlinkCount == 4) PC.B7 = 1; if(LedBlinkCount == 5 || LedBlinkCount == 6 || LedBlinkCount == 7 || LedBlinkCount == 8 || LedBlinkCount == 9) PC.B7 = 0; } if(LedBlinkMode == 7) //LedBlinkMode:GBYBRB, Buzzer { if(LedBlinkCount == 0 || LedBlinkCount == 1 || LedBlinkCount == 2 || LedBlinkCount == 3 || LedBlinkCount == 4) PC.B4 = 1; //Buzzer if(LedBlinkCount == 5 || LedBlinkCount == 6 || LedBlinkCount == 7 || LedBlinkCount == 8 || LedBlinkCount == 9) PC.B4 = 0; //Buzzer if(LedBlinkCount == 0 || LedBlinkCount == 2 || LedBlinkCount == 4 || LedBlinkCount == 6 || LedBlinkCount == 8) PORTC |= 0xE0; //PC.B5 = 1, PC.B6 = 1, PC.B7 = 1 if(LedBlinkCount == 1 || LedBlinkCount == 3 || LedBlinkCount == 5 || LedBlinkCount == 7 || LedBlinkCount == 9) PORTC &= 0x1F; //PC.B5 = 0, PC.B6 = 0, PC.B7 = 0 } if(LedBlinkMode == 8) //AD_Adjust15v PORTC &= 0x1F; //PC.B5 = 0, PC.B6 = 0, PC.B7 = 0 LedBlinkCount = LedBlinkCount + 1; if(LedBlinkCount == 10) LedBlinkCount = 0; ADCON0 |= (1<<GO); //A/D Conversion start } } // // User occurrence code // // // Occurrence - A key has been pressed (or is repeating) // void KeyPress() { switch(KP4Value) { case 0:UpKey = 1;break; case 1:DownKey = 1;break; case 2:LeftKey = 1;break; case 3:RightKey = 1;break; case 4:DispModeKey = 1;break; case 5:SetModeKey = 1;break; case 6:SetKey = 1;break; } } // // Occurrence - A/D Conversion complete // void ad_data_v() { BV_PV_Work = (ulong)ADRESH << 8; BV_PV_Work = BV_PV_Work | ADRESL; BV_PV = BV_PV_Work * 150 / BV_15v; } トップページヘもどる |