; ; Measuring instrument RLC ; ; Author xxxx ; Version 1.0 ; Date 09/07/2007 ; ; ASSIGNMENT OF THE CONTROLLER PINs PIC16F873A ;*************************************************************************************** ;*PIN * NAME * DESIGNATION ;*************************************************************************************** ; 1 * MCLR/Vpp * Dump ; 2 * RA0/AN0 * ADC input ; 3 * RA1/AN1 * input Ubat * 2/(2+13) ; 4 * RA2/AN2/Vref- * Kn Freq/Set ; 5 * RA3/AN3/Vref+ * Ref 2.5V ; 6 * RA4/T0CKI * Kn posl.-parall. SZ/"+" ; 7 * RA5/AN4/SS * Kn mode of display RLC-Z-Y-Q- D/"-" ; 8 * Vss * GND ; 9 * OSC1/CLKIN * Quartz 20 MHz ; 10 * OSC2/CLKOUT * Quartz 20 MHz ; 11 * RC0/T1OSO/T1CKI * ; 12 * RC1/T1OSI/CCP2 * Sine 100 / 1000 Hz (SHIM) ; 13 * RC2/CCP1 * "0" - __=1, "1" - __=10 - the first cascade ; 14 * RC3/SCK/SCL * "0" - __=1, "1" - __=10 - the second cascade ; 15 * RC4/SDI/SDA * Divider "0" - 100Hz "1" - 1kHz ; 16 * RC5/SDO * "0" - the voltage, "1" - the current ; 17 * RC6/TX/CK * "0" - 100 Ohms, "1" - 100k current-sensing device ; 18 * RC7/RX/DT * "0" - PWR OFF, "1" - PWR ON ; 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_Freq equ 2 Kn_F_P equ 4 Kn_Disp equ 5 Kn_ALL_UP equ b'00110100' Port_B_Config equ b'11000000' Port_C_Config equ b'00000001' ; Port C bit equates Kg_1 equ 2 ;first amplifier 0-__=1, 1-__=10 Kg_2 equ 3 ;second amplifier 0-__=1, 1-__=10 f_100_1k equ 4 ;Divider "0" - 100Hz "1" - 1kHz U_I equ 5 ;measurement 0-U, 1-I Rsh equ 6 ;resistance R for current measuring 0-100 Ohms, 1-100kOhms PWR_ON equ 7 ;"0" - PWR OFF, "1" - PWR ON Sine_out equ 1 ;**************************************************************************************** list p=PIC16F873a #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 _RS PORTB,4 #define _E PORTB,5 ;Value of the bits Flags go_m equ 0 ;Command to launch of the series of measurements, ;it is installed in the program, is dropped at processing of interruption start_m equ 1 ;launch of sequence of 20th measurements BH.signal ;it is installed and is dropped _____ interruption freq equ 2 ;0-100Hz, 1-1kHz f_p equ 3 ;0- sequential equivalent circuit, 1- parallel long_btn equ 4 ;long pressure calibr equ 5 ;mode open/short of the calibration debug equ 6 ;Mode of debugging L_Z equ 7 ;used for clearing of leading zero ; For a mode of installation of constants: const_change equ 2 ;constant changed ;Value of bits Flags_.D d_RLC equ 0 ;Display R and L/C d_Z equ 1 ;Display the impedance d_Y equ 2 ;Display the complex conductivity d_Q equ 3 ;Display the Q d_D equ 4 ;Display the loss tangent ;d_UI equ 3 ;Display voltage and current (for the test) CBLOCK 0x35 ;0x20-0x34 for FLOATING POINT LIBRARY ; Blocks of the data Flags Sine_step Sine_val Dly0 ;Stores 3 bytes of data for the delay count Dly1 ;Dly0 is the least significant byte Dly2 ;while Dly2 is the most significant byte BCD0 ; Low-order byte BCD1 BCD2 BCD3 BCD4 ; High-order byte T0 T1 Temp_LCD Count1 Count2 Temp1 Temp2 Temp3 NZ ; number of significant places for the output to the display Count_ADC ; counter of the number of ADC measurements ;Variables for storage intermediate ????? calculation X3 X2 X1 X0 Y3 Y2 Y1 Y0 ;-------------------------- ;Variables for the DFT calculation U_Re3 ;voltage, real part, low-order byte U_Re2 U_Re1 U_Re0 ;voltage, real part, high-order byte U_Im3 ;voltage, imaginary part, low-order byte U_Im2 U_Im1 U_Im0 ;voltage, imaginary part, high-order byte I_Re3 ;Current, real part, the low-order byte I_Re2 I_Re1 I_Re0 ;Current, real part, the high-order byte I_Im3 ;Current, imaginary part, the low-order byte I_Im2 I_Im1 I_Im0 ;Current, imaginary part, the high-order byte Z_Re3 ;Resistance, real part, the low-order byte Z_Re2 Z_Re1 Z_Re0 ;Resistance, real part, the high-order byte Z_Im3 ;Resistance, imaginary part, the low-order byte Z_Im2 Z_Im1 Z_Im0 ;Resistance, imaginary part, the high-order byte Num_p ;Number of a point f_tmp f_tmp2 ;-------------------------- EE_ADR ;auxiliary cell for work with EEPROM EE_DATA K_U ;K_U strengthening with the measurement of the voltage (1-__=1, 2-__=10, 3-__=100) K_I ;K_I strengthening with the measurement of the current (1-__=1, 2-__=10, 3-__=100) ENDC CBLOCK 0x71 ;Preservation of context at interruptions STATUS_TEMP PCLATH_TEMP W_TEMP ;------------- Flags_D ENDC CBLOCK 0xF1 W_TEMP1 ;Preservation of context at interruptions ENDC CBLOCK 0xA0 ADC_val:2*.20 ;Block For preservation 20?? Of measurements ADC Btn_old ; old state of the buttons Btn_now Btn_sw ; wear and tear of the buttons Btn_time1 Btn_time2 Auto_off_time ENDC ;========================= ; MACROS ;========================= Dly24 MACRO DLY ;Take the delay value argument from the macro, precalculate ;the required 3 RAM values and load 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 ; Region EEPROM ; Given ; Address in EEPROM K_E_1 DE 0x7B, 0x4C, 0xCC, 0xCD ;0.1 K_E_2 DE 0x78, 0x23, 0xD7, 0x0A ;0.01 ;K-T is increased by 1000, since K-T for voltage (USR_100) is also increased by 1000 K_Rsh_0 DE 0x81, 0x24, 0x1A, 0x42 ; (1/195)*1000=5.12820512 ;WARNING: 195 is 100 + Ron of the multiplexer DA4.1. ;We have to change the design at this point and modify K_Rsh_0 value for (1/100)*1000=10 K_Rsh_1 DE 0x78, 0x23, 0xD7, 0x0A ; (1/100000)*1000=0.01 w_100 DE 0x88, 0x1D, 0x14, 0x62 ;2*Pi*f=6283,185307 (for 1kHz) w_1000 DE 0x8B, 0x44, 0x59, 0x7C ;2*Pi*f=6283,185307 (for 1kHz) ;Constants for compensating the input impedance ;for 100Hz Zs_Re_100 DE 0, 0, 0, 0 ;Short Zs_Im_100 DE 0, 0, 0, 0 ;Short Yo_Re_100 DE 0, 0, 0, 0 ;Open Yo_Im_100 DE 0, 0, 0, 0 ;Open ;for 1kHz Zs_Re_1k DE 0, 0, 0, 0 ;Short Zs_Im_1k DE 0, 0, 0, 0 ;Short Yo_Re_1k DE 0, 0, 0, 0 ;Open Yo_Im_1k DE 0, 0, 0, 0 ;Open USR_100 dt 0x00, 0x00, 0x03, 0xE8 ; 0x3E8=1000 USR_100k dt 0x00, 0x00, 0x03, 0xE8 ; 0x3E8=1000 K_Ubat dt 0x79, 0x16, 0x28, 0xCC ; k=9V/491=0.01822 org 0x00 ;******************************************************************************* ; BEGINNING OF THE PROGRAM ;******************************************************************************* nop ;for MPLAB-ICD2 goto init ;------------------ Interrupt ------------------ org 0x004 movwf W_TEMP ;save W swapf STATUS,W ;swap STATUS, W clrf STATUS ;bank 0 movwf STATUS_TEMP ;save status movf PCLATH,W movwf PCLATH_TEMP ;save PCLFTH pagesel $ call Load_Sine_Val btfss Flags, start_m goto tst_go_m ;--- ADC --- bsf ADCON0,GO ;begin the analog-to-digital conversion btfsc ADCON0,GO goto $-1 ; we await the ends of the conversion ;we preserve with the accumulation the result of the measurements incf FSR, F ;indicator to the low-order byte banksel ADRESL movf ADRESL,W addwf INDF, F ; we add the low-order byte decf FSR, F ; indicator to the high-order byte btfsc STATUS, C ; there was transfer during the addition? incf INDF, F ; we increase the high-order byte banksel ADRESH movf ADRESH,W addwf INDF, F ; we summarize the high-order byte incf FSR incf FSR ; indicator to the track to vapor of the registers decfsz Count_ADC, F goto btn_check movlw ADC_val ; beginning of the block of the measurements movwf FSR ; we prepare indicator to the block of the results of the measurements movlw .20 ; on 20 measurements for the period movwf Count_ADC ;the number of measurements ADC during the period decfsz Num_p, F ;the number of periods goto btn_check ;measurements are finished, we discard the flags bcf Flags, start_m bcf Flags, go_m tst_go_m ;synchronization of the installation of flag of the starting of measurements on the beginning of the period btfss Flags, go_m goto btn_check movlw .1 ; if Sine_step=1, then this subwf Sine_step,W ; the last point of sine, in the following interruption btfsc STATUS, Z ; there will be Sine_step=20 bsf Flags, start_m ;To establish a flag of start of a cycle ????? btn_check ;working buttons, a somewhat simplified version bsf STATUS, RP0 ;bank 1 incfsz Btn_time1, F goto restore_context ;255 calls we pass clrf STATUS ;bank 0 movf PORTA, W ; 50us*255=12,75 ms (for 1 kHz) bsf STATUS, RP0 ;bank 1 andlw Kn_ALL_UP ;we separate the bits of the keyboard movwf Btn_now ;let us memorize the current state of the buttons subwf Btn_old, W ;W = Btn_old - Btn_now btfss STATUS, C goto btn_up ;old < now btfss STATUS, Z ;old >= now goto btn_end movlw Kn_ALL_UP subwf Btn_now, W btfsc STATUS, Z goto btn_end ;all buttons are tempered decfsz Btn_time2 ; we count the time of the retention of the button goto btn_end bcf STATUS, RP0 ;bank 0 movlw .80 btfss Flags, freq movlw .8 ;for 100 Hz bsf STATUS, RP0 ;bank 1 movwf Btn_time2 ; the platoon of the flag of the "long" pressure bcf STATUS, RP0 ;bank 0 bsf Flags, long_btn goto btn_end btn_up ;button was pulled movf Btn_old, W movwf Btn_sw bcf STATUS, RP0 ;bank 0 movlw .80 btfss Flags, freq movlw .8 ;for 100 Hz bsf STATUS, RP0 ;bank 1 movwf Btn_time2 btn_end movf Btn_now, W movwf Btn_old restore_context clrf STATUS ;bank 0 bcf PIR1,CCP1IF ;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 INTCON clrf PCLATH clrf PORTA clrf PORTB clrf PORTC clrf Flags_D clrf Flags ;Initial installations: movlw 1< 1ms/20 = 50us, 50us/0.2 = 250 movwf CCPR1L movlw b'00001011' ;mode of comparison, the trigger is ??????? movwf CCP1CON banksel PIE1 movlw b'00000100' ;permission of interruption from module CCP1 movwf PIE1 banksel INTCON movlw b'11000000' ;interruptions permission from ??????? modules movwf INTCON ;================================================ Measure ;================================================ ; Measurement of the voltage ;------------------------------------------------ Measure_U bcf PORTC, U_I ;0-U, 1-I call Set_Kg ;To establish ???? to K-T strengthening call Delay_5_ms call Delay_5_ms call Delay_5_ms call Delay_5_ms call Delay_5_ms call Delay_5_ms call Delay_5_ms call Delay_5_ms call Delay_5_ms call Make_ADC call Chk_m ; control of the measurements iorlw 0 ;0 - measurement in the range, 1 - shortage, 2 - sorting btfss STATUS, Z goto u_2 u_1 call DFT ;calculation of the real and imaginary part of the voltage goto Measure_I u_2 xorlw 1 btfss STATUS, Z goto u_3 ;2-sorting call Inc_K_U ;1-shortage iorlw 0 btfsc STATUS, Z goto u_1 ;0-increase further nowhere, to accept measurement as there is goto Measure_U u_3 call Dec_K_U ; 0 - error, 1-OK iorlw 0 btfss STATUS, Z goto Measure_U call ClrDSP movlw "U" call CharLCD call DispSP movlw LOW _ADC_ovl call Read_String call Delay_05_sec goto Measure_U ;================================================ ; Measurement of the current ;------------------------------------------------ Measure_I bsf PORTC, U_I ;0-U, 1-I call Set_Kg ;To establish ???? to K-T strengthening call Delay_5_ms call Delay_5_ms call Delay_5_ms call Delay_5_ms call Delay_5_ms call Delay_5_ms call Delay_5_ms call Delay_5_ms call Delay_5_ms call Make_ADC call Chk_m ; control of the measurements iorlw 0 ;0 - measurement in the range, 1 - shortage, 2 - sorting btfss STATUS, Z goto i_2 i_1 call DFT ;calculation of the real and imaginary part of the current goto mlt_0 i_2 xorlw 1 btfss STATUS, Z goto i_3 ;2-sorting call Inc_K_I ;1-shortage iorlw 0 btfsc STATUS, Z goto i_1 ;0-increase further nowhere, to accept measurement as there is xorlw 1 btfss STATUS, Z goto Measure_U ;2-Ku is increased due to ????. Rsh, all measurements all over again goto Measure_I ;1-Ku is increased without ????. Rsh, we measure the current repeatedly i_3 call Dec_K_I iorlw 0 btfss STATUS, Z goto Measure_I call ClrDSP movlw "I" call CharLCD call DispSP movlw LOW _ADC_ovl call Read_String call Delay_05_sec goto Measure_I ;---------------------------------------------- ;Is multiplied U,I to the scaling K-T mlt_0 ; We consider Rsh=100Ohms -> _=0.01, Rsh=100kOhms -> _=0.00001 movlw I_Re0 ;real part of the current movwf f_tmp ;sokhraneyaem the address of the first number movlw low K_Rsh_1 ;100 kOhms btfss PORTC, Rsh ;0-100 Ohms, 1-100 kOhms movlw low K_Rsh_0 ;100 Ohms movwf f_tmp2 ;address of the second coefficient in EEPROM call Mult ;we scale I_Re movlw I_Im0 ;imaginary part of the current movwf f_tmp ;???? address of the first number call Mult ;we scale I_Im ; We consider K_U and K_I ; current movlw 2 subwf K_I, W btfss STATUS, Z goto mlt_1 movlw LOW K_E_1 movwf f_tmp2 goto mlt_2 mlt_1 movlw 3 subwf K_I, W btfss STATUS, Z goto mlt_3 movlw LOW K_E_2 movwf f_tmp2 mlt_2 movlw I_Re0 movwf f_tmp call Mult movlw I_Im0 movwf f_tmp call Mult ;the voltage mlt_3 ;we multiply to the correction user K-T for Rsh=100Ohms or 100kOhms movlw LOW USR_100k btfss PORTC, Rsh movlw LOW USR_100 movwf f_tmp2 movlw U_Re0 movwf f_tmp call Mult_int movlw U_Im0 movwf f_tmp call Mult_int movlw 2 subwf K_U, W btfss STATUS, Z goto mlt_4 movlw LOW K_E_1 movwf f_tmp2 goto mlt_5 mlt_4 movlw 3 subwf K_U, W btfss STATUS, Z goto mlt_6 movlw LOW K_E_2 movwf f_tmp2 mlt_5 movlw U_Re0 movwf f_tmp call Mult movlw U_Im0 movwf f_tmp call Mult mlt_6 ;----------------------------------------------- ; ???? keyboard ; RA2 - 100/1000 Hz ; RA4 - sequential / parallel SZ ; RA5 - RLC, Z, Y banksel Btn_sw movlw Kn_ALL_UP subwf Btn_sw, W btfsc STATUS, Z goto bt_end ; buttons were not pressed banksel Flags btfss Flags, long_btn goto bt_5 bcf Flags, long_btn banksel Btn_sw btfsc Btn_sw, Kn_F_P goto bt_4 banksel Flags ;We include mode OPEN of calibration bsf Flags, f_p ; parallel SZ bt_3 clrf Flags_D bsf Flags_D, d_RLC ; Display RLC bsf Flags, calibr ;we establish the flag of calibration goto bt_end bt_4 btfsc Btn_sw, Kn_Disp goto bt_4a banksel Flags ;We include mode SHORT of calibration bcf Flags, f_p ; sequential SZ goto bt_3 bt_4a btfsc Btn_sw, Kn_Freq goto bt_end banksel Flags ; We include a mode ???? movlw 1 << debug xorwf Flags, F ;we invert the bit goto bt_end bt_5 btfss Flags, calibr goto bt_7 bcf Flags, calibr banksel Btn_sw btfsc Btn_sw, Kn_Freq goto bt_7 call Save_Zin ;Preservation of input impedance in EEPROM call ClrDSP movlw LOW _Saved call Read_String banksel Btn_sw movlw Kn_ALL_UP movwf Btn_sw banksel Flags goto Disp_end_2 ;----------- bt_7 banksel Btn_sw movf Btn_sw, W banksel Temp1 movwf Temp1 btfsc Temp1, Kn_Freq ;100/1000 Hz goto bt_1 movlw 1 << freq xorwf Flags, F ;we invert the bit of the frequency call set_freq bt_1 btfsc Temp1, Kn_F_P ;sequential / parallel SZ goto bt_2 movlw 1 << f_p xorwf Flags, F ;we invert the bit bt_2 btfsc Temp1, Kn_Disp ;RLC, Z, Y goto bt_end btfss Flags_D, d_D ; the last version goto next_disp movlw 1 movwf Flags_D goto bt_end next_disp bcf STATUS, C rlf Flags_D, F bt_end banksel Btn_sw movlw Kn_ALL_UP movwf Btn_sw banksel Flags ;----------------------------------------------- ; Calculation Zx, Yx btfss Flags, calibr ;calibration compensation we do not consider for the mode goto calc_comp btfsc Flags, f_p ;0-the series circuit of the substitution, 1-parallel call Swap_UI ;For the parallel diagram we change by the places U and I call Div_UI ;we divide U/I, we obtain the impedance Z or the conductivity Y goto mlt_7 calc_comp call Div_UI ;we divide U/I, we obtain the impedance Z or the conductivity Y call Comp_Zin ; the compensation for the input impedance mlt_7 ;------ Display the results of the measurements ------ call ClrDSP btfss Flags, f_p goto chk_f btfss Flags_D, d_RLC goto $+2 goto Disp_RLC_p ;Display RLC, parallel SZ btfss Flags_D, d_Z goto $+2 goto Disp_Z_p ;Display Z parallel SZ btfss Flags_D, d_Y goto $+2 goto Disp_Y_p ;Display Y, parallel SZ btfss Flags_D, d_Q goto Disp_D_p ;Display D, parallel SZ goto Disp_Q_p ;Display Q, parallel SZ chk_f btfss Flags_D, d_RLC goto $+2 goto Disp_RLC_f ;Display RLC, sequential SZ btfss Flags_D, d_Z goto $+2 goto Disp_Z_f ;Display Z sequential SZ btfss Flags_D, d_Y goto $+2 goto Disp_Y_f ;Display Y, sequential SZ btfss Flags_D, d_Q goto Disp_D_f ;Display D, sequential SZ goto Disp_Q_f ;Display Q, sequential SZ ;------ for the test - Display U and I ------ ;Disp_UI ; movlw U_Re0 ; call Disp_val ; call DispSP ; movlw U_Im0 ; call Disp_val ; call SecLine ; movlw I_Re0 ; call Disp_val ; call DispSP ; movlw I_Im0 ; call Disp_val ; goto Disp_end ;------ Display RLC, parallel SZ ------ Disp_RLC_p movlw "R" call CharLCD movlw "p" call CharLCD call DispSP movlw LOW E0 ; number 1 pagesel Prog_To_A call Prog_To_A movlw Z_Re0 call Copy_To_B call FPD32 ;A=A/B pagesel $ call Disp_A movlw 1 ;sign is the omega call CharLCD disp_LC_p call SecLine btfss Z_Im1,7 ; Conductivity: "+" for C, "-" for L goto disp_Cp ; capacity bcf Z_Im1,7 ; inductance, we discard "-" movlw LOW w_1000 ;Lp=1/(w*Bp) btfss Flags, freq ;0-100Hz, 1-1kHz movlw LOW w_100 pagesel EEPROM_To_B call EEPROM_To_B movlw Z_Im0 call Copy_To_A call FPM32 ;A=w*Bp call BEQUA ;B=A movlw LOW E0 ; number 1 call Prog_To_A call FPD32 ;A=A/B pagesel $ movlw "L" call CharLCD movlw "p" call CharLCD call DispSP call Disp_A movlw "H" ;Henry(s) call CharLCD goto Disp_end disp_Cp ;Cp=Bp/w movlw LOW w_1000 ;Lp=1/(w*Bp) btfss Flags, freq ;0-100Hz, 1-1kHz movlw LOW w_100 pagesel EEPROM_To_B call EEPROM_To_B movlw Z_Im0 call Copy_To_A call FPD32 ;A=Bp/w pagesel $ movlw "C" call CharLCD movlw "p" call CharLCD call DispSP call Disp_A movlw "F" ;Farads call CharLCD goto Disp_end ;------ Display Y, parallel SZ ------ Disp_Y_p movlw "G" call CharLCD movlw "p" call CharLCD call DispSP movlw Z_Re0 call Disp_val movlw "S" ;siemens call CharLCD call SecLine movlw "B" call CharLCD movlw "p" call CharLCD call DispSP movlw Z_Im0 call Disp_val movlw "S" ;siemens call CharLCD goto Disp_end ;------ Display Z, parallel SZ ------ Disp_Z_p movlw "R" call CharLCD movlw "p" call CharLCD call DispSP movlw LOW E0 ; number 1 pagesel Prog_To_A call Prog_To_A movlw Z_Re0 call Copy_To_B call FPD32 ;A=A/B pagesel $ call Disp_A movlw 1 ;sign is the omega call CharLCD call SecLine movlw "X" call CharLCD movlw "p" call CharLCD call DispSP movlw LOW E0 ; number 1 pagesel Prog_To_A call Prog_To_A movlw Z_Im0 call Copy_To_B call FPD32 ;A=A/B pagesel $ movlw b'10000000' xorwf AARGB0, F ;we invert the sign -/+ call Disp_A movlw 1 ;sign is the omega call CharLCD goto Disp_end ;------ Display RLC, sequential SZ ------ Disp_RLC_f movlw "R" call CharLCD movlw "s" call CharLCD call DispSP movlw Z_Re0 call Disp_val movlw 1 ;sign is the omega call CharLCD disp_LC_f call SecLine btfss Z_Im1,7 ; Xs: "-" for C, "+" for L goto disp_Ls ; inductance bcf Z_Im1,7 ; capacity, we discard "-" movlw LOW w_1000 ;Cs=1/(w*Xs) btfss Flags, freq ;0-100Hz, 1-1kHz movlw LOW w_100 pagesel EEPROM_To_B call EEPROM_To_B movlw Z_Im0 call Copy_To_A call FPM32 ;A=w*Xs call BEQUA ;B=A movlw LOW E0 ; number 1 call Prog_To_A call FPD32 ;A=1/(w*Xs) pagesel $ movlw "C" call CharLCD movlw "s" call CharLCD call DispSP call Disp_A movlw "F" ;Farads call CharLCD goto Disp_end disp_Ls ;Ls=Xs/w movlw LOW w_1000 btfss Flags, freq ;0-100Hz, 1-1kHz movlw LOW w_100 pagesel EEPROM_To_B call EEPROM_To_B movlw Z_Im0 call Copy_To_A call FPD32 ;A=Xs/w pagesel $ movlw "L" call CharLCD movlw "s" call CharLCD call DispSP call Disp_A movlw "H" ;Henry(s) call CharLCD goto Disp_end ;------ Display Y, sequential SZ ------ Disp_Y_f movlw "G" call CharLCD movlw "s" call CharLCD call DispSP movlw LOW E0 ; number 1 pagesel Prog_To_A call Prog_To_A movlw Z_Re0 call Copy_To_B call FPD32 ;A=A/B pagesel $ call Disp_A movlw "S" ;Siemens call CharLCD call SecLine movlw "B" call CharLCD movlw "s" call CharLCD call DispSP movlw LOW E0 ; number 1 pagesel Prog_To_A call Prog_To_A movlw Z_Im0 call Copy_To_B call FPD32 ;A=A/B pagesel $ movlw b'10000000' xorwf AARGB0, F ;we invert the sign -/+ call Disp_A movlw "S" ;Siemens call CharLCD goto Disp_end ;------ Display Z, sequential SZ ------ Disp_Z_f movlw "R" call CharLCD movlw "s" call CharLCD call DispSP movlw Z_Re0 call Disp_val movlw 1 ;sign is the omega call CharLCD call SecLine movlw "X" call CharLCD movlw "s" call CharLCD call DispSP movlw Z_Im0 call Disp_val movlw 1 ;sign is the omega call CharLCD goto Disp_end ;------ Display Q ------ Disp_Q_p Disp_Q_f movlw "Q" call CharLCD call DispSP pagesel Copy_To_A movlw Z_Im0 call Copy_To_A movlw Z_Re0 call Copy_To_B call FPD32 ;Q=Bp/Gp movlw b'01111111' andwf AARGB0, F ;we take the module of the number pagesel $ call Disp_A btfss Flags, f_p goto disp_LC_f goto disp_LC_p ;------ Display D ------ Disp_D_p Disp_D_f movlw "D" call CharLCD call DispSP pagesel Copy_To_A movlw Z_Re0 call Copy_To_A movlw Z_Im0 call Copy_To_B call FPD32 ;Q=Gp/Bp movlw b'01111111' andwf AARGB0, F ;we take the module of the number pagesel $ call Disp_A btfss Flags, f_p goto disp_LC_f goto disp_LC_p ;------------------------ Disp_val ;normalization and Display value and ???? on the display pagesel Copy_To_A call Copy_To_A pagesel $ call Disp_A return ;------------------------ Disp_end btfss Flags, debug goto Disp_end_1 movlw 0xC0+.13 call CmdLCD movlw "K" btfss PORTC, Rsh movlw 1 ;ohms call CharLCD movf K_U, W call NumLCD movf K_I, W call NumLCD Disp_end_1 movlw 0x80+.13 call CmdLCD movlw LOW _1k btfss Flags, freq movlw LOW _100 call Read_String btfss Flags, calibr goto Disp_end_2 movlw 0xC0+.11 call CmdLCD movlw LOW _open btfss Flags, f_p movlw LOW _short call Read_String Disp_end_2 banksel Auto_off_time incfsz Auto_off_time, F goto Disp_end_3 banksel PORTC bcf PORTC, PWR_ON ; We switch off a feed Disp_end_3 banksel Flags btfsc Flags, freq call Delay_05_sec ; for 100Hz without the delay goto Measure ;=================================== ;Multiplies two numbers ; f_tmp2 - address of the first coefficient in EEPROM ; f_tmp - address of the second coefficient ; The result is kept to the address of, transferred in f_tmp Mult movf f_tmp2, W pagesel EEPROM_To_B call EEPROM_To_B mult_B pagesel Copy_To_A movf f_tmp, W call Copy_To_A call FPM32 movf f_tmp, W call Copy_From_A pagesel $ return ;The same, only the number in f_tmp2 will preliminary be transformed in ;from int in float Mult_int movf f_tmp2, W pagesel EEPROM_To_A call EEPROM_To_A call FLO32 call BEQUA pagesel $ goto mult_B ;====================================================== ; To execute a series from 40 measurements ADC (two periods) ;------------------------------------------------------ Make_ADC pagesel Clr_ADC call Clr_ADC pagesel $ movlw ADC_val movwf FSR ; We prepare the index on the block of results of measurements movlw .20 ; on 20 measurements for the period movwf Count_ADC ;number of measurements ADC during the period movlw .40 ; 40 periods on 1kHz, sootv. 40 ms movwf Num_p ; or two periods 50Hz bsf Flags, go_m ;To execute measurements btfsc Flags, go_m goto $-1 ; expectation of the end of the measurements return ;====================================================== ; Dump of the counter of time of autoswitching-off ;====================================================== Reset_auto_off_time banksel Auto_off_time clrf Auto_off_time banksel STATUS return ;====================================================== ; increase K-T strengthening with the measurement of the current ; Output: 0 - to increase further nowhere ; 1 - __ is increased without perekl. Rsh ; 2 - __ is increased due to perekl. Rsh ;------------------------------------------------------ Inc_K_I movlw 3 subwf K_I, W btfss STATUS, Z goto next_KI btfsc PORTC, Rsh ;0 - R=100 Ohms, 1 - R=100kOhms retlw 0 ;increase K-T is further nowhere call Reset_auto_off_time bsf PORTC, Rsh ; include R=100kOhms movlw 1 movwf K_I ; __=1 retlw 2 ; __ is increased due to perekl. Rsh next_KI call Reset_auto_off_time incf K_I, F retlw 1 ; __ is increased without perekl. Rsh ;====================================================== ; increase K-T strengthening with the measurement of the voltage ; Output: 0 - to increase further nowhere ; 1 - __ is increased without perekl. Rsh ; 2 - __ is increased due to perekl. Rsh ;------------------------------------------------------ Inc_K_U ;If Rsh=100k, then max. __=10, further we switch the shunt to 100 Ohms movlw 2 ;__ max = 10 btfss PORTC, Rsh ;0 - R=100 Ohms, 1 - R=100kOhms movlw 3 ;__ max = 100 subwf K_U, W btfss STATUS, Z goto next_KU btfss PORTC, Rsh ;0 - R=100 Ohms, 1 - R=100kOhms retlw 0 ;increase K-T is further nowhere call Reset_auto_off_time bcf PORTC, Rsh ; R=100 Ohms movlw 1 movwf K_U ; __=1 retlw 2 ; __ is increased due to perekl. Rsh next_KU call Reset_auto_off_time incf K_U, F retlw 1 ; __ is increased without perekl. Rsh ;====================================================== ; To decrease K- T strengthening with the measurement of the current ; Output: 0 -error, to decrease further nowhere ; 1 - __ is reduced ;------------------------------------------------------ Dec_K_I movlw 1 subwf K_I, W btfsc STATUS, Z retlw 0 call Reset_auto_off_time decf K_I, F retlw 1 ;====================================================== ; To decrease K-T strengthening with the measurement of the voltage ; Output: 0 - error, to decrease further nowhere ; 1 - __ is reduced ;------------------------------------------------------ Dec_K_U movlw 1 subwf K_U, W btfsc STATUS, Z retlw 0 call Reset_auto_off_time decf K_U, F retlw 1 ;====================================================== ; To include necessary K-T strengthenings ; 1-1, 2-10, 3-100 ;------------------------------------------------------ Set_Kg movf K_I, W btfss PORTC, U_I ; 0-U, 1-I movf K_U, W movwf Temp1 movlw LOW tbl_go addwf Temp1, F ;8 younger bats of the table of transitions movlw HIGH tbl_go ;5 senior bats btfsc STATUS, C ; There was a transition of border 0xFF byte? addlw 1 ; Yes movwf PCLATH movf Temp1, W tbl_go movwf PCL ;Tabulared transition goto set_1 goto set_10 goto set_100 set_1 bcf PORTC, Kg_1 goto $+1 bcf PORTC, Kg_2 return set_10 bsf PORTC, Kg_1 goto $+1 bcf PORTC, Kg_2 return set_100 bsf PORTC, Kg_1 goto $+1 bsf PORTC, Kg_2 return ;====================================================== ; To establish frequency of generation ; 100 or 1000 Hz ;------------------------------------------------------ set_freq movlw .80 btfss Flags, freq ;0-100Hz, 1-1000Hz movlw .8 banksel Btn_time2 movwf Btn_time2 ;Time of long pressing of buttons banksel Flags btfss Flags, freq ;0-100Hz, 1-1000Hz goto set_100Hz clrf CCPR1H movlw .249 ;F = 1 kHz, T = 1ms, 20 steps => 1ms/20 = 50us, 50us/0.2 = 250 movwf CCPR1L bsf PORTC, f_100_1k return set_100Hz movlw 0x09 ;F = 100 kHz T = 10ms, 20 steps => 10ms/20 = 500us, 500us/0.2 = 2500, 2499 = 0x9C3 movwf CCPR1H movlw 0xC3 movwf CCPR1L bcf PORTC, f_100_1k return ;====================================================== ; The control of measurements ; Output: ; 0 - Measurements in a range, 1 - Shortage, 2 - sorting ; Y0,Y1 - min Y2,Y3 - max ;------------------------------------------------------ Chk_m movlw ADC_val movwf FSR movf INDF, W movwf Y0 ;high-order byte movwf Y2 incf FSR, F movf INDF, W movwf Y1 ;low-order byte movwf Y3 ;-------------------------- chk_min incf FSR, F movf Y0, W subwf INDF,W ;W=INDF-Y0 btfss STATUS, C goto min_to_Y0 ;New value is less than in Y0 btfss STATUS, Z goto chk_max incf FSR, F ;The first byte is equal, we compare the second byte movf Y1, W subwf INDF,W ;W=INDF-Y1 btfss STATUS, C goto min_to_Y1 ;New value is less than in Y1 decf FSR, F ;-------------------------- chk_max movf INDF, W subwf Y2, W ;W=Y2-INDF btfss STATUS, C goto max_to_Y2 ;New value is less than in Y2 btfss STATUS, Z goto chk_end2 incf FSR, F ;The first byte is equal, we compare the second byte movf INDF, W subwf Y3, W ;W=Y1-INDF btfss STATUS, C goto max_to_Y3 ;New value is less than in Y1 goto chk_end ;-------------------------- chk_end2 incf FSR, F chk_end movlw ADC_val+.39 subwf FSR, W btfss STATUS, Z goto chk_min ; Check on ADC Output from borders pagesel ClrA call ClrA movf Y0, W movwf AARGB1 movf Y1, W movwf AARGB2 call FLO2432 movlw LOW lim_min_1k ;The minimal value of sum ADC call Prog_To_B call TALTB32 ;AB? ; 1-Yes, 0-No pagesel $ iorlw 0 btfss STATUS, Z retlw 2 ; sorting pagesel BEQUA call BEQUA call ClrA movf Y2, W movwf AARGB1 movf Y3, W movwf AARGB2 call FLO2432 call FPS32 movlw LOW lim_amp_1k ;The minimal double amplitude of a signal call Prog_To_B call TALTB32 ;A A call BEQUA ; A -> B call FPM32 ; A=A*B, _._. _=I_Re*I_Re movlw Y0 call Copy_From_A ; Y=I_Re*I_Re movlw I_Im0 call Copy_To_A ; I_Im -> A call BEQUA ; A -> B call FPM32 ; A=A*B, _._. _=I_Im*I_Im movlw Y0 call Copy_To_B call FPA32 ;A=I_Re*I_Re + I_Im*I_Im movlw Y0 call Copy_From_A ; we preserve the denominator ; the numerator of real part movlw U_Re0 call Copy_To_A ;U_Re -> A movlw I_Re0 call Copy_To_B ;I_Re -> B call FPM32 ;A=U_Re*I_Re movlw X0 call Copy_From_A movlw U_Im0 call Copy_To_A ;U_Im -> A movlw I_Im0 call Copy_To_B ;I_Im -> B call FPM32 ;A=U_Im*I_Im movlw X0 call Copy_To_B call FPA32 ;A=U_Re*I_Re + U_Im*I_Im movlw Y0 call Copy_To_B ;B=the denominator call FPD32 ;A=A/B movlw Z_Re0 call Copy_From_A ;we preserve the real part ;the numerator of imaginary part movlw U_Re0 call Copy_To_A ;U_Re -> A movlw I_Im0 call Copy_To_B ;I_Im -> B call FPM32 ;A=U_Re*I_Im movlw X0 call Copy_From_A movlw I_Re0 call Copy_To_A ;I_Re -> A movlw U_Im0 call Copy_To_B ;U_Im -> B call FPM32 ;A=I_Re*U_Im movlw X0 call Copy_To_B call FPS32 ;A=I_Re*U_Im - U_Re*I_Im movlw Y0 call Copy_To_B ;B=the denominator call FPD32 ;A=A/B movlw Z_Im0 call Copy_From_A ;we preserve the real part pagesel $ ;====================================================== ; We interchange the position U and I that after division to receive ; Conductivity at a parallel equivalent circuit ;------------------------------------------------------ Swap_UI movlw U_Im0 movwf Temp1 movlw I_Im0 movwf Temp2 movlw .8 ; Volume of the block movwf Count1 swap_loop movf Temp1, W ;The address of block U movwf FSR movf INDF, W movwf X1 ;We keep value U in X1 movf Temp2, W ;The address of block I movwf FSR movf INDF, W movwf X2 ;We keep value I in X2 movf X1, W movwf INDF movf Temp1, W ;The address of block U movwf FSR movf X2, W movwf INDF decf Temp1, F ; We move aside reduction decf Temp2, F ; Addresses decfsz Count1, F goto swap_loop return ;======================================================================= ; Compensation for the input impedance ; ; Zmeas - Zs Zs - short circuit impedance ; Zx= ----------------- Zmeas - uncorrected measured impedance ; 1 - (Yo * Zmeas) Yo - open parallel admittance ; ; nput - Zmeas in Z_Re, Z_Im ; Output - Zx or Yx in Z_Re, Z_Im ;======================================================================= Comp_Zin pagesel Copy_To_A ; We consider numerator, the valid part movlw Z_Re0 call Copy_To_A pagesel $ movlw LOW Zs_Re_1k btfss Flags, freq movlw LOW Zs_Re_100 pagesel EEPROM_To_B call EEPROM_To_B call FPS32 ;A = Zmeas_Re - Zs_Re movlw U_Re0 call Copy_From_A ; We keep in block U for the subsequent division ; We consider numerator, an imaginary part movlw Z_Im0 call Copy_To_A pagesel $ movlw LOW Zs_Im_1k btfss Flags, freq movlw LOW Zs_Im_100 pagesel EEPROM_To_B call EEPROM_To_B call FPS32 ;A = Zmeas_Im - Zs_Im movlw U_Im0 call Copy_From_A ; We keep in block U for the subsequent division ; Yo * Zmeas = (Y_Re*Zmeas_Re - Yo_Im*Zmeas_Im) + ; (Yo_Re*Zmeas_Im + Y_Im*Zmeas_Re)j movlw Z_Re0 call Copy_To_A pagesel $ movlw LOW Yo_Re_1k btfss Flags, freq movlw LOW Yo_Re_100 pagesel EEPROM_To_B call EEPROM_To_B call FPM32 movlw I_Re0 call Copy_From_A ; Y_Re*Zmeas_Re movlw Z_Im0 call Copy_To_A pagesel $ movlw LOW Yo_Im_1k btfss Flags, freq movlw LOW Yo_Im_100 pagesel EEPROM_To_B call EEPROM_To_B call FPM32 ; Yo_Im*Zmeas_Im call BEQUA movlw I_Re0 call Copy_To_A call FPS32 ; Yo_Re*Zmeas_Re - Yo_Im*Zmeas_Im call BEQUA movlw LOW E0 call Prog_To_A ; A=1 call FPS32 ; 1 - (Yo_Re*Zmeas_Re - Yo_Im*Zmeas_Im) movlw I_Re0 call Copy_From_A ; The valid part of a denominator movlw Z_Re0 call Copy_To_A pagesel $ movlw LOW Yo_Im_1k btfss Flags, freq movlw LOW Yo_Im_100 pagesel EEPROM_To_B call EEPROM_To_B call FPM32 movlw I_Im0 call Copy_From_A ;Y_Im*Zmeas_Re movlw Z_Im0 call Copy_To_A pagesel $ movlw LOW Yo_Re_1k btfss Flags, freq movlw LOW Yo_Re_100 pagesel EEPROM_To_B call EEPROM_To_B call FPM32 ; Yo_Re*Zmeas_Im call BEQUA movlw I_Im0 call Copy_To_A call FPA32 movlw b'10000000' xorwf AARGB0, F ;we invert the sign -/+ movlw I_Im0 call Copy_From_A pagesel $ btfsc Flags, f_p ;0-consecutive equivalent circuit which is 1-parallel call Swap_UI ;for the parallel scheme we interchange the position U and I call Div_UI ;We divide U/I, we receive complex resistance Z or conductivity Y return ;======================================================================= ; Preservation of an input impedance in EEPROM ;======================================================================= Save_Zin banksel Flags movlw Z_Re0 pagesel Copy_To_A call Copy_To_A pagesel $ btfss Flags, freq goto save_1 movlw LOW Yo_Re_1k ;The real part 1kHz btfss Flags, f_p movlw LOW Zs_Re_1k goto save_2 save_1 movlw LOW Yo_Re_100 ;The real part 100Hz btfss Flags, f_p movlw LOW Zs_Re_100 save_2 pagesel A_To_EEPROM call A_To_EEPROM movlw Z_Im0 call Copy_To_A pagesel $ btfss Flags, freq goto save_3 movlw LOW Yo_Im_1k ;Imaginary part 1kHz btfss Flags, f_p movlw LOW Zs_Im_1k goto save_4 save_3 movlw LOW Yo_Im_100 ;Imaginary part 100Hz btfss Flags, f_p movlw LOW Zs_Im_100 save_4 pagesel A_To_EEPROM call A_To_EEPROM pagesel $ return ;----------------------------------------------------------------------------- ;Loading value Sin (2*PI*t/20) in registers of porosity SHIM CCPR2L:CCPCON <5:4> Load_Sine_Val movlw HIGH Sine_Table movwf PCLATH decf Sine_step, W ;The index value in the table on 1 is less call Sine_Table movwf Sine_val movlw b'11001111' andwf CCP2CON rrf Sine_val, F btfsc STATUS, C bsf CCP2CON, 4 ;Duration is SHIM, low-order bit (0) rrf Sine_val, F btfsc STATUS, C bsf CCP2CON, 5 ;Duration is SHIM, bit N 1 movf Sine_val, W andlw 0x3F movwf CCPR2L ;Duration is SHIM - rest decfsz Sine_step,F ;Following step goto lsv_1 ;For alignment of duration in sequence movlw .20 ;New period movwf Sine_step return lsv_1 nop ;for alignments of duration in sequence return ;------------------------- Delay ------------------------- ; Subroutines of pauses ; The exact delay will turn out only at an interdiction of interruptions Delay_05_sec ;Pause 0.5 s Dly24 D'156249' ; 0.5/(4/20000000)/16=156250-1=156249 goto DoDly24 Delay_5_ms ; Pause 5 ms Dly24 D'1562' ; 0.005/(4/20000000)/16=1562.5=1562 goto DoDly24 Delay_200_us ; Pause 200 us 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 ;============================================== ; - - - - - - - LCD - - - - - - - ; Translation of the index into the second symbol of the second line SecLine movlw 0xC0 ; Loading of a command CmdLCD movwf Temp_LCD ; bcf _RS swapf Temp_LCD, W andlw 0x0F movwf PORTB bsf _E nop nop nop bcf _E movf Temp_LCD, W andlw 0x0F movwf PORTB bsf _E nop nop nop bcf _E ; clrf PORTB call Delay_200_us return ; Code conversion in ASCII and a conclusion NumLCD andlw 0x0F ; Mask iorlw 0x30 ; ASCII ; Conclusion ASCII of a symbol CharLCD movwf Temp_LCD SendLCD swapf Temp_LCD, W andlw 0x0F iorlw b'00010000' ; RS=1 movwf PORTB bsf _E nop nop nop bcf _E movf Temp_LCD, 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 ; The display in an initial condition goto LongSend ClrDSP movlw 1 ; Clearing of the display LongSend call CmdLCD goto Delay_5_ms DispDot movlw "." goto CharLCD Disp0 movlw "0" goto CharLCD DispSP movlw " " goto CharLCD ;----------------------------------------------------------- ;Reading of a line from the table and a conclusion on LCD Read_String movwf Count1 decf Count1,F ;Correction of initial displacement movlw HIGH Table movwf PCLATH get_next_s movf Count1,W call Table andlw 0xFF ; Check on the end of a line btfsc STATUS, Z return call CharLCD incf Count1,F goto get_next_s ;---------------------- Load CGRAM LCD --------------------- ;to load the sign generator Load_ZG movlw b'01001000' ; AC in CGRAM=8 call CmdLCD movlw HIGH Table movwf PCLATH movlw .16 ;2 signs on 8 bytes movwf Count1 movlw LOW omega-1 movwf Count2 ;Displacement in the table get_s call Table ;To receive a symbol from the table call CharLCD incf Count2,F movf Count2,W decfsz Count1,F goto get_s return ;---------------------------------------------------------- ;Conclusion from transferred in W addresses of block BCD0... 4 ;On the indicator Disp_Full movwf FSR ;The address of a cell for a conclusion on LCD next_byte swapf INDF,W call NumLCD movf INDF,W call NumLCD ;Let's check up, whether we have reached up to BCD0 movlw BCD0 subwf FSR,W btfsc STATUS,Z return decf FSR,F goto next_byte ;---------------------- BCD --------------------- ; Code conversion value from binary in a decimal format BCD movlw 0x20 movwf T1 clrf BCD0 clrf BCD1 clrf BCD2 clrf BCD3 clrf BCD4 BcdLoop rlf AARGB3, F rlf AARGB2, F rlf AARGB1, F rlf AARGB0, 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 ;======================================================================= ; Scaling and conclusion to the screen of argument A ; NZ - number meaning categories ;======================================================================= Disp_A btfss AARGB0,7 ;Sign "-" goto dsp_1 bcf AARGB0, 7 ;We clean "-" movlw "-" call CharLCD dsp_1 clrf Y0 ;the number of the coefficient movlw LOW E9 ;the address of the zero (1E9) coefficient movwf Y1 ; comparison A coefficient? cmp_A_E movf Y1, W pagesel Prog_To_B call Prog_To_B call TAGTB32 ; A>E ? pagesel $ iorlw 0 ; 0 - ___, 1 - __ btfss STATUS, Z goto A_GT_E movlw 4 addwf Y1, F ;address is the track of the coefficient incf Y0, F movlw .8 ;number multipliers (from 0 up to 7, femto it is not considered) subwf Y0, W btfss STATUS, Z goto cmp_A_E ;New comparison decf Y0, F ;normalization, in Y0 - number of the coefficient A_GT_E ;A >= E incf Y0, W ;We take a trace. A multiplier to receive after translation in movwf Y1 ;The whole at least 3 signs after a comma bcf STATUS, C rlf Y1, F rlf Y1, F ;the number of the coefficient (1..8)*4 movlw LOW E9 addwf Y1, W ;initial + address displacement pagesel Prog_To_B call Prog_To_B call FPD32 ;A=A/B, where B=1E(+/-3*N) call INT3232 ; Translation in the whole pagesel $ call BCD ; Conclusion to the display bsf Flags, L_Z ; To not deduce in the lead zero movlw 4 movwf NZ ; Number of significant figures for a conclusion movlw BCD4 call DispBCD movlw BCD4 call DispBCD movlw BCD3 call DispBCD movlw BCD3 call DispBCD movlw BCD2 call DispBCD movlw BCD2 call DispBCD bcf Flags, L_Z ; We deduce all successively movlw BCD1 call DispBCD movf NZ, F btfsc STATUS, Z goto prefix call DispDot ;Decimal point movlw BCD1 call DispBCD_2 movlw BCD0 call DispBCD_2 movlw BCD0 call DispBCD_2 prefix btfss Flags, calibr ;For a mode of calibration without a blank call DispSP movlw LOW _pref-1 addwf Y0, W call Table iorlw 0 btfss STATUS, Z goto CharLCD return ; if the code of coefficient is equal to zero (for one), nothing it is concluded ;---------------------- BCD to LCD --------------------- ; Conclusion of the category and preparation for a conclusion of the following DispBCD_2 movf NZ, F btfsc STATUS, Z return DispBCD movwf FSR swapf INDF,F movf INDF,W btfss Flags,L_Z ;1 - to not deduce in the lead zero goto chk_NZ andlw 0x0F btfsc STATUS,Z return ;The miss of a conclusion bcf Flags,L_Z ; This and all posdedujushchie figures it is deduced chk_NZ movf NZ, F btfsc STATUS, Z goto Disp0 ; Meaning categories have terminated, we deduce 0 decf NZ, F movf INDF,W call NumLCD return ;------------------------------------------------------- ; in sequence for work with corrective K -Tami ; ; Inkrementirovaniye of semiblock B IncB bsf Flags, const_change ;we establish the flag of a change in the constant incf BARGB2, F btfsc STATUS, Z incf BARGB1, F goto ShowX ; Dekrementirovaniye of semiblock B DecB bsf Flags, const_change ;we establish the flag of a change in the constant movf BARGB2, F btfsc STATUS, Z decf BARGB1, F decf BARGB2, F ShowX movlw BEXP movwf Temp2 ;the address of source - high-order address of the block movlw AARGB0 movwf Temp1 ;the address of recipient - high-order address of the block pagesel Copy call Copy pagesel $ bcf Flags, L_Z ; to derive leading zero movlw 4 ;the number of significant places movwf NZ 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 ;----------------------- Save_Const ;address K- that is transferred in Y1 movf Y1, W pagesel B_To_EEPROM call B_To_EEPROM pagesel $ return ;======================================================= ; Display the supply voltage Ubat ; ;======================================================= Disp_Ubat ;initialization ADC banksel ADCON0 movlw b'10001001' ;Fosc/32, _____ AN1, ______ ___ ___. movwf ADCON0 call Delay_200_us ; Pause for charging C-hold of ADC bsf ADCON0,GO ;to begin the analog-to-digital conversion btfsc ADCON0,GO goto $-1 ; await the end of conversion ;voozvrashchayem tuning ADC to the channel O movlw b'10000001' ;Fosc/32, channel AN0, Module ADC incl. movwf ADCON0 pagesel ClrA call ClrA banksel ADRESL movf ADRESL, W ;Younger byte of measurement banksel AARGB2 movwf AARGB2 movf ADRESH,W movwf AARGB1 call FLO32 movlw LOW K_Ubat call EEPROM_To_B call FPM32 pagesel $ movlw LOW _Ubat call Read_String call Disp_A movlw "V" call CharLCD call Delay_05_sec return ;======================================================= ;Tables of constants. Begins with 0x700 address ; (posdelniye of 256 bytes of the zero page of the memory of programs) include "tables.inc" ;//////////////////////////////////////////////////////////////////////////////////// ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ; P A G E N 1 ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ;//////////////////////////////////////////////////////////////////////////////////// ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++ ; ; PIC16 24 BIT FLOATING POINT LIBRARY ; Library we shall place in 1-st village of memory of programs ; Before a call to use pagesel ; ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++ #define P16_MAP1 0 #define P16_MAP2 1 org 0x800 include "math16.inc" include "fp32.a16" include "taxxb32.a16" ;------------------------------------------------------- ; ; Auxiliary in sequence for works with library FPL32 ; ;------------------------------------------------------- Clr_ADC movlw ADC_val + .39 ; The high-order address of the block of measurements movwf FSR movlw .40 ;Volume of the block movwf Count1 goto ClrLoop ; _______ ______ X, Y Clr_XY movlw Y0 ; The low-order address of block X, Y movwf FSR movlw .8 ;Volume of the block movwf Count1 goto ClrLoop ClrB movlw BEXP ; Clearing of the block _ goto ClrA+1 ClrA movlw AEXP ; Clearing of the block _ movwf FSR movlw 4 ;Volume of the block movwf Count1 ClrLoop clrf INDF ; Cycle of clearing decf FSR, F ; We reduce the address decfsz Count1, F goto ClrLoop return ;------------------------------------------------------- ; Data reading from EEPROM in the block A EEPROM_To_A movwf EE_ADR ; keep the address of cell EEPROM movlw AEXP goto ee_1 ; Data reading from EEPROM in the block B EEPROM_To_B movwf EE_ADR ; keep the address of cell EEPROM movlw BEXP ee_1 movwf FSR movlw 4 ;Volume of the block 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 ; Bank 2 movwf EEADR ; The address of cell EEPROM banksel EECON1 ; Bank 3 bcf EECON1,EEPGD ;To choose EEPROM bsf EECON1,RD ;????? reading banksel EEDATA ; Bank 2 movf EEDATA,W ; W = EEDATA return ;------------------------------------------------------- ; Record of the block BARG in EEPROM ; The address in EEPROM is transferred in W B_To_EEPROM movwf EE_ADR movlw BEXP goto w_ee_1 ; Record of block AARG in EEPROM ; The address in EEPROM is transferred in W A_To_EEPROM movwf EE_ADR movlw AEXP w_ee_1 movwf FSR movlw 4 ;Volume of the block 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 ;Bank 3 btfsc EECON1,WR goto $-1 banksel EE_ADR movf EE_ADR,W banksel EEADR ; Bank 2 movwf EEADR banksel EE_DATA movf EE_DATA,W banksel EEDATA ; Bank 2 movwf EEDATA banksel EECON1 ; Bank 3 bcf EECON1,EEPGD bsf EECON1,WREN movlw 0x55 movwf EECON2 movlw 0xAA movwf EECON2 bsf EECON1,WR nop bcf EECON1,WREN return ;------------------------------------------------------- ; Copying "to destination" the block (4 bytes) data ; Temp1 = address of the addressee - the high-order address of the block is indicated ; Temp2 = address of a source - the high-order address of the block is indicated ;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 ; Volume of the block 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 ; We move aside reduction decf Temp2, F ; Addresses decfsz Count1, F goto Copy_Loop return ;--------------------------------------------------- ; Data reading from table Cos (x) in the block B Cos_To_B movwf f_tmp ; keep the index on number value Cos bcf STATUS, C rlf f_tmp, F rlf f_tmp, F ;We multiply on 4 movlw BEXP movwf FSR movlw 4 ;Volume of the block movwf Count1 Cos_read_loop movlw HIGH Table movwf PCLATH movlw LOW _Cos-1 addwf f_tmp, W call Table ;We take byte value Cos pagesel $ movwf INDF ;We keep in BARG incf f_tmp, F; decf FSR, F decfsz Count1, F goto Cos_read_loop return ;--------------------------------------------------- ; Copying of the block (4 bytes) from memory of the programs in reg. A Prog_To_A movwf f_tmp ; We preserve indicator to source address decf f_tmp, F ;korektiruyem for address of correct sample movlw AEXP movwf FSR goto prog_1 ; Copying of the block (4 bytes) from memory of the programs in reg. B Prog_To_B movwf f_tmp ; We preserve indicator to source address decf f_tmp, F ;korektiruyem for address of correct sample movlw BEXP movwf FSR prog_1 movlw 4 ;Volume of the block movwf Count1 ptb_loop movlw HIGH Table movwf PCLATH movf f_tmp, W call Table ;We take byte pagesel $ movwf INDF ;We keep in BARG incf f_tmp, F; decf FSR, F decfsz Count1, F goto ptb_loop return ;--------------------------------------------------- ; Loading of data of ADC measurement in the block A ADC_To_A call ClrA movf Num_p, W ;Number of a point of measurement movwf f_tmp bcf STATUS, C rlf f_tmp, F ;measurement takes 2 bytes, we multiply on 2 movlw ADC_val addwf f_tmp, W movwf FSR movf INDF, W ;high-order byte ???? movwf AARGB1 incf FSR movf INDF, W ;low-order byte ???? movwf AARGB2 return END