define user register
WEI1EQUH'0C';BIT0=MODS: select mode bit 0: mode 11: mode 2
;BIT1=BREK: circuit break judgment bit 0: no circuit break 1: circuit break
;BIT2=
;BIT3=
;BIT4=
;BIT5=slow beep
;BIT6=fast beep
;BIT7=long beep
WEI2EQUH'0D';Start value of "hundreds place value operation"
WEI3EQUH'0E';Start value of "tens value operation"
WEI4EQUH'0F';Ones place value
WEI5EQUH'10'; Hundreds place value
WEI6EQUH'11'; Tens place value
WEI7EQUH'12';
WEI8EQUH'13';
WEI9EQUH'14';
WEIAEQUH'15';
WEIBEQUH'16'
WEICEQUH'17'
WEIDEQUH'18'
WEIEEQUH'19'
WEIFEQUH'1A'
WEIGEQUH'1B'
WEIHEQUH'1C'
WEIIEQUH'1D'
CHECKEQUH'7'
DPEQUH'1'
ADEQUH'0'
BUZZEREQUH'3'
REQUH'2'
LEQUH'4'
;************************************************ ************************
; vector address
ORGH'00'; reset vector
GOTOMAIN
ORGH'04'; interrupt vector
NOP
GOTOINTER
;************************************************ ************************
; digital value
TABLE:
ADDWFPCL, F;
RETLWB'01000000'; "0" value
RETLWB'01111001'; "1" value
RETLWB'00100100'; "2" value
RETLWB'00110000'; "3" value
RETLWB'00011001'; "4" value
RETLWB'00010010'; "5" value
RETLWB'00000010'; "6" value
RETLWB'01011000'; "7" value
RETLWB'00000000'; "8" value
RETLWB'00010000'; "9" value
;------------------------------------------------ -----------------------
;Clear registers WEI1-WEIG
MAIN:
CLRFWEI1;
CLRFWEI2;
CLRFWEI3;
CLRFWEI4;
CLRFWEI5;
CLRFWEI6;
CLRFWEI7;
CLRFWEI8;
CLRFWEI9;
CLRFWEIA;
CLRFWEIB;
CLRFWEIC;
CLRFWEID;
CLRFWEIE;
CLRFWEIF;
CLRFWEIG;
CLRFWEIH;
CLRFWEII;
BSFSTATUS, RP0;
BCFOPTION_REG, NOT_RBPU
BCFSTATUS, RP0;
MOV FPORTB, 1;
BTFSSPORTB, 1;
BSFWEI1, 0;
;------------------------------------------------ -----------------------
;Set A/D channel and A/D structure
BSFSTATUS, RP0;
MOV LWB'00000010'; set an "A/D port"
MOV WFADCON1; reference voltage: working voltage 5V
MOV LWB'10000000';
MOV WFTRISB;
MOV LWB'00000001';
MOV WFTRISA;
MOV LWB'10000111';
MOV WFOPTION_REG;
MOV LWB'10100000';
MOV WFINCON;
;------------------------------------------------ ----------------------
;set port "input/output" and set initial state
BCFSTATUS, RP0;
MOV LWB'01000000'; set A/D channel: AN0
MOV WFADCON0; select internal 1:8 clock oscillation
MOV LWB'01111111';
MOV WFPORTB;
MOV LWB'00010110';
MOV WFPORTA;
MOV LWD'252';
MOV WFTMR0; set the initial value of TMR0
;------------------------------------------------ -----------------------
; select mode
BTFSCWEI1, 0; judge whether the "mode switch" is closed
GOTOMODLE2; "mode switch" is closed, then enter "mode 2"
GOTOMODLE1; "mode switch" is disconnected, then enter "mode 1"
;------------------------------------------------ -----------------------
;"Mode 1" initialization
MODLE1:
MOV FPORTB, 1;
BTFSSPORTB, CHECK; determine whether there is an open circuit
GOTO$+7;
BSFWEI1, 1;
BSFWEI1, 6; There is an open circuit: the buzzer sounds fast and the "no display" delays for 3 seconds
BCFWEI1, 5;
BCFWEI1, 7;
CALLDELAY3S; No open circuit: "No display" delay 3 seconds
GOTOSTART;
CALLDELAY3S;
GOTOSTART;
;------------------------------------------------ -----------------------
;"Mode 2" initializes and detects each segment of the digital tube, and the buzzer "long beeps"
MODLE2:
BSFWEI1, 0; set "mode select bit"
BSFWEI1, 7; turn on the buzzer "long beep"
BCFWEI1, 5;
BCFWEI1, 6;
BCFSTATUS, C; set "carry flag"
MOV LWB'11111111';
MOV WFWEI7;
RLFWEI7, F;
MOV FWEI7, W;
MOV WFPORTB; set "detect nixie tube segment value" to PORT5
BCFPORTA, R; open "right digital tube"
BCFPORTA, L; open "left digital tube"
CALLDELAYP5;
BSFPORTA, R; turn off "right nixie tube"
BSFPORTA, L; turn off "left nixie tube"
MOV LWB'11111111';
MOV WFPORTB; clear the "detection digital tube segment value" for PORT5
BTFSCWEI7, 6; check whether the detection is completed
GOTO$-D'11'; continue to detect if not completed
BCFPORTA, DP; completed setting "decimal point" and "1" value
BCFPORTA, R; open "right digital tube"
BCFPORTA, L; open "left digital tube"
CALLDELAYP5;
BSFPORTA, R; turn off "right nixie tube"
BSFPORTA, L; turn off "left nixie tube"
BSFPORTA, DP; clear "decimal point" and "1" value
BCFWEI1, 7; turn off the buzzer "long beep"
BCFWEI1, 6;
BCFWEI1, 5;
GOTOSTART;
;------------------------------------------------ -----------------------
;start working
START:
MOV FPORTB, F;
BTFSCPORTB, CHECK; determine whether there is an open circuit
GOTODUANLU; there is an open circuit
BCFWEI1, 1; clear 0 circuit breaker discrimination bit
GOTOPANZHI; no open circuit
;------------------------------------------------ -----------------------
; circuit breaker
DUANLU:
BSFWEI1, 1; set the disconnection judgment bit
BSFWEI1, 6;
BCFWEI1, 5;
BCFWEI1, 7;
GOTOPANZHI;
;------------------------------------------------ -----------------------
; judge the voltage value
PANZHI:
BSFADCON0, ADON; A/D is working
BSFADCON0, GO_DONE; A/D starts running
BTFSCADCON0, GO_DONE; judge whether A/D is completed
GOTO$-1; A/D not completed
BCFADCON0, ADIF;
BCFADCON0, ADON; A/D has finished turning off A/D
CALLCV;
MOV FADRES, W;
MOV WFWEI8;
MOV WFWEI2; A/D value is passed to WEI2
BCFSTATUS, C; clear the "carry flag"
SUBLWD'200';
BTFSSSTATUS, C
GOTOV_20;Skip to "20V Above" procedure
MOV FADRES, W
BCFSTATUS, C; clear the "carry flag"
SUBLWD'160'
BTFSSSTATUS, C
GOTOV16; Skip to "Between 16V-19.9V" procedure
MOV FADRES, W
BCFSTATUS, C; clear the "carry flag"
SUBLWD'100'
BTFSSSTATUS, C
GOTOV10; Skip to "Between 10V-15.9V" procedure
MOV FADRES, W
BCFSTATUS, C; clear the "carry flag"
SUBLWD'50'
BTFSSSTATUS, C
GOTOV5; Skip to "Between 5V-9.9V" procedure
GOTOV4.9; skip to the program below 4.9V
;------------------------------------------------ ------------------------
V4.9: ;The digital tube below 4.9V displays LL
BTFSCWEI1, 1; judge whether there is an open circuit
GOTO$+6;
BSFWEI1, 7; no open circuit long beep
BCFWEI1, 6;
BCFWEI1, 5;
CALLLL;
GOTOSTART;
BSFWEI1, 6; there is an open circuit fast sound
BCFWEI1, 5;
BCFWEI1, 7;
CALLLL;
GOTOSTART;
;------------------------------------------------ ------------------------
V5: between 5V-9.9V
BTFSCWEI1, 1; judge whether there is an open circuit
GOTO$+5;
BSFWEI1, 5; no open circuit slow sound
BCFWEI1, 6;
BCFWEI1, 7;
GOTODISPLAY;
BSFWEI1, 6; there is an open circuit fast sound
BCFWEI1, 5;
BCFWEI1, 7;
GOTODISPLAY;
;------------------------------------------------ ------------------------
V10: between 10V-15.9V
BTFSCWEI1, 1; judge whether there is an open circuit
GOTO$+5;
BCFWEI1, 5; no circuit breaker, no sound
BCFWEI1, 6;
BCFWEI1, 7;
GOTODISPLAY;
BSFWEI1, 6; there is an open circuit fast sound
BCFWEI1, 5;
BCFWEI1, 7;
GOTODISPLAY;
;------------------------------------------------ ------------------------
V16: ;16V-19.9V
BSFWEI1, 6; fast sound
BCFWEI1, 5;
BCFWEI1, 7;
GOTODISPLAY;
;------------------------------------------------ ------------------------
V_20:
BTFSCWEI1, 1; judge whether there is an open circuit
GOTO$+6;
BSFWEI1, 7; no open circuit long beep
BCFWEI1, 6;
BCFWEI1, 5;
CALLHH;
GOTOSTART;
BSFWEI1, 6; there is an open circuit fast sound
BCFWEI1, 5;
BCFWEI1, 7;
CALLHH;
GOTOSTART;
;------------------------------------------------ ------------------------
;Operation "display value"
DISPLAY:
NOP;
HUN:
MOV FWEI2, W;
MOV WFWEI3; The residual value of WEI2-100D is passed to WEI3 as the starting value of "tens value operation"
MOV LWD'100'
BCFSTATUS, C; clear the "carry flag"
SUBWWEI2, F; WEI2-100D residual value is passed to WEI2
BTFSSSTATUS, C; judge whether WEI2 is greater than 100D
GOTOTEN; if less than 100D, jump to "tens value operation"
INCFWEI5, F; greater than 100DWEI5+1: Hundreds place value
GOTOHUN
TEN:
MOV FWEI3, W;
MOV WFWEI4;
MOV LWD'10'; The remainder of WEI3-10D is passed to WEI4 as the starting value of "unit value operation"
BCFSTATUS, C; clear the "carry flag"
SUBWWEI3, F; WEI3-10D residual value is passed to WEI3
BTFSSSTATUS, C; judge whether WEI2 is greater than 10D
GOTONUMB; if less than 10D, jump to "ones place value operation"
INCFWEI6, F; greater than 10DWEI6+1: Tens place value
GOTOTEN
;------------------------------------------------ -----------------------
;Display "tens value" and "decimal point"
NUMB:
MOV FWEI6, W
CALLTABLE;
MOV WFPORTB; set "ten's value"
BCFPORTA, DP; set decimal point
BCFPORTA, L; open to display "ten's value"
CALLDELAY;
MOV LWB'11111111';
MOV WFPORTB; clear "tens value"
BSFPORTA, DP; clear decimal point
BSFPORTA, L; turn off the display of "tens value"
;------------------------------------------------ -----------------------
;Display "ones place value" "hundred place value"
MOV FWEI4, W
CALLTABLE
MOV WFPORTB; set "ones place value"
BCFSTATUS, Z; clear the "zero flag"
CLRW; clear W
IORWFWEI5, W;
BTFSSSTATUS, Z; determine whether there is a "hundreds place value"
BCFPORTA, DP; display "hundreds place"
BCFPORTA, R; open to display "ones place value"
CALLDELAY;
MOV LWB'11111111';
MOV WFPORTB; clear "ones place value"
BSFPORTA, DP; clear "hundreds"
BSFPORTA, R; turn off the display of "ones place value"
CLRFWEI6;
CLRFWEI5;
GOTOSTART;
;************************************************ ************************
; Delay 20MS second program
DELAY:
MOV LWD'10';
MOV WFWEIE;
DELAY1:
MOV LWD'10';
MOV WFWEIF;
DELAY2:
MOV LWD'10';
MOV WFWEIG;
DELAY3:
DECFSZWEIG, F;
GOTODELAY3;
DECFSZWEIF, F;
GOTODELAY2;
DECFSZWEIE, F;
GOTODELAY1;
RETURN;
;------------------------------------------------ -----------------------
; Delay 0.5 second program
DELAYP5:
CLRFWEI9;
CLRFWEIA;
BTFSSWEIA, 2;
GOTO$-1;
CLRFWEI9;
CLRFWEIA;
RETURN;
;------------------------------------------------ -----------------------
; Delay 3 seconds program
DELAY3S:
CLRFWEI9;
CLRFWEIA;
BTFSSWEIA, 4;
GOTO$-1;
CLRFWEI9;
CLRFWEIA;
RETURN;
;------------------------------------------------ -----------------------
CV:
BTFSSWEI1, 0;
RETURN;
MOV LWB'11100000';
ANDWWEI1, W;
BTFSSSTATUS, Z;
RETURN;
MOV FADRES, W;
XORWWEI8, W;
BTFSSSTATUS, Z;
GOTOCLEAR;
BTFSSWEIA, 4;
RETURN;
BSFINTCON, RBIE; enable PORTB pin change interrupt
BCFINTCON, GIE; disable global interrupts
BCFINTCON, T0IE;
MOV FPORTB, F; read status
SLEEP; go to sleep
NOP;
CLRFINTCON;
BSFINTCON, GIE;
BSFINTCON, T0IE;
CLRFWEI9;
CLRFWEIA;
RETURN;
CLEAR:
CLRFWEI9;
CLRFWEIA;
RETURN;
;------------------------------------------------ -----------------------
LL:
MOV LWB'11000111';
MOV WFPORTB;
BCFPORTA, L;
BCFPORTA, R;
CALLDELAY;
MOV LWB'11111111';
MOV WFPORTB;
BSFPORTA, L;
BSFPORTA, R;
RETURN
;------------------------------------------------ -----------------------
HH:
MOV LWB'10001001';
MOV WFPORTB;
BCFPORTA, L;
BCFPORTA, R;
CALLDELAY;
MOV LWB'11111111';
MOV WFPORTB;
BSFPORTA, L;
BSFPORTA, R;
RETURN
;************************************************ ************************
;TMR0 interrupt
INTER:
MOV WFWEIH; W, STATUS is pushed onto the stack
SWAPFSTATUS, W;
MOV WFWEII;
BCFINTCON, T0IF;
MOV LWD'252';
MOV WFTMR0; set the initial value of TMR0
INCFSZWEI9, F;
GOTO$+2;
INCFWEIA, F;
MOV LWB'11100000';
ANDWWEI1, W;
BTFSCSTATUS, Z;
GOTOOUT2;
MOV LWB'00001000';
XORWFPORTA, F;
BTFSSWEI1, 6;
GOTO$+D'10';
INCFSZWEIB, F;
GOTOOUT;
BCFPORTA, BUZZER;
BSFSTATUS, RP0;
MOV FTRISA, W;
XORLWB'00001000';
MOV WFTRISA;
BCFSTATUS, RP0;
GOTOOUT;
;------------------------------------------------ -----------------------
BTFSSWEI1, 5;
GOTOOUT1;
INCFSZWEIC, F;
GOTOOUT;
INCFWEID, F;
BTFSSWEID, 2;
GOTOOUT;
CLRFWEIC;
CLRFWEID;
BCFPORTA, BUZZER;
BSFSTATUS, RP0;
MOV FTRISA, W;
XORLWB'00001000';
MOV WFTRISA;
BCFSTATUS, RP0;
GOTOOUT;
OUT1:
BSFSTATUS, RP0;
MOV FTRISA, W;
ANDLWB'11110111';
MOV WFTRISA;
BCFSTATUS, RP0;
GOTOOUT;
OUT2:
BCFPORTA, BUZZER;
OUT:
SWAPFWEII, W; W, STATUS pop stack
MOV WFSTATUS;
SWAPFWEIH, F;
SWAPFWEIH, W;
RETFIE; enable interrupt and return
END
72V Battery Pack ,Lithium Ion Battery Pack,Lithium Battery Pack,Battery Power Pack
Zhejiang Casnovo Materials Co., Ltd. , https://www.casnovo-new-energy.com