;
; Čçěĺđčňĺëü ĺěęîńňč č ESR ýëĺęňđîëčňč÷ĺńęčő ęîíäĺíńŕňîđîâ
; C/ESR meter
; Ŕâňîđ Ăčíö Îëĺă
; Âĺđńč˙ 1.0
; Äŕňŕ 22/12/2006
;
; Â ďđîăđŕěěĺ čńďîëüçîâŕíű ôđŕăěĺíňű ęîäŕ čçěĺđčňĺë˙ FLC
; Ŕëĺęńŕíäđŕ Áóĺâńęîăî, ă.Ěčíńę, Áĺëŕđóńü
;***************************************************************************************
;*ÍÎĂŔ * ČĚß * ÍŔÇÍŔ×ĹÍČĹ
;***************************************************************************************
; 1 * MCLR/Vpp * Ńáđîń
; 2 * RA0/AN0 * âűőîä ÄÓ (Ęó=330)
; 3 * RA1/AN1 * âűőîä ÄÓ (Ęó=33)
; 4 * RA2/AN2/Vref- * Ęí. Set coeff./Set "0"
; 5 * RA3/AN3/Vref+ *
; 6 * RA4/T0CKI * Ęí.+/Test
; 7 * RA5/AN4/SS * Ęí.-
; 8 * Vss * GND
; 9 * OSC1/CLKIN * Ęâŕđö 20 ĚĂö
; 10 * OSC2/CLKOUT * Ęâŕđö 20 ĚĂö
; 11 * RC0/T1OSO/T1CKI * Çŕđ˙ä Ńő, I=10mA
; 12 * RC1/T1OSI/CCP2 * Đŕçđ˙ä Ńő
; 13 * RC2/CCP1 * Ęîěďŕđŕňîđ âĺđőíĺăî óđîâí˙ çŕđ˙äęč Ńő
; 14 * RC3/SCK/SCL * âő."-" íŕ çĺěëţ
; 15 * RC4/SDI/SDA * âő."+" íŕ Ńő
; 16 * RC5/SDO * âő."-" íŕ Ńő
; 17 * RC6/TX/CK * Ęîěďŕđŕňîđ íčćíĺăî óđîâí˙ çŕđ˙äęč Ńő
; 18 * RC7/RX/DT *
; 19 * Vss * +5V
; 20 * Vdd * GND
; 21 * RB0/INT * LCD_D4
; 22 * RB1 * LCD_D5
; 23 * RB2 * LCD_D6
; 24 * RB3/PGM * LCD_D7
; 25 * RB4 * LCD_R/S
; 26 * RB5 * LCD_E
; 27 * RB6/PGC *
; 28 * RB7/PGD *
;****************************************************************************************
Port_A_Config equ 0xFF
; Port A bit equates
Kn_Set equ 2
Kn_Plus equ 4
Kn_Minus equ 5
Port_B_Config equ b'11000000'
Port_C_Config equ b'11000100'
; Port C bit equates
Cap_Charge equ 0
Cap_Discharge equ 1
Comp_Up equ 2
In_N_Gnd equ 3
In_P_Cx equ 4
In_N_Cx equ 5
Comp_Low equ 6
ESR_ready equ b'00110011' ;âęë. đŕçđ˙ä, "+" č "-" ÄÓ íŕ Ńő
ESR_start equ b'00110000' ;âęë. çŕđ˙ä, "+" č "-" ÄÓ íŕ Ńő
Cap_ready equ b'00011011' ;âęë. đŕçä˙ä, "-" ÄÓ íŕ çĺěëţ, "+" íŕ Ńő
Cap_start equ b'00011000' ;âęë. çŕđ˙ä, "-" ÄÓ íŕ çĺěëţ, "+" íŕ Ńő
Cap_start2 equ b'00110000' ;âęë. çŕđ˙ä, "-" ÄÓ íŕ Cx, "+" íŕ Ńő
Max_Count equ .70 ;ěŕęńčěŕëüíîĺ ÷čńëî (1 áŕéň, íĺ áîëĺĺ 256) ďĺđĺďîëíĺíčé TMR0 ďđč ń÷ĺňĺ
;řŕă ń÷ĺňŕ - 0.2 ěęń, 65536*0.2=13107.2 ěęń - îäíî ďĺđĺďîëíĺíčĺ
;čëč ďđč I=10mA 15 îňń÷ĺňîâ/ěęÔ 65536/15=4369 ěęô - îäíî ďĺđĺďîëíĺíčĺ
;Ďóńňü Ńő ěŕő=150000ěęÔ, 150000/4369=34
;Ó÷čňűâŕ˙ âđĺě˙ çŕđ˙äŕ äî íčćíĺé ăđŕíčöű ęîíńňŕíňó íŕäî óäâîčňü
;****************************************************************************************
#include P16F873a.inc ; ; 20.000 MHz
__CONFIG _CP_OFF & _BODEN_OFF & _HS_OSC & _WRT_OFF & _WDT_OFF & _PWRTE_ON & _DEBUG_OFF & _CPD_OFF & _LVP_OFF
; #define _BAT PORTA,1 ; 0- low bat
#define _RS PORTB,4
#define _E PORTB,5
CBLOCK 0x35 ;0x20-0x34 for FLOATING POINT LIBRARY
; Áëîęč äŕííűő
W_TEMP ;ńîőđŕíĺíčĺ ęîíňĺęńňŕ ďđč ďđĺđűâŕíč˙ő
STATUS_TEMP
PCLATH_TEMP
Dly0 ;Stores 3 bytes of data for the delay count
Dly1 ;Dly0 is the least significant byte
Dly2 ;while Dly3 is the most significant byte
; Temp
Temp1
Temp2
Temp3
Temp4
Count1
Count2
T0
T1
; Áëîęč äŕííűő
T2 ; Ńňŕđřčé áŕéň
T3
T4
T5 ; Ěëŕäřčé áŕéň
AX ; Ńňŕđřčé áŕéň
A0
A1
A2 ; Ěëŕäřčé áŕéň
A3
A4
A5
BCD0 ; Ěëŕäřčé áŕéň
BCD1
BCD2
BCD3
BCD4 ; Ńňŕđřčé áŕéň
U330_L ;Íŕďđ˙ćĺíčĺ ń âűőîäŕ ÄÓ, Ęó=330, ěëŕäřčé áŕéň
U330_H ;Íŕďđ˙ćĺíčĺ ń âűőîäŕ ÄÓ, Ęó=330, ńňŕđřčé áŕéň
U33_L ;Íŕďđ˙ćĺíčĺ ń âűőîäŕ ÄÓ, Ęó=33, ěëŕäřčé áŕéň
U33_H ;Íŕďđ˙ćĺíčĺ ń âűőîäŕ ÄÓ, Ęó=33, ńňŕđřčé áŕéň
TMR1_Count ;Ń÷ĺň÷čę ďĺđĺďîëíĺíčé TMR1
TMR0_Count ;Ń÷ĺň÷čę ďĺđĺďîëíĺíčé TMR0
Flags
EE_ADR ;âńďîěîăŕňĺëüíŕ˙ ˙÷ĺéęŕ äë˙ đŕáîňű ń EEPROM
EE_DATA
NZ ;÷čńëî çíŕ÷ŕůčő đŕçđ˙äîâ ďđč âűâîäĺ íŕ číäčęŕňîđ
NC ;íîěĺđ ęîíńňŕíňű
Const_ADR ;ŕäđĺń ęîíńňŕíňű â EEPROM
ENDC
CBLOCK 0xB5
W_TEMP1 ;ńîőđŕíĺíčĺ ęîíňĺęńňŕ ďđč ďđĺđűâŕíč˙ő
ENDC
;=========================
; ĚŔĘĐÎŃŰ
;=========================
bank0 macro
bcf STATUS, RP0
endm
bank1 macro
bsf STATUS, RP0
endm
Dly24 MACRO DLY
;Take the delay value argument from the macro, precalculate
;the required 3 RAM values and load the The RAM values Dly2,Dly1
;and Dly0.
banksel Dly0
movlw DLY & H'FF'
movwf Dly0
movlw DLY >>D'08' & H'FF'
movwf Dly1
movlw DLY >>D'16' & H'FF'
movwf Dly2
;Bytes are shifted and anded by the assembler to make user
;calculations easier.
endm
;==========================
ORG 0x2100 ; Îáëŕńňü EEPROM
; Äŕííűĺ ; Ŕäđĺń â EEPROM
; ęîđđĺęňčđóţůčĺ ęîýôôčöčĺíňű äë˙:
USR_1 DE 0x00, 0x00, 0x03, 0xE8 ; 1 - ďđĺäĺëŕ 1 Îě
USR_10 DE 0x00, 0x00, 0x03, 0xE8 ; 1 - ďđĺäĺëŕ 10 Îě
USR_Cx DE 0x00, 0x00, 0x03, 0xE8 ; 1 - čçěĺđĺíč˙ ĺěęîńňč
;K_ESR_1 DE 0x7F, 0x00, 0x00, 0x00 ; 1 - ďđĺäĺëŕ 1 Îě
;K_ESR_10 DE 0x7F, 0x00, 0x00, 0x00 ; 1 - ďđĺäĺëŕ 10 Îě
;K_Cx DE 0x7F, 0x00, 0x00, 0x00 ; 1 - čçěĺđĺíč˙ ĺěęîńňč
;numbers in FLOATING POINT LIBRARY format
U0_ESR_1 DE 0x85, 0x16, 0x00, 0x00 ; 75=85160000 - "0" íŕ ďđĺäĺëĺ 1 Îě
U0_ESR_10 DE 0x81, 0x60, 0x00, 0x00 ; 7=81600000 - "0" íŕ ďđĺäĺëĺ 10 Îě
; ěíîćčňĺëč äë˙ đŕń÷ĺňîâ:
M_ESR_1 DE 0x75, 0x40, 0x30, 0x0C ; 1/682=7540300C
M_ESR_10 DE 0x78, 0x74, 0x89, 0x8D ; 1/67=7874898D
M_Cx DE 0x74, 0x2E, 0xC3, 0x3E ; 1/(15*100)=742EC33E
sub_Cx DE 0x80, 0x40, 0x00, 0x00 ; 3=80400000 - âű÷čňŕĺňń˙ čç ďîęŕçŕíčé TMR1
;==========================
org 0x700 ; ďîńäĺëíčĺ 256 áŕéň 1-é ńňđŕíčöű ďŕě˙ňč ďđîăđŕěě
Table addwf PCL,F
omega dt b'00000000' ;çíŕę îěĺăŕ
dt b'00001110'
dt b'00010001'
dt b'00010001'
dt b'00010001'
dt b'00001010'
dt b'00011011'
dt b'00000000'
mu dt b'00000000'
dt b'00000000'
dt b'00010010'
dt b'00010010'
dt b'00010010'
dt b'00011110'
dt b'00010001'
dt b'00010000'
_Const dt "Coeff. for",0
_ESR dt "ESR",0
_Cx dt " Cx ",0
_Time_out dt "Cx ---",0
_1_ohm dt " 1 ",1,0
_10_ohm dt " 10 ",1,0
_tst_1 dt "1",1,"=",0
_tst_10 dt " 10",1,"=",0
_write_U0 dt "U0 ---> EEPROM ",0
_ready dt "It is ready!",0
org 0x00
;*******************************************************************************
; ÍŔ×ŔËÎ ĎĐÎĂĐŔĚĚŰ
;*******************************************************************************
nop ;for MPLAB-ICD2
goto init
;------------------ Interrupt ------------------
org 0x004
movwf W_TEMP ;save W
swapf STATUS,W ;swap STATUS, W
clrf STATUS
movwf STATUS_TEMP ;save status
movf PCLATH,W
movwf PCLATH_TEMP ;save PCLFTH
decfsz TMR0_Count
goto restore_context
bsf Flags,0 ;Time Out!
goto stop_TMR1
restore_context
bcf INTCON,T0IF ;clear interrupt flag
movf PCLATH_TEMP,W
movwf PCLATH
swapf STATUS_TEMP,W ;fetch status, reswap nibbles
movwf STATUS ;restore status
swapf W_TEMP,F ;swap nibbles in preparation
swapf W_TEMP,W ;for the swap restoration of w
retfie ;return from interrupt
;-----------------------------------------------
init
banksel INTCON
clrf Flags
clrf INTCON
clrf PCLATH
clrf PORTA
clrf PORTB
movlw ESR_ready ;âęë. đŕçđ˙ä, "+" č "-" ÄÓ íŕ Ńő
movwf PORTC
banksel TRISA
movlw Port_A_Config
movwf TRISA
;číčöčŕëčçŕöč˙ ŔÖĎ
movlw b'10000100';ďđŕâîĺ âűđŕâíčâŕíčĺ, Vdd, Vss, AN0, AN1, AN3
movwf ADCON1
movlw Port_B_Config
movwf TRISB
movlw Port_C_Config
movwf TRISC
; Číčöčŕëčçŕöč˙ LCD â 4-ő áčňíűé đĺćčě
InitLCD
call Delay_5_ms
call Delay_5_ms
call Delay_5_ms ;ďŕóçŕ 15 ěń ďîńëĺ âęë ďčňŕíč˙
banksel PORTB
movlw 3
movwf Count1
movwf PORTB
SetLoop
bsf _E ;äë˙ číčöčŕëčçŕöčč LCD 3 đŕçŕ ďîńűëŕĺňń˙ ęîěŕíäŕ 0x30
nop
nop
nop
bcf _E
call Delay_5_ms
decfsz Count1,f
goto SetLoop
movlw 2 ; 4-x áčňíűé
movwf PORTB
call Send
movlw 28 ; 4-ő áčňíűé, 2 ńňđîęč, 5ő7
call CmdLCD
movlw 0C ; Âęëţ÷čňü äčńďëĺé
call CmdLCD
movlw 6
call CmdLCD
call Load_ZG ; Çŕăđóçčňü ńčěâîëű ěţ č îěĺăŕ
call ClrDSP ; Î÷čńňčňü äčńďëĺé
;--------------------------------------------------
btfsc PORTA, Kn_Set ;
goto Main
;------------ đĺćčě óńňŕíîâęč ęîíńňŕíň ------------
goto c_1
Const_Loop
btfss PORTA, Kn_Plus
call IncB
btfss PORTA, Kn_Minus
call DecB
btfsc PORTA, Kn_Set
goto Const_Loop
btfss Flags,5 ;ôëŕă čçěĺíĺíč˙ ęîíńňŕíňű
goto c_3
call Save_Const ;ęîíńňŕíňŕ čçěĺíčëŕńü, íŕäî ńîőđŕíčňü
c_3
incf NC,F
movf NC,W
sublw 3 ;÷čńëî ęîíńňŕíň
btfss STATUS,Z
goto $+2
c_1 clrf NC
bcf Flags,5 ;Î÷čůŕĺě ôëŕă čçěĺíĺíč˙ ęîíńňŕíňű
call ClrDSP ; Î÷čńňčňü äčńďëĺé
movlw LOW _Const
call Read_String
movlw HIGH $
movwf PCLATH
movf NC,W
addwf PCL,F ;ňŕáëč÷íűé ďĺđĺőîä
goto const_1_ohm ;+0
goto const_10_ohm ;+1
goto const_Cx ;+2
c_2 call ShowX
goto Const_Loop
const_1_ohm
movlw LOW USR_1
movwf Const_ADR
call EEPROM_To_B
movlw LOW _1_ohm
call Read_String
goto c_2
const_10_ohm
movlw LOW USR_10
movwf Const_ADR
call EEPROM_To_B
movlw LOW _10_ohm
call Read_String
goto c_2
const_Cx
movlw LOW USR_Cx
movwf Const_ADR
call EEPROM_To_B
movlw LOW _Cx
call Read_String
goto c_2
;------- Číčöčŕëčçŕöč˙ ěîäóë˙ ŔÖĎ ------
Main
; banksel ADCON1
; movlw b'10000100';ďđŕâîĺ âűđŕâíčâŕíčĺ, Vdd, Vss, AN0, AN1, AN3
; movwf ADCON1
ESR_measure
banksel PORTC
movlw ESR_start ; âęë. çŕđ˙ä, "+" č "-" ÄÓ íŕ Ńő
movwf PORTC
movlw 0x4 ;Çŕäĺđćęŕ 3.6ěęń (18 öčęëîâ) äë˙ îęîí÷ŕíč˙ ďĺđĺő.ďđîöĺńńîâ - ĎÎÄÎÁĐŔŇÜ!!!
call Delay_go
bcf PORTC, In_P_Cx ;îňęëţ÷ŕĺě Ńçŕď îň Ńő
nop ;???
bsf PORTC, Cap_Charge ;âűęë. Içŕđ.
;Čçěĺđ˙ĺě íŕďđ˙ćĺíčĺ ń âűőîäŕ äčô.óńčëčňĺë˙ ń Ęó=330
banksel ADCON0
movlw b'10000001' ;Fosc/32, ęŕíŕë 0, ěîäóëü ŔÖĎ âęë.
movwf ADCON0
call Delay_20_us
bsf ADCON0,2 ;íŕ÷ŕňü ŕíŕëîăî-öčôđîâîĺ ďđĺîáđŕçîâŕíčĺ
btfsc ADCON0,2
goto $-1 ; ćäĺě îęîí÷ŕíč˙ ďđĺîáđŕçîâŕíč˙
movf ADRESH,W
movwf U330_H
banksel ADRESL
movf ADRESL,W
banksel U330_L
movwf U330_L
;Čçěĺđ˙ĺě íŕďđ˙ćĺíčĺ ń âűőîäŕ äčô.óńčëčňĺë˙ ń Ęó=33
banksel ADCON0
movlw b'10001001' ;Fosc/32, ęŕíŕë 1, ěîäóëü ŔÖĎ âęë.
movwf ADCON0
call Delay_20_us
bsf ADCON0,2 ;íŕ÷ŕňü ŕíŕëîăî-öčôđîâîĺ ďđĺîáđŕçîâŕíčĺ
btfsc ADCON0,2
goto $-1 ; ćäĺě îęîí÷ŕíč˙ ďđĺîáđŕçîâŕíč˙
movf ADRESH,W
movwf U33_H
banksel ADRESL
movf ADRESL,W
banksel U33_L
movwf U33_L
;------------ Ĺńëč ESR>10 Îě, čçěĺđĺíčĺ ĺěęîńňč íĺ âűďîëí˙ĺě ------------
clrf Flags
movlw 0x03
subwf U33_H,W ;ĺńëč ďîęŕçŕíč˙ ŔÖĎ>=0x300 (768)
btfss STATUS,Z
goto Cx_0 ;ďĺđĺőîä íŕ čçěĺđĺíčĺ ĺěęîńňč
bsf Flags,0 ;âçâîäčě ôëŕă Time Out
goto Cx_3
;------------ Čçěĺđĺíčĺ ĺěęîńňč ęîíäĺíńŕňîđŕ ------------
Cx_0
movlw Cap_ready ;âęë. đŕçä˙ä, "-" ÄÓ íŕ çĺěëţ, "+" íŕ Ńő
movwf PORTC
call TMR0_init ;Çŕďóńęŕĺě TMR0 äë˙ ďđĺäîňâđŕůĺíč˙ çŕâčńŕíčé ďđč čçěĺđĺíčč ĺěęîńňč
call Delay_200_us
btfss PORTC, Comp_Low ; 1 - Cx đŕçđ˙äčëń˙
goto $-2 ;ćäĺě ńíîâŕ 200 ěęń
call Delay_200_us ;äë˙ íŕäĺćíîńňč ĺůĺ çŕäĺđćęŕ
call TMR1_init
movlw 0x03
subwf U330_H,W ;ĺńëč ďîęŕçŕíč˙ ŔÖĎ>=0x300 (768)
btfss STATUS,Z ;ň.ĺ. ESR>1 Îě, ĺěęîńňü čçěĺđ˙ĺě ń ęîěďĺíńŕöčĺé ESR
goto Cx_1
movlw Cap_start2 ;âęë. çŕđ˙ä, "-" ÄÓ íŕ Cx, "+" íŕ Ńő
movwf PORTC
movlw 0x4 ;Çŕäĺđćęŕ 3.6ěęń (18 öčęëîâ) äë˙ çŕđ˙äŕ Ń íŕ "-" âőîäĺ ÄÓ
call Delay_go
bcf PORTC,In_N_Cx ;îňęëţ÷ŕĺě "-" âőîä ÄÓ îň Ńő
goto Cx_2
Cx_1
movlw Cap_start ;âęë. çŕđ˙ä, "-" ÄÓ íŕ çĺěëţ, "+" íŕ Ńő
movwf PORTC
Cx_2
btfsc PORTC, Comp_Low ; 0 - Cx çŕđ˙äčëń˙ äî íčćíĺé ăđŕíčöű
goto $-1
bsf T1CON, TMR1ON ; çŕďóńęŕĺě ňŕéěĺđ
tst_charge
btfss PORTC,Comp_Up; 0 - Cx çŕđ˙äčëń˙ äî âĺđőíĺé ăđŕíčöű
goto stop_TMR1
btfsc PIR1, TMR1IF ; TMR1 ďĺđĺďîëíĺí?
call Inc_count
goto tst_charge
stop_TMR1
clrf T1CON ;îńňŕíîâčňü TMR1
clrf INTCON ;çŕďđĺůŕĺě ďđĺđűâŕíč˙
btfsc PIR1, TMR1IF ;ďđîâĺđčě ďîńëĺäíčé đŕç íŕ ďĺđĺďîëíĺíčĺ ňŕéěĺđŕ
call Inc_count ;áűëî ďĺđĺďîëíĺíčĺ
Cx_3 movlw Cap_ready ;âęë. đŕçä˙ä, "-" ÄÓ íŕ çĺěëţ, "+" íŕ Ńő
movwf PORTC
;--------------------------------------------------------
;Âűâîäčě đĺçóëüňŕň íŕ číäčęŕňîđ
; call CursorHome
call ClrDSP
;Timeout
btfss Flags,0
goto Disp_Cx
movlw LOW _Time_out
call Read_String
goto Disp_ESR
;--------------------------------------------------------
clrf FPFLAGS
bsf FPFLAGS, RND ; ôëŕă îęđóăëĺíč˙ ďđč đŕń÷ĺňŕő
Disp_Cx
movlw LOW _Cx
call Read_String
clrf AEXP
movf TMR1_Count,W
movwf AARGB0
movf TMR1H,W
movwf AARGB1
movf TMR1L,W
movwf AARGB2
btfsc PORTA, Kn_Plus
goto Calc_Cx
call BCD ;Ĺńëč íŕćŕňŕ ęíîďęŕ ďëţń, ňî ňĺńňîâűé âűâîä
movlw BCD4 ;ňŕéěĺđŕ áĺç îáđŕáîňęč
call Disp_Full
goto Disp_ESR
Calc_Cx
call FLO2424 ;Integer to float conversion
movlw low sub_Cx
call EEPROM_To_B
call FPS24 ;A=A-3
movlw low M_Cx
call EEPROM_To_B
call FPM24 ;A=A*M_Cx
movlw low USR_Cx
call X_To_B
call INT2424 ;Output: 24 bit 2's complement integer right
;justified in AARGB0, AARGB1, AARGB2
clrf AEXP
call BCD
bsf Flags,1 ;íĺ âűâîäčňü ëčäčđóţůčĺ íóëč
movlw 3
movwf NZ ;÷čńëî çíŕ÷ŕůčő đŕçđ˙äîâ, îńňŕëüíűĺ áóäóň 0
bsf Flags,3 ;âęëţ÷čňü ďđîâĺđęó çíŕ÷. đŕçđ˙äîâ ďđč âűâîäĺ
movlw BCD3
call DispBCD
movlw BCD3 ;ďîęŕçŕíč˙ óâĺëč÷ĺíű â 10 đŕç,
call DispBCD ;çäĺńü ńîňíč ňűń˙÷ ěęÔ
movlw BCD2 ;äĺń˙ňęč ňűń˙÷ ěęÔ
call DispBCD
movlw BCD2 ;ňűń˙÷č ěęÔ
call DispBCD
; ĺńëč âďĺđĺäč áűëč îäíč íóëč, đŕçäĺëčňĺëü íĺ âűâîäčě
btfsc Flags,1
goto next_1
movlw "," ;đŕçäĺëčňĺëü ňűń˙÷
call CharLCD
next_1
movlw BCD1 ;ńîňíč ěęÔ
call DispBCD
btfsc Flags,1 ;äî ńîňĺí íĺáűëî çíŕ÷ŕůčő öčôđ,
bsf Flags,2 ;áóäĺě âűâîäčňü äĺń˙ňűĺ äîëč ěęÔ
movlw BCD1 ;äĺń˙ňęč ěęÔ
call DispBCD
bcf Flags,1 ;ďđîâĺđęŕ íŕ =0 íĺ íóćíŕ, âűâîäčě âńĺ ďîäđ˙ä
movlw BCD0 ;ĺäčíčöű ěęÔ
call DispBCD
btfss Flags,2 ;íóćĺí ëč âűâîä äĺń˙ňč÷íîé ňî÷ęč
goto next_2 ;íĺň
bcf Flags,2 ;äŕ
call DispDot ;äĺń˙ňč÷íŕ˙ ňî÷ęŕ
movlw BCD0 ;äĺń˙ňűĺ ěęÔ
call DispBCD
next_2
call DispSP
movlw 2 ;ęîä ěţ
call CharLCD
movlw "F"
call CharLCD
;----------------------------
Disp_ESR
btfss PORTA, Kn_Plus
goto tst_ESR
bcf Flags,4 ;ńáđîń ôëŕăŕ áîëüřĺ 10 Îě
movlw 0x03
subwf U330_H,W ;ĺńëč ďîęŕçŕíč˙ ŔÖĎ>=0x300 (768)
btfsc STATUS,Z ;ďđîâĺđ˙ĺě âňîđîé ęŕíŕë (10 Îě)
goto chk_10
; Ęŕíŕë 1 Îě
call ClrA
movf U330_H,W ;óńčëčňĺëü Ęó=330, ďđĺäĺë 1 Îě
movwf AARGB0
movf U330_L,W
movwf AARGB1
call FLO1624 ;to 24 bit floating point
movlw low U0_ESR_1
call EEPROM_To_B
call FPS24 ;A=A-U0 - âű÷čňŕĺě ńěĺůĺíčĺ íóë˙
movlw low M_ESR_1
call EEPROM_To_B
call FPM24 ;A=A*M_ESR_1
movlw low USR_1
call X_To_B
goto ESR_to_LCD
chk_10
movlw 0x03
subwf U33_H,W ;ĺńëč ďîęŕçŕíč˙ ŔÖĎ>=0x300 (768)
btfsc STATUS,Z
bsf Flags,4 ;áîëüřĺ 10 Îě
;ęŕíŕë 10 Îě
call ClrA
movf U33_H,W ;óńčëčňĺëü Ęó=33, ďđĺäĺë 10 Îě
movwf AARGB0
movf U33_L,W
movwf AARGB1
call FLO1624 ;to 24 bit floating point
movlw low U0_ESR_10
call EEPROM_To_B
call FPS24 ;A=A-U0 - âű÷čňŕĺě ńěĺůĺíčĺ íóë˙
movlw low M_ESR_10
call EEPROM_To_B
call FPM24 ;A=A*M_ESR_10
movlw low USR_10
call X_To_B
ESR_to_LCD
call SecLine
movlw LOW _ESR
call Read_String
btfss Flags,4 ;>10 ohm?
goto next_3
movlw ">"
call CharLCD
goto next_4
next_3 call DispSP
next_4 movlw 0x80
andwf AARGB0,W ;âűäĺë˙ĺě çíŕę "-"
btfsc STATUS,Z
goto next_5 ;đĺçóëüňŕň > 0
call ClrA ;đĺçóëüňŕň < 0, âűâîäčě îäíč íóëč
goto next_6
next_5 call INT2424
next_6 bcf Flags,3 ;âűęëţ÷čňü ďđîâĺđęó çíŕ÷. đŕçđ˙äîâ ďđč âűâîäĺ
bsf Flags,1 ;íĺ âűâîäčňü ëčäčđóţůčĺ íóëč
clrf AEXP
call BCD
movlw BCD2
call DispBCD
movlw BCD2
call DispBCD ;äĺń˙ňęč Îě
bcf Flags,1 ;ďđîâĺđęŕ íŕ =0 íĺ íóćíŕ, âűâîäčě âńĺ ďîäđ˙ä
movlw BCD1 ;ĺäčíčöű Îě
call DispBCD
call DispDot
movlw BCD1
call DispBCD
movlw BCD0
call DispBCD
movlw BCD0
call DispBCD
call DispSP
movlw 1 ;çíŕę îě
call CharLCD
end_disp
banksel PORTC
bsf PORTC, Cap_Discharge ;âęë. đŕçđ˙ä Ńő
call Delay_05_sec
banksel PORTC
bcf PORTC, Cap_Discharge ;âűęë. đŕçđ˙ä Ńő
goto ESR_measure
;Äë˙ ňĺńňčđîâŕíč˙ - âűâîä ŔÖĎ áĺç îáđŕáîňęč
;ńđŕçó 2-ő ęŕíŕëîâ (1 č 10 Îě)
tst_ESR
call SecLine
;ęŕíŕë 1 Îě
movlw LOW _tst_1
call Read_String
call ClrA
movf U330_H,W ;óńčëčňĺëü Ęó=330, ďđĺäĺë 1 Îě
movwf AARGB1
movf U330_L,W
movwf AARGB2
call BCD
movlw BCD1
call Disp_Full
;ęŕíŕë 10 Îě
movlw LOW _tst_10
call Read_String
call ClrA
movf U33_H,W ;óńčëčňĺëü Ęó=33, ďđĺäĺë 10 Îě
movwf AARGB1
movf U33_L,W
movwf AARGB2
call BCD
movlw BCD1
call Disp_Full
btfsc PORTA, Kn_Set ;ďđîâĺđęŕ ęíîďęč óńňŕíîâęč íóë˙
goto end_disp
;Ńîőđŕíĺíčĺ U0 â EEPROM ------------------------
call CursorHome
movlw LOW _write_U0
call Read_String
;U0 äë˙ l Îě
call ClrA
movf U330_H,W ;óńčëčňĺëü Ęó=330, ďđĺäĺë 1 Îě
movwf AARGB0
movf U330_L,W
movwf AARGB1
call FLO1624 ;to 24 bit floating point
call BEQUA
movlw LOW U0_ESR_1
movwf Const_ADR
call Save_Const
;U0 äë˙ l0 Îě
call ClrA
movf U33_H,W ;óńčëčňĺëü Ęó=33, ďđĺäĺë 10 Îě
movwf AARGB0
movf U33_L,W
movwf AARGB1
call FLO1624 ;to 24 bit floating point
call BEQUA
movlw LOW U0_ESR_10
movwf Const_ADR
call Save_Const
call Delay_3_sec
call ClrDSP
movlw LOW _ready
call Read_String
call Delay_1_sec
goto end_disp
;------------------------- TMR1 -------------------------
;Číčöčŕëčçŕöč˙ ňŕéěĺđŕ TMR1, řŕă ń÷ĺňŕ = 0.2 ěęń
TMR1_init
clrf TMR1L
clrf TMR1H
bcf PIR1, TMR1IF
movlw b'00000000'; 1:1 Fosc/4
movwf T1CON
clrf TMR1_Count
return
;------------------------- TMR1 -------------------------
;Óâĺëč÷čňü ń÷ĺň÷čę ďĺđĺďîëíĺíčé TMR1
Inc_count
bcf PIR1, TMR1IF ;î÷čůŕĺě ôëŕă ďĺđĺďîëíĺíč˙ ňŕéěĺđŕ
incfsz TMR1_Count,F
return
bsf Flags,0 ;Time out
goto stop_TMR1;çŕ îňâĺäĺííîĺ âđĺě˙ čçěĺđĺíč˙ íĺ äîćäŕëčńü îęîí÷ŕíč˙ çŕđ˙äŕ
;------------------------- TMR0 -------------------------
;Číčöčŕëčçŕöč˙ ňŕéěĺđŕ TMR0, řŕă ń÷ĺňŕ = 0.2 ěęń
TMR0_init
movlw Max_Count
movwf TMR0_Count ;íŕ÷ŕëüíîĺ çíŕ÷ĺíčĺ ń÷ĺň÷čęŕ ďĺđĺďîëíĺíčé TMR0
clrf TMR0 ;clear timer
movlw OPTION_REG ;Work around the OPTION
movwf FSR ;address OPTION_REG -> FSR
movlw b'00000111' ; set up timer. 1:256 presc
movwf INDF
bcf INTCON,T0IF ;clear tmr0 int flag
bsf INTCON,T0IE ;enable TMR0 int
bsf INTCON,GIE ;enable global interrupts
clrf TMR0 ;start timer
return
;------------------------- Delay -------------------------
; Ďîäďđîăđŕěěű ďŕóç
Delay_3_sec ;Ďŕóçŕ 3 ńĺę
Dly24 D'937499' ; 3/(4/20000000)/16=937500-1=937499
goto DoDly24
Delay_2_sec ;Ďŕóçŕ 2 ńĺę
Dly24 D'624999' ; 2/(4/20000000)/16=625000-1=624999
goto DoDly24
Delay_1_sec ;Ďŕóçŕ 1 ńĺę
Dly24 D'312499' ; 1/(4/20000000)/16=312500-1=312499
goto DoDly24
Delay_05_sec ;Ďŕóçŕ 0.5 ńĺę
Dly24 D'156249' ; 0.5/(4/20000000)/16=156250-1=156249
goto DoDly24
Delay_5_ms ;Ďŕóçŕ 5 ěń
Dly24 D'1562' ; 0.005/(4/20000000)/16=1562.5=1562
goto DoDly24
Delay_200_us ;Ďŕóçŕ 200 ěęń
Dly24 D'62' ; 0.0002/(4/20000000)/16=62.5=62
goto DoDly24
DoDly24 ;16 Tcy per loop
movlw H'FF' ;Start with -1 in W
addwf Dly0,F ;LSB decrement
btfsc STATUS,C ;was the carry flag set?
clrw ;If so, 0 is put in W
addwf Dly1,F ;Else, we continue.
btfsc STATUS,C
clrw ;0 in W
addwf Dly2,F
btfsc STATUS,C
clrw ;0 in W
iorwf Dly0,W ;Inclusive-OR all variables
iorwf Dly1,W ;together to see if we have reached
iorwf Dly2,W ;0 on all of them.
btfss STATUS,Z ;Test if result of Inclusive-OR's is 0
goto DoDly24
return
Delay_20_us
movlw 0x1F ;Çŕäĺđćęŕ 20 ěęń
Delay_go
movwf Dly0
decfsz Dly0,F
goto $-1
nop
nop
return
;---------------------- LCD ---------------------
; Ďĺđĺâîä óęŕçŕňĺë˙ íŕ âňîđîé ńčěâîë âňîđîé ńňđîęč
SecLine movlw 0xC0
; Çŕăđóçęŕ ęîěŕíäű
CmdLCD movwf Temp4
; bcf _RS
swapf Temp4, W
andlw 0x0F
movwf PORTB
bsf _E
nop
nop
nop
bcf _E
movf Temp4, W
andlw 0x0F
movwf PORTB
bsf _E
nop
nop
nop
bcf _E
; clrf PORTB
call Delay_200_us
return
; Ďĺđĺęîäčđîâęŕ â ASCII č âűâîä
NumLCD andlw 0x0F ; ěŕńęŕ
iorlw 0x30 ; ASCII
; Âűâîä ASCII ńčěâîëŕ
CharLCD movwf Temp4
SendLCD swapf Temp4, W
andlw 0x0F
iorlw b'00010000' ; RS=1
movwf PORTB
bsf _E
nop
nop
nop
bcf _E
movf Temp4, W
andlw 0x0F
iorlw b'00010000' ; RS=1
movwf PORTB
Send bsf _E
nop
nop
nop
bcf _E
clrf PORTB
call Delay_200_us
return
CursorHome movlw 0x02 ; Äčńďëĺé â čńőîäíîĺ ńîńňî˙íčĺ
goto LongSend
ClrDSP movlw 1 ; Î÷čńňęŕ äčńďëĺ˙
LongSend call CmdLCD
goto Delay_5_ms
DispDot movlw "."
goto CharLCD
Disp0 movlw "0"
goto CharLCD
DispSP movlw " "
goto CharLCD
;-----------------------------------------------------------
;×ňĺíčĺ ńňđîęč čç ňŕáëčöű č âűâîä íŕ LCD
Read_String
movwf Count1
decf Count1,F ;ęîđđĺęöč˙ íŕ÷ŕëüíîăî ńěĺůĺíč˙
movlw HIGH Table
movwf PCLATH
get_next_s
movf Count1,W
call Table
andlw 0xFF ; ďđîâĺđęŕ íŕ ęîíĺö ńňđîęč
btfsc STATUS, Z
return
call CharLCD
incf Count1,F
goto get_next_s
;---------------------- Load CGRAM LCD ---------------------
;çŕăđóçčňü çíŕęîăĺíĺđŕňîđ
Load_ZG
movlw b'01001000' ; AC in CGRAM=8
call CmdLCD
movlw HIGH Table
movwf PCLATH
movlw .16 ;2 çíŕęŕ ďî 8 áŕéň
movwf Count1
movlw LOW omega-1
movwf Count2 ;ńěĺůĺíčĺ â ňŕáëčöĺ
get_s call Table ;ďîëó÷čňü ńčěâîë čç ňŕáëčöű
call CharLCD
incf Count2,F
movf Count2,W
decfsz Count1,F
goto get_s
return
;----------------------------------------------------------
;âűâîä čç ďĺđĺäŕííîăî â W ŕäđĺńŕ áëîęŕ BCD0...4
;íŕ číäčęŕňîđ
Disp_Full
movwf FSR ;ŕäđĺń ˙÷ĺéęč äë˙ âűâîäŕ íŕ LCD
next_byte
swapf INDF,W
call NumLCD
movf INDF,W
call NumLCD
;ďđîâĺđčě, äîáđŕëčńü ëč ěű äî BCD0
movlw BCD0
subwf FSR,W
btfsc STATUS,Z
return
decf FSR,F
goto next_byte
;---------------------- BCD to LCD ---------------------
; Âűâîä đŕçđ˙äŕ č ďîäăîňîâęŕ ę âűâîäó ńëĺäóţůĺăî
DispBCD movwf FSR
NextNibble swapf INDF,F
movf INDF,W
btfss Flags,1 ;1 - íĺ âűâîäčňü ëčäčđóţůčĺ íóëč
goto chk_NZ
andlw 0x0F
btfsc STATUS,Z
return ;ďđîďóńę âűâîäŕ
bcf Flags,1 ; ýňó č âńĺ ďîńäĺäóţůčĺ öčôđű âűâîäčě
chk_NZ
btfss Flags,3 ; 1- âűâîäčňü ňîëüęî NZ đŕçđ˙äîâ, îńňŕëüíűĺ - 0
goto NumLCD
movf NZ,F
btfsc STATUS,Z ;ń÷ĺň÷čę=0?
goto Disp0 ;äŕ, âűâîäčě 0
decf NZ,F ;íĺň, âűâîäčě ňî ÷ňî ĺńňü
call NumLCD
return
;---------------------- BCD ---------------------
; Ďĺđĺęîäčđîâęŕ çíŕ÷ĺíč˙ čç äâîč÷íîăî â äĺń˙ňč÷íűé ôîđěŕň
BCD movlw 0x20
movwf T1
clrf BCD0
clrf BCD1
clrf BCD2
clrf BCD3
clrf BCD4
BcdLoop rlf AARGB2, F
rlf AARGB1, F
rlf AARGB0, F
rlf AEXP, F
rlf BCD0, F
rlf BCD1, F
rlf BCD2, F
rlf BCD3, F
rlf BCD4, F
decfsz T1, F
goto Adjust
return
Adjust movlw .5
movwf Count2
movlw BCD0
movwf FSR
goto ADloop+1
ADloop incf FSR, F
call Adjbcd
decfsz Count2, F
goto ADloop
goto BcdLoop
Adjbcd movlw 0x03
addwf INDF, W
movwf T0
btfsc T0, 3
movwf INDF
movlw 0x30
addwf INDF, W
movwf T0
btfsc T0, 7
movwf INDF
return
;-------------------------------------------------------
; Ęîďčđîâŕíčĺ "ďî íŕçíŕ÷ĺíčţ" áëîęŕ (4 áŕéňŕ) äŕííűő
; Temp1 = ŕäđĺń ďîëó÷ŕňĺë˙ - óęŕçűâŕĺňń˙ ńňŕđřčé ŕäđĺń áëîęŕ
; Temp2 = ŕäđĺń čńňî÷íčęŕ - óęŕçűâŕĺňń˙ ńňŕđřčé ŕäđĺń áëîęŕ
;CEQUA movlw CX ; C=A
Copy_From_A
movwf Temp1 ; Xw=A
movlw AEXP
movwf Temp2
goto Copy
BEQUA movlw AEXP ; B=A
Copy_To_B movwf Temp2 ; B=Xw
movlw BEXP
goto Copy_B
;AEQUF movlw FX ; A=F
Copy_To_A
movwf Temp2 ; A=Xw
movlw AEXP
Copy_B movwf Temp1
Copy movlw 4 ; Îáú¸ě áëîęŕ
movwf Count1
Copy_Loop
movf Temp2, W
movwf FSR
movf INDF, W
movwf Temp3
movf Temp1, W
movwf FSR
movf Temp3, W
movwf INDF
decf Temp1, F ; äâčăŕĺěń˙ â ńňîđîíó óěĺíüřĺíč˙
decf Temp2, F ; ŕäđĺńîâ
decfsz Count1, F
goto Copy_Loop
return
;-------------------------------------------------------
X_To_B call EEPROM_To_B ; Çŕăđóçęŕ ęîýôôčöčĺíňŕ X
call ASwapB
call FLO2424
call FPM24
return
ASwapB movlw T5
call Copy_From_A
movlw BEXP
call Copy_To_A
movlw T5
call Copy_To_B
return
;-------------------------------------------------------
; Î÷čńňęŕ áëîęîâ Ŕ č Â
ClrB movlw BEXP ; Î÷čńňęŕ áëîęŕ Â
goto ClrA+1
ClrA movlw AEXP ; Î÷čńňęŕ áëîęŕ Ŕ
movwf FSR
movlw 4 ;Îáúĺě áëîęŕ
movwf Count1
ClrLoop
clrf INDF ; Öčęë î÷čńňęč
decf FSR, F ; óěĺíüřŕĺě ŕäđĺń
decfsz Count1, F
goto ClrLoop
return
;-------------------------------------------------------
; ×ňĺíčĺ äŕííűő čç EEPROM â áëîę B
EEPROM_To_B
movwf EE_ADR ; Ńîőđŕí˙ĺě ŕäđĺń ˙÷ĺéęč EEPROM
movlw BEXP
movwf FSR
movlw 4 ;Îáúĺě áëîęŕ
movwf Count1
EE_read_loop
call ReadEEPROM
banksel BEXP
movwf INDF
incf EE_ADR, F
decf FSR, F
decfsz Count1, F
goto EE_read_loop
return
; ×ňĺíčĺ EEPROM
ReadEEPROM
movf EE_ADR,W ;
banksel EEADR ; áŕíę 2
movwf EEADR ; ŕäđĺń ˙÷ĺéęč EEPROM
banksel EECON1 ; áŕíę3
bcf EECON1,EEPGD ;âűáđŕňü EEPROM
bsf EECON1,RD ;číčöčŕëčçđîâŕňü ÷ňĺíčĺ
banksel EEDATA ; áŕíę2
movf EEDATA,W ; W = EEDATA
return
;-------------------------------------------------------
; Çŕďčńü áëîęŕ BARG â EEPROM
; Ŕäđĺń â EEPROM çŕäŕĺňń˙ â Const_ADR
Save_Const
movf Const_ADR,W
movwf EE_ADR
movlw BEXP
movwf FSR
movlw 4 ;Îáúĺě áëîęŕ
movwf Count1
EE_write_loop
movf INDF,W
movwf EE_DATA
call WriteEEPROM
banksel BEXP
incf EE_ADR, F
decf FSR, F
decfsz Count1, F
goto EE_write_loop
return
; Çŕďčńü EEPROM
WriteEEPROM
banksel EECON1 ;áŕíę3
btfsc EECON1,WR
goto $-1
banksel EEADR ;áŕíę2
movf EE_ADR,W
movwf EEADR
movf EE_DATA,W
movwf EEDATA
banksel EECON1
bcf EECON1,EEPGD
bsf EECON1,WREN
movlw 0x55
movwf EECON2
movlw 0xAA
movwf EECON2
bsf EECON1,WR
bcf EECON1,WREN
return
;-------------------------------------------------------
; Číęđĺěĺíňčđîâŕíčĺ ďîëóáëîęŕ B
IncB
bsf Flags,5 ;óńňŕíŕâëčâŕĺě ôëŕă čçěĺíĺíč˙ ęîíńňŕíňű
incf BARGB2, F
btfsc STATUS, Z
incf BARGB1, F
goto ShowX
; Äĺęđĺěĺíňčđîâŕíčĺ ďîëóáëîęŕ B
DecB
bsf Flags,5 ;óńňŕíŕâëčâŕĺě ôëŕă čçěĺíĺíč˙ ęîíńňŕíňű
movf BARGB2, F
btfsc STATUS, Z
decf BARGB1, F
decf BARGB2, F
ShowX
movlw BEXP
call Copy_To_A
call BCD
call SecLine
movlw BCD1
call DispBCD
call DispDot
movlw BCD1
call DispBCD
movlw BCD0
call DispBCD
movlw BCD0
call DispBCD
call Delay_05_sec
return
;=======================================================
;
PIC16 24 BIT FLOATING POINT LIBRARY
#define P16_MAP1 0
#define P16_MAP2 1
include "math16.inc"
include "fp24.a16"
END