TITLE "00_HEADER_LiIon.INC" ;********************************************************************* ; File: 00_HEADER_LiIon.INC ; Author: Ottmar ; Date: 21.05.2022 ;********************************************************************* ;--PINBELEGUNG PORTA ; RA7:6 n.c. (16)(15) ; RA5 (04) MCLR, Reset-Taster ; RA4 (03) AN3 DRAIN- " " SHUNT ; RA3 (02) AN4 SHUNT-Spannung ADC-Input DRAIN ; RA2 (01) AN2 VDD5V " Ub ca. 5V VDD5V ; RA1 (18) SS2 (1)MCP4151 SPI-Slave Seleckt ; RA0 (17) SDO2 (3)MCP4151 SPI-Data Output ; ;--PINBELEGUNG PORTB ; RB7 (13) ICSPDAT-PGD + LCD-DAT (2Wire-LCD Interf.) ; RB6 (12) ICSPCLK-PGC + LCD-CLK " " " ; RB5 (11) SCK2 (2)MCP415 1SPI-Clock ; RB4 (10) MCP4151,P0W. ; RB3 (09) AN9 ADC-Input für MCP4151,P0W (=Vref OPA) ; RB2 (05) START_KEY ; RB1 (06) n.c. ; RB0 (07) LED ; ;--MCP4151 Digital Potentiometer 10kOhm ; CS (1) Slave select (Low active) ; SCK (2) Serial Clock fmax 250 kHz ; SDI/SDO(3) Serial Data In/Serial Data Out ; Vss (4) Ground (0V) ; P0A (5) connect Pin to GND ; P0W (6) Wiper (Schleifer, Abgriff) ; P0B (7) connect it to Vdd or other Voltage <=5,5V ; Vdd (8) ca.5V ; Interface MCU <-> MCP4151 ; vgl. MCP4151 Datenblatt S. 41 6.0 SERIAL INTERFACE (SPI) ;********************************************************************* LIST ;--SUPPRESSED WARNINGS ERRORLEVEL -207 ;"Found label after column 1." ERRORLEVEL -302 ;"Register in operand not in bank 0.." ERRORLEVEL -303 ;Program word too large. Truncated to core size. ERRORLEVEL -306 ;"Cross. page boundary- ensure page bits are set" ; ;--MCU-CONFIGURATION LIST P=16F1827 ;list directive to define processor #INCLUDE ;processor specific var. definitions ; ;--CONFIGURATION WORD SetUP ; Der PIC 16F1827 verfügt über 2 Configurations-Register. ; Falls hier eine Fehlermeldung auftritt (..illegal charakter) ; ist vmtl. im Menü "Configure" der falsche Prozessor gewählt. ; ; Internal Oscillator, PLL is OFF __CONFIG _CONFIG1, _FOSC_INTOSC & _CLKOUTEN_OFF & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _IESO_OFF & _FCMEN_OFF __CONFIG _CONFIG2, _LVP_OFF & _WRT_OFF & _STVREN_OFF & _BORV_19 &_PLLEN_OFF NOLIST ;********************************************************************* ;--RAM ALLOCATION in the GPR (General Purpose RAM) LIST CBLOCK 0x20 LcdData ;LcdInit HD44780_2Wire.INC LcdBit ;Bitzähler LcdFlags ;Ablaufsteuerung Daten/Instruktionen d1,d2,d3,d4,d5,d6 ;counters (vgl. delay routines) tmpLines ;Zeile im LCD ; ;--SONSTIGE pntr1,pntr0 ;Adresszeiger ACb3,ACb2,ACb1,ACb0 BCb3,BCb2,BCb1,BCb0 BCD4,BCD3,BCD2,BCD1,BCD0 cntDig,cntBit cntB2D cnTemp ;--CHARGE Vdd1,Vdd0 ;Versorgungsspannung 5V Vdrain1,Vdrain0 ;Verlust über Drain-Source Vakku1,Vakku0 ;Vakku1:0 = Vdd1:0 - Vdrain1:0 Vshunt1, Vshunt0 ;zugleich Ladestrom in mA ;--SPI Data1,Data0 WiperValue WiperMax,WiperMin ;WiperValue Max-/Minimalwert ;-Flags Flags ;-ISR KeyState KeyPress cnt1,cnt0 cnt10ms Estd,Zstd ;ISR-Clock Stunden Emin,Zmin ; Minuten Esec,Zsec ; Sekunden ;--Allgemein tmpVar ;ADC ENDC ;********************************************************************* ; LABELS & CONSTANTS ;********************************************************************* ; Xtal frequency, used to calculate multiplier in delays XTAL EQU .4 ;MHz (set to actual Fosc) FOSC_MULT EQU XTAL/.4 ;used in delays an LCD_Init ;--------------------------------------------------------------------- ; PORT-REGISTER-LABELS ;--------------------------------------------------------------------- ; Zahl in Klammern () -> Pinbelegung 16F1827 ; vgl. Pinzuodnung S.11ff Table 1-2ff ;--ADC_PORT (PORTA) Analog Voltage Measurement ADC_PORT EQU PORTA ADC_LAT EQU LATA ADC_TRIS EQU TRISA ADC_ANSEL EQU ANSELA ; Pinbelegung MCLRE EQU RA5 ;(04) MCLRE Reset Button DRAIN EQU RA4 ;(02) AN3 Udrain zugleich -Akku SHUNT EQU RA3 ;(03) AN4 Ushunt Strommessung VDD5V EQU RA2 ;(01) AN2 Vdd 5V zugleich +Akku ; VREF EQU RB3 ;(09) AN9 vgl.ADC_PORT ; SS2 EQU RA1 ;(18) SPI_PORT,SS2 RA1 ; SDO2 EQU RA0 ;(17) SPI_PORT,SDO2 RA0 ; ;--LCD-PORT (PORTB) 2 Wire Interface LCD_PORT EQU PORTB LCD_LAT EQU LATB LCD_TRIS EQU TRISB LCD_ANSEL EQU ANSELB ; LCDDAT EQU RB7 ;(13)LCD_DATA (blue) ->LCD-PORT LCDCLK EQU RB6 ;(12)LCD_CLOCK (grey) ->LCD-PORT ; ;--KEY_PORT (PORTB) KEY Start/Stop, Icharge Up/Down KEY_PORT EQU PORTB KEY_LAT EQU LATB KEY_TRIS EQU TRISB KEY_ANSEL EQU ANSELB ; ; LCDDAT EQU RB7 ;(13)LCD_DATA ->LCD-PORT ; LCDCLK EQU RB6 ;(12)LCD_CLOCK ->LCD-PORT ; SCK2 EQU RB5 ;(11) ->SPI_PORT SW_VREF EQU RB4 ;(10) OPA,Vref ON/OFF VREF EQU RB3 ;(09) AN9 vgl.ADC_PORT KEY_START EQU RB2 ;(08) active LOW KEY_STOP EQU RB1 ;(07) " " LED_GRN EQU RB0 ;(06) ->"#define LED_ON/_OFF KEY_MASK EQU 0x06 ;RB2:1=11 pushbuttons ; ;--SPI_PORT (PORTB) SPI-Dialog with MCP4151 SPI_PORT EQU PORTB SPI_LAT EQU LATB SPI_TRIS EQU TRISB SPI_ANSEL EQU ANSELB ; SCK2 EQU RB5 ;(11) SPI:PORT,SCK2 SS2 EQU RA1 ;(18)SPI_PORT,SS2 RA1(18) SDO2 EQU RA0 ;(17) SPI_PORT,SDO2 RA0(17) ; ;--------------------------------------------------------------------- ; OTHER LABELS ADC-channels, Flags etc. ;--------------------------------------------------------------------- ;--ADC Analog channels S.145 ADC_VDD EQU b'00001000' ;RA2(01) AN2 Vdd ADC_SHUNT EQU b'00001100' ;RA3(02) AN3 Strommess-Shunt ADC_DRAIN EQU b'00010000' ;RA4(03) AN4 -Referenz für Uakku ADC_VREF EQU b'00100100' ;RB3(09) AN9 Vref für OPA LM358 ; ;--ADC-FLAGS (Ablaufsteuerung ADC-/Berechnungs/LCD-Ausgabe) ; Flags ; V_VDD5V EQU .0 ;Batt+ zugl. 5V-Versorgung ; V_SHUNT EQU .1 ;Spannung über Strommess.Shunt ; V_DRAIN EQU .2 ;Batt- Spannung an Drain ; V_VREF EQU .3 ;Vref OPA,Vref ; I_BATT EQU .4 ;Ladestraom ; V_AKKU EQU .5 ;--Flags ISR_ACTIVE EQU .4 ;Flags,4 CHRG_END EQU .5 ;Flags,5 NEW_SEC EQU .6 ;Flags,6 1/0 New second has/not occured ERR EQU .7 ;Flags,7 FLAGMASK EQU b'11100000' ; ;--MCP4151 WIPER_MAX EQU .150 WIPER_MIN EQU .1 ; SPI 16-Bit Command WIPER0_WRITE EQU 0x00 ;Hinweise zur Bittfolge: ; b15:12="0000" address of wiper0 ;b11:10="00" Write Data ; b 9:8 ="00" b9:8 Databits ;b 7:0 =WiperValue WIPER0_READ EQU 0x0C ;b3:2="11" Read Data ; 8-Bit Commands WIPER0_INCR EQU 0x04 ;b2:0="100" increment WIPER0_DECR EQU 0x08 ;b3:0="1000" decrement ; ;--CHARGE AKKU V_MAX1 EQU 0x10 ;Max. Ladespannung 1 Zelle Li-Ion V_MAX0 EQU 0x68-.20 ;0x1068 = 4200mV ; V_MAX1 EQU 0x0F ;3900mV = 0x0F3C ; V_MAX0 EQU 0x3C ; ; #DEFINE CTRL_LEDON bcf SPI_PORT,LED_GRN ;RB0 Kontroll-LED EIN #DEFINE CTRL_LEDOFF bsf SPI_PORT,LED_GRN ;RB0 Kontroll-LED AUS #DEFINE VREF_ON bsf SPI_PORT,SW_VREF ;RB4(10) OPA-Vref (MCP4151,P0W) #DEFINE VREF_OFF bcf SPI_PORT,SW_VREF ;RB4 ;********************************************************************* ; LCD-PROPERTIES (Eigenschaften an aktuellen LCD-Typ anpassen) ;********************************************************************* ; LCD_TYPE EQU 1 ;=1 LCD 2x8 und 2x16 ; LCD_TYPE EQU 2 ;=2=LCD 4x16 LCD_TYPE EQU 3 ;=3=LCD 4x20 ; IF LCD_TYPE == 1 ;Uncomment LCD_DIGITS 2x8 OR 2x16 !!! LCD_LINES EQU .2 ;LCD 2x8 * 2x16 ; LCD_DIGITS EQU .8 ;LCD 2x8 ; LCD_DIGITS EQU .16 ;LCD 2x16 ENDIF ;------------------------------------- ; NO CHANGES AFTER THIS LINE ALLOWED! ;------------------------------------- LINE1 EQU 0x00 ;all LCDs LINE2 EQU 0x40 ;" " ; IF LCD_TYPE==2 LINE3 EQU 0x10 ;LCDs 4x16 only LINE4 EQU 0x50 ;" " " LCD_LINES EQU .4 ;Lines LCD_DIGITS EQU .16 ;digits/line ENDIF ; IF LCD_TYPE==3 LINE3 EQU 0x14 ;LCDs 4x20 only LINE4 EQU 0x54 ;" " " LCD_LINES EQU .4 LCD_DIGITS EQU .20 ;digits/line ENDIF ; #DEFINE LCD_DATA LCD_LAT,LCDDAT ;Strobe Data (H->L -> Enable) #DEFINE LCD_CLK LCD_LAT,LCDCLK ;Strobe Clock (H->L) #DEFINE LCD_RS LcdFlags,7 ;0/1 Data-Mode/Instruction-Mode #DEFINE NIBBLE LcdFlags,6 ;1/0 send Upper/Lower Nibble to LCD ; SET_DDRAM_ADDR EQU 0x80 ;Function "SET DDRAM-ADDRESS" SET_CGRAM_ADDR EQU 0x40 ;"Set CGRAM Address" b'01000000 ; DISPLAY_OFF EQU 0x08 ;Function "Display Disabled" DISPLAY_ON EQU 0x0C ;Function "Display enabled, Crsr On, Blink Off ;********************************************************************* ORG 0x0000 ;PROCESSOR RESET VECTOR GOTO init ;*********************************************************************