; ************************************************************** ; * Include file for key routines for akkuloader.asm * ; * (C)2005 by Gerhard Schmidt, info@avr-asm-tutorial.net * ; ************************************************************** ; ; Provides Registers Task ; --------------------------------------------------------- ; KeyInit rmp,Z,X Init the key input, set default values ; Keys rmp Asks the input pins for pressed keys, ; for main loop operation ; KeyMenueFirst nn Outputs the first menue for the keys ; --------------------------------------------------------- ; ; Constants ; .EQU pLedO = PORTD ; Leds connected to port D .EQU cLedM = 0xF0 ; All led port bits set .EQU pKeyO = PORTD ; Keys connected to port D .EQU pKeyD = DDRD ; Key direction registers .EQU pKeyI = PIND ; Key read port .EQU cKeyB = 0xE0 ; Three keys on bits 7, 6 and 5 .EQU cKeyM = 0x1F ; mask for clearing bits 7, 6, and 5 ; ; ============== Routine for initialisation of the keys ===== ; ; Init the Leds, powering the Leds on for 4 seconds ; KeyLedInit: ldi ZH,HIGH(sLedC) ldi ZL,LOW(sLedC) ldi rmp,5 ; 5 bytes clr R0 KeyLedInit1: st Z+,R0 dec rmp brne KeyLedInit1 in rmp,pLedO cbr rmp,cLedM ; clear the Led bit powering Leds on out pLedO,rmp ret ; ; Init the keys ; KeyInit: clr rKeyLst ; clear last key read clr rKeyRep ; clear counter for key repeat ; ; Reset the variables for key inputs ; KeyReset: ldi XH,HIGH(sKeyJ1) ; target in Sram ldi XL,LOW(sKeyJ1) ldi ZH,HIGH(2*KeyInitTable) ; source table ldi ZL,LOW(2*KeyInitTable) ldi rmp,6 ; 3 words, 6 bytes KeyReset1: lpm ; read byte from table adiw ZL,1 st X+,R0 ; to Sram dec rmp brne KeyReset1 clr rmp ; set channel = 0 sts sKeyCh,rmp ret ; ; Table for key init ; KeyInitTable: .DW KeyM1,0,0 ; ; ===================== Routines for the main loop ============ ; ; operates the Led output ; KeyLeds: in R0,pLedO ; remember the actual output state ldi rmp,0x0F ; clear all Led outputs, setting Leds on and R0,rmp lds rmp,sLedC ; read Led counter dec rmp ; downcount counter brne KeyLeds4 ; not zero, skip checking new states lds R1,sState ; read status of the channels ldi ZH,HIGH(sLed1) ; point Z to channel values ldi ZL,LOW(sLed1) ldi XL,4 ; repeat four times KeyLeds1: lsr R1 ; lower status bit brcs KeyLeds2 ; lower status bit is one ldi XH,32 ; channel compare value for 50% pulse width lsr R1 ; higher status bit brcs KeyLeds3 ; 10=load, set channel value ldi XH,64 ; 00=inactive, later sets Led off rjmp KeyLeds3 ; set channel value KeyLeds2: ; lower status bit is one clr XH ; 11=maintain, later sets Led on for whole cycle lsr R1 ; shit higher bit to carry brcs KeyLeds3 ; set channel value ldi XH,56 ; 01=unload, sets Led on for 8 cycles KeyLeds3: ; store channel value and repeat st Z+,XH ; set channel value dec XL ; next channel brne KeyLeds1 ; another channel ldi rmp,64 ; 64 cycles to counter KeyLeds4: ; compare channels with counter in rmp sts sLedC,rmp ; store counter ldi XH,0x80 ; mask for setting a Led bit ldi XL,4 ; four channels ldi ZH,HIGH(sLed1) ; point Z to channel values ldi ZL,LOW(sLed1) KeyLeds5: ; check if Led should be off ld R1,Z+ ; read channel value cp R1,rmp ; compare counter and channel value brcs KeyLeds6 ; leave Led output on or R0,XH ; switch channel output on = Led Off KeyLeds6: lsr XH ; mask one right dec XL ; next channel brne KeyLeds5 ; again a channel out pLedO,R0 ; set channel output bits ret ; done ; ; Keys asks the input pins for pressed keys ; Keys: in R1,pKeyO ; Save current status of the output bits in R0,pKeyD ; Save the direction bits mov rmp,R0 ; copy direction bits andi rmp,cKeyM ; clear the direction bits out pKeyD,rmp ; set key pins to input mov rmp,R1 ; set the pullup resistors on ori rmp,cKeyB ; set bits to one out pKeyO,rmp ; to port nop ; wait a while nop nop nop in rmp,pKeyI ; read the key port out pKeyD,R0 ; restore original directions out pKeyO,R1 ; restore original output states andi rmp,cKeyB ; isolate key bits cpi rmp,cKeyB ; all keys inactive? brne Keys2 ; no Keys1: clr rKeyRep ; repeat to zero mov rKeyLst,rmp ; store this ret ; done Keys2: cp rmp,rKeyLst ; equal to last key state? brne Keys1 ; no, clear the counter inc rKeyRep ; increase counter ldi rmp,cKeyRep ; compare with preselected number cp rmp,rKeyRep breq Keys3 ; equal, go ret Keys3: ; Key ok, start selected routine mov R0,rKeyLst ; read the keys again ldi ZH,HIGH(sKeyJ1) ; point to first key adress ldi ZL,LOW(sKeyJ1) Keys4: rol R0 brcc Keys5 adiw ZL,2 ; next adress rjmp Keys4 Keys5: ld rmp,Z+ ; read jump adress and jump ld R0,Z mov R1,R0 ; check if adress is zero or R1,rmp breq Keys6 push rmp push R0 Keys6: ret ; jump ; ; ================== common routines for menues ============ ; ; Set position to Menue start ; KeyMStrt: push ZH ; save Z push ZL ldi ZH,3 ; line 4 ldi ZL,9 ; position 10 rcall LcdPos ; set position pop ZL ; restore Z pop ZH ret ; ; clears the menue part and sets position ; to the beginning of this area ; KeyMClr: rcall KeyMStrt ldi rmp,' ' mov R0,rmp ldi rmp,11 mov R1,rmp KeyMClr1: rcall LcdR0 dec R1 brne KeyMClr1 rjmp KeyMStrt ; ; Display first menue on line 3 ; KeyMenueFirst: rcall KeyMStrt ; set position ldi ZH,HIGH(2*KeyTxtMenue) ldi ZL,LOW(2*KeyTxtMenue) rcall LcdDisplZ ldi rmp,17 ; Set cursor position sts sLcdCs,rmp rjmp KeyReset ; init the jump adresses ; First menue on Lcd KeyTxtMenue: .DB " Menue...",0 ; ; Output an error message on illegal channel numbers ; KeyGetChError: rcall KeyMClr ; Clear the menue part ldi ZH,HIGH(2*KeyTxtChErr) ; Error text ldi ZL,LOW(2*KeyTxtChErr) rcall LcdDisplZ ; display error text ldi rmp,18 ; set cursor position sts sLcdCs,rmp ret ; ; Get channel number in R0 ; Display an error message if channel is not between 1..4, and return ; with carry flag set ; KeyGetChR0: lds R0,sKeyCh ; read current channel tst R0 ; = zero? breq KeyGetChR0e push rmp ldi rmp,5 cp R0,rmp ; > 4 ? pop rmp brcc KeyGetChR0e clc ret KeyGetChR0e: rcall KeyGetChError sec ret ; KeyTxtChErr: .DB "Ch error!",0 ; ; Set selected channel state to value in rmp ; KeyChSet: rcall KeyGetChR0 ; get channel number in R0 brcs KeyChSet3 ldi ZL,0xFC ; channel mask bits = 0 KeyChSet1: dec R0 ; channel reached? breq KeyChSet2 ; yes sec ; set carry for mask rol rol ZL ; next channel rol ZL lsl rmp ; shift rmp left lsl rmp rjmp KeyChSet1 ; again KeyChSet2: lds ZH,sState ; load state bits and ZH,ZL ; clear channel activity bits or ZH,rmp ; set desired activity bits for channel sts sState,ZH ; set new state KeyChSet3: ret ; ; Set the channel's pwm to the value in rmp ; KeySetPwm: rcall KeyGetChR0 brcs KeySetPwm2 ldi ZH,HIGH(cPwm1S-1) ; clear the channel's pwm value ldi ZL,LOW(cPwm1S-1) KeySetPwm1: adiw ZL,1 ; next pwm channel dec R0 brne KeySetPwm1 st Z,rmp ; set pwm value KeySetPwm2: ret ; ; Clear the channel's unload bit ; KeyClrUnl: rcall KeyGetChR0 brcs KeyClrUnl2 ldi rmp,0xF7 ; mask KeyClrUnl1: sec ; roll a 1 in rol rmp ; rotate mask left dec R0 ; next channel brne KeyClrUnl1 and rPwmOut,rmp ; clear the unload bit KeyClrUnl2: ret ; done ; ; Clear the channel's capacity counter ; KeyClrCap: rcall KeyGetChR0 brcs KeyClrCap1 dec R0 ldi ZH,HIGH(sAdcC) ldi ZL,LOW(sAdcC) add ZL,R0 add ZL,R0 st Z+,rmp st Z+,rmp std Z+6,rmp KeyClrCap1: ret ; ; Get the parameter of the current channel, set adress and input decimal ; Expects the parameter base adress in X and the maximum in Z ; KeyGetParam: rcall KeyGetChR0 brcs KeyGetParam1 dec R0 lsl R0 ; * 8 lsl R0 lsl R0 add XL,R0 ; correct adress clr R0 adc XH,R0 ld R0,X+ ; read LSB sts sKeyNW,R0 ; store in decimal input number ld R0,X ; read MSB sts sKeyNW+1,R0 sts sKeyNM,ZL sts sKeyNM+1,ZH KeyGetParam1: ret ; ; Set the parameter of the current channel ; Expects the parameter adress in X and the text message in Z ; KeySetParam: rcall KeyGetChR0 brcs KeySetParam1 dec R0 lsl R0 ; * 8 lsl R0 lsl R0 add XL,R0 ; correct adress clr R0 adc XH,R0 lds rmp,sKeyNW st X+,rmp lds rmp,sKeyNW+1 st X,rmp rcall KeyMClr rcall LcdDisplZ ldi ZH,HIGH(KeyM12a) ldi ZL,LOW(KeyM12a) ijmp KeySetParam1: ret ; ; After finishing a menue entry, display the text in X ; KeyMDone: rcall KeyMClr ; Clear the menue part of the LCD rcall LcdDisplZ mov ZH,XH mov ZL,XL ijmp ; ; ================= Handle menue table entries =========== ; ; Output the menue entry in X, menue entry in sKeyNC ; expects adress of menue table in X ; KeyMOut: rcall KeyMClr KeyMOut1: mov ZH,XH ; copy menue start to Z mov ZL,XL lds R1,sKeyNC ; read the entry number KeyMOut2: ; check if current menue point reached tst R1 ; menue point reached at zero? brne KeyMOut5 ; not reached KeyMOut3: ; reached, output text lpm adiw ZL,1 mov rmp,R0 cpi rmp,'#' breq KeyMOut4 rcall LcdChar rjmp KeyMout3 KeyMOut4: ; output finished, search next Null lpm adiw ZL,1 tst R0 brne KeyMOut4 ; read the lcd position and the jump adress lpm adiw ZL,1 sts sLcdCs,R0 lpm adiw ZL,1 sts sKeyJ3,R0 ; store adress in key 3 lpm sts sKeyJ3+1,R0 ret KeyMOut5: ; not the desired entry, search the next lpm adiw ZL,1 tst R0 brne KeyMOut5 adiw ZL,3 lpm ldi rmp,0xFF cp rmp,R0 breq KeyMOut6 dec R1 rjmp KeyMOut2 KeyMOut6: ; start new clr R1 sts sKeyNC,R1 rjmp KeyMOut1 ; ; ================= Get decimal number input ============ ; ; ; Displays the decimal number in sKeyNW at the end of line 4 ; KeyDecDispl: ; display the decimal number ldi ZH,3 ; Line 4 ldi ZL,15 ; Position 16 rcall LcdPos ; Set lcd position lds R2,sKeyNW ; read number lds R3,sKeyNW+1 rcall LcdDec5 ; write number on Lcd lds ZL,sKeyNC ; set LCD cursor position subi ZL,-15 sts sLcdCs,ZL ldi ZH,3 rjmp LcdPos ; ; Set the decimal input jump adresses and get a decimal ; expects: text pointer in Z, return adress in X, skip adress ; in sKeyJ1 ; KeyDec: rcall KeyMClr ; clear menue area rcall LcdDisplZ ; output text ldi ZH,HIGH(sKeyJR) ; point to return adress ldi ZL,LOW(sKeyJR) st Z+,XL st Z+,XH lds XL,sKeyJ1 ; store skip return adress lds XH,sKeyJ1+1 st Z+,XL st Z+,XH ldi XL,LOW(KeyDecL) ; J1 adress ldi XH,HIGH(KeyDecL) st Z+,XL st Z+,XH ldi XL,LOW(KeyDecU) ; J2 adress ldi XH,HIGH(KeyDecU) st Z+,XL st Z+,XH ldi XL,LOW(KeyDecR) ; J3 adress ldi XH,HIGH(KeyDecR) st Z+,XL st Z+,XH ldi rmp,4 ; cursor at last digit sts sKeyNC,rmp rjmp KeyDecDispl ; display number and set cursor ; KeyDecL: ; Left key lds rmp,sKeyNC ; dec cursor position dec rmp cpi rmp,0xFF ; left out? breq KeyDecL1 sts sKeyNC,rmp ; set cursor rjmp KeyDecDispl ; display number and set cursor KeyDecL1: lds ZL,sKeyJS ; read skip adress lds ZH,sKeyJS+1 ijmp ; jump to skip routine ; KeyDecU: ; Middle key ldi ZH,HIGH(2*KeyDecTbl) ; Z to decimal table ldi ZL,LOW(2*KeyDecTbl) lds rmp,sKeyNC ; add current position lsl rmp ; * 2 add ZL,rmp ; point to value in decimal table clr rmp adc ZH,rmp lpm ; read decimal value mov XL,R0 adiw ZL,1 lpm mov XH,R0 lds ZL,sKeyNW ; read current decimal number lds ZH,sKeyNW+1 add ZL,XL ; add both adc ZH,XH lds XL,sKeyNM ; read maximum lds XH,sKeyNM+1 sec cpc ZL,XL ; compare with maximum cpc ZH,XH brcs KeyDecU1 clr ZH ; > max, clear number clr ZL KeyDecU1: sts sKeyNW,ZL ; store number sts sKeyNW+1,ZH rjmp KeyDecDispl ; display number and set cursor ; KeyDecR: ; Right key lds rmp,sKeyNC ; read cursor inc rmp ; next position cpi rmp,5 ; right out? brcc KeyDecR1 ; yes sts sKeyNC,rmp ; store position rjmp KeyDecDispl KeyDecR1: lds ZL,sKeyJR ; read jump adress lds ZH,sKeyJR+1 ijmp ; jump to finish input ; KeyDecTbl: .DW 10000 .DW 1000 .DW 100 .DW 10 .DW 1 ; ; ================= Menues ===================== ; ; Menue 1, select ; KeyM1: ldi XH,HIGH(2*KeyTxtM1) ; Menue text ldi XL,LOW(2*KeyTxtM1) rcall KeyMOut ; Display menue part KeyM1a: ldi rmp,LOW(KeyMenueFirst) ; Set left key jump adress sts sKeyJ1,rmp ldi rmp,HIGH(KeyMenueFirst) sts sKeyJ1+1,rmp ldi rmp,LOW(KeyM1Up) ; Set middle key jump adress sts sKeyJ2,rmp ldi rmp,HIGH(KeyM1Up) sts sKeyJ2+1,rmp clr rmp ; start with menue entry 0 sts sKeyNC,rmp ret ; ; Menue 1 Up Routine ; KeyM1Up: lds rmp,sKeyNC ; next higher menue entry inc rmp sts sKeyNC,rmp ldi XH,HIGH(2*KeyTxtM1) ; point X at menue table ldi XL,LOW(2*KeyTxtM1) rjmp KeyMOut ; ; Menue 11: Select Akku and Channel ; KeyM11: clr rmp ; Set selected menue entry to 0 sts sKeyNC,rmp ldi XH,HIGH(2*KeyTxtM11) ; point X to menue table ldi XL,LOW(2*KeyTxtM11) rcall KeyMOut ; Display selected menue entry KeyM11a: ldi rmp,LOW(KeyM1) ; Set left key jump adress to menue 1 sts sKeyJ1,rmp ldi rmp,HIGH(KeyM1) sts sKeyJ1+1,rmp ldi rmp,LOW(KeyM11Up) ; Set middle key jump adress to M11Up sts sKeyJ2,rmp ldi rmp,HIGH(KeyM11Up) sts sKeyJ2+1,rmp ret ; ; Menue 11 Up key routine ; KeyM11Up: lds rmp,sKeyNC ; next menue entry inc rmp sts sKeyNC,rmp ldi XH,HIGH(2*KeyTxtM11) ; selected menue text ldi XL,LOW(2*KeyTxtM11) rjmp KeyMOut ; output menue entry ; ; Select Menue routines ; KeyM111: ; Select akku number rcall KeyGetChR0 ; read channel brcs KeyM111e dec R0 ldi ZH,HIGH(sAdcAI1) ; read akkunumber ldi ZL,LOW(sAdcAI1) add ZL,R0 add ZL,R0 ld rmp,Z sts sKeyNW,rmp clr rmp sts sKeyNW+1,rmp lds rmp,sEANm ; read number of akkus sts sKeyNM,rmp ; set max akkus clr rmp sts sKeyNM+1,rmp ldi XH,HIGH(KeyM111R) ; Return adress in X ldi XL,LOW(KeyM111R) ldi ZH,HIGH(2*KeyTxtM111) ; Text adress in Z ldi ZL,LOW(2*KeyTxtM111) rjmp KeyDec ; input a decimal number KeyM111e: ret ; KeyTxtM111: .DB "Akku=",0 ; ; Return from dec input with akku number ; KeyM111R: rcall KeyGetChR0 brcs KeyM111Re dec R0 ldi ZH,HIGH(sAdcAI1) ldi ZL,LOW(sAdcAI1) add ZL,R0 add ZL,R0 lds rmp,sKeyNW ; copy input number to channel st Z,rmp rcall IdSetPar ldi XH,HIGH(KeyM11a) ; jump back ldi XL,LOW(KeyM11a) ldi ZH,HIGH(2*KeyTxt112R) ldi ZL,LOW(2*KeyTxt112R) rjmp KeyMDone KeyM111Re: ret ; KeyTxt111R: .DB "Accu set",0,0 ; KeyM112: ; Select channel number lds rmp,sKeyCh ; read channel and transfer to number input sts sKeyNW,rmp clr rmp sts sKeyNW+1,rmp ldi rmp,4 ; Set maximum value sts sKeyNM,rmp clr rmp sts sKeyNM+1,rmp ldi XH,HIGH(KeyM112R) ; Return adress in X ldi XL,LOW(KeyM112R) ldi ZH,HIGH(2*KeyTxtM112) ; Text adress in Z ldi ZL,LOW(2*KeyTxtM112) rjmp KeyDec ; input a decimal number ; KeyTxtM112: .DB "Chann=",0,0 ; ; Set channel to input number ; KeyM112R: lds rmp,sKeyNW ; copy input number to channel sts sKeyCh,rmp ldi XH,HIGH(KeyM11a) ; jump back ldi XL,LOW(KeyM11a) ldi ZH,HIGH(2*KeyTxt112R) ldi ZL,LOW(2*KeyTxt112R) rjmp KeyMDone ; KeyTxt112R: .DB "Ch set",0,0 ; KeyM113: ; Direct load ldi rmp,LOW(500) sts sKeyNW,rmp ldi rmp,HIGH(500) sts sKeyNW+1,rmp ldi rmp,LOW(9999) sts sKeyNM,rmp ldi rmp,HIGH(9999) sts sKeyNM+1,rmp ldi XH,HIGH(KeyM113R) ; Return adress in X ldi XL,LOW(KeyM113R) ldi ZH,HIGH(2*KeyTxtM113) ; Text adress in Z ldi ZL,LOW(2*KeyTxtM113) rjmp KeyDec ; input a decimal number ; KeyTxtM113: .DB "Capac.=",0 ; KeyM113R: rcall KeyGetChR0 brcs KeyM113Re rcall KeyClrUnl ldi rmp,0x02 ; set load state rcall KeyChSet ldi rmp,128 rcall KeySetPwm rcall KeyGetChR0 dec R0 lsl R0 lsl R0 lsl R0 ldi ZH,HIGH(sCh1LC) ; set current ldi ZL,LOW(sCh1LC) add ZL,R0 clr R0 adc ZH,R0 lds XL,sKeyNW ; read capacity lds XH,sKeyNW+1 mov R2,XL ; copy mov R3,XH lsr R3 ; / 2 ror R2 lsr R3 ; / 4 ror R2 lsr R3 ; / 8 ror R2 st Z+,R2 ; set load current st Z+,R3 add XL,R2 ; add to nominal capacity adc XH,R3 st Z+,XL ; set capacity st Z+,XH lsl XL ; * 2 rol XH clr rmp rol rmp st Z+,XH ; set maintain current st Z,rmp ldi XH,HIGH(KeyM11a) ; return adress ldi XL,LOW(KeyM11a) ldi ZH,HIGH(2*KeyTxt113D) ; text output ldi ZL,LOW(2*KeyTxt113D) rjmp KeyMDone KeyM113Re: ret ; KeyTxt113D: .DB "Autoload",0,0 ; ; Menue "Set" routines ; KeyM12: clr rmp ; Set selected menue entry to 0 sts sKeyNC,rmp ldi XH,HIGH(2*KeyTxtM12) ; point X to menue table ldi XL,LOW(2*KeyTxtM12) rcall KeyMOut ; Display selected menue entry KeyM12a: ldi rmp,LOW(KeyM1) ; Set left key jump adress to menue 1 sts sKeyJ1,rmp ldi rmp,HIGH(KeyM1) sts sKeyJ1+1,rmp ldi rmp,LOW(KeyM12Up) ; Set middle key jump adress to M12Up sts sKeyJ2,rmp ldi rmp,HIGH(KeyM12Up) sts sKeyJ2+1,rmp ret ; ; Menue 12 Up key routine ; KeyM12Up: lds rmp,sKeyNC ; next menue entry inc rmp sts sKeyNC,rmp ldi XH,HIGH(2*KeyTxtM12) ; selected menue text ldi XL,LOW(2*KeyTxtM12) rjmp KeyMOut ; output menue entry ; KeyM121: ldi XH,HIGH(sCh1UV) ; channel number ldi XL,LOW(sCh1UV) ldi ZH,HIGH(1300) ; maximum ldi ZL,LOW(1300) rcall KeyGetParam ; Parameter in X to input and maximum to Z ldi XH,HIGH(KeyM121R) ; Return adress in X ldi XL,LOW(KeyM121R) ldi ZH,HIGH(2*KeyTxtM121) ; Text adress in Z ldi ZL,LOW(2*KeyTxtM121) rjmp KeyDec; input a decimal number ; KeyM122: ldi XH,HIGH(sCh1LC) ; channel number ldi XL,LOW(sCh1LC) ldi ZH,HIGH(350) ; maximum ldi ZL,LOW(350) rcall KeyGetParam ; Parameter in X to input and maximum to Z ldi XH,HIGH(KeyM122R) ; Return adress in X ldi XL,LOW(KeyM122R) ldi ZH,HIGH(2*KeyTxtM122) ; Text adress in Z ldi ZL,LOW(2*KeyTxtM122) rjmp KeyDec; input a decimal number ; KeyM123: ldi XH,HIGH(sCh1LW) ; channel number ldi XL,LOW(sCh1LW) ldi ZH,HIGH(9999) ; maximum ldi ZL,LOW(9999) rcall KeyGetParam ; Parameter in X to input and maximum to Z ldi XH,HIGH(KeyM123R) ; Return adress in X ldi XL,LOW(KeyM123R) ldi ZH,HIGH(2*KeyTxtM123) ; Text adress in Z ldi ZL,LOW(2*KeyTxtM123) rjmp KeyDec; input a decimal number ; KeyM124: ldi XH,HIGH(sCh1MC) ; channel number ldi XL,LOW(sCh1MC) ldi ZH,HIGH(100) ; maximum ldi ZL,LOW(100) rcall KeyGetParam ; Parameter in X to input and maximum to Z ldi XH,HIGH(KeyM124R) ; Return adress in X ldi XL,LOW(KeyM124R) ldi ZH,HIGH(2*KeyTxtM124) ; Text adress in Z ldi ZL,LOW(2*KeyTxtM124) rjmp KeyDec; input a decimal number ; KeyTxtM121: .DB "Unload=",0 ; KeyTxtM122: .DB "Load I=",0 ; KeyTxtM123: .DB "Capac.=",0 ; KeyTxtM124: .DB "Maint.=",0 ; ; Set the channels unload voltage to the value in sKeyNW ; KeyM121R: ldi XH,HIGH(sCh1UV) ; X to unload voltage ldi XL,LOW(sCh1UV) ldi ZH,HIGH(2*KeyTxtM121D) ; Z to text ldi ZL,LOW(2*KeyTxtM121D) rjmp KeySetParam ; set the channel's parameter ; ; Set the channels load current to the value in sKeyNW ; KeyM122R: ldi XH,HIGH(sCh1LC) ; X to load current ldi XL,LOW(sCh1LC) ldi ZH,HIGH(2*KeyTxtM122D) ; Z to text ldi ZL,LOW(2*KeyTxtM122D) rjmp KeySetParam ; set the channel's parameter ; ; Set the channels nominal capacity to the value in sKeyNW ; KeyM123R: ldi XH,HIGH(sCh1LW) ; X to capacity ldi XL,LOW(sCh1LW) ldi ZH,HIGH(2*KeyTxtM123D) ; Z to text ldi ZL,LOW(2*KeyTxtM123D) rjmp KeySetParam ; set the channel's parameter ; ; Set the channels maintain current to the value in sKeyNW ; KeyM124R: ldi XH,HIGH(sCh1MC) ; X to maintain current ldi XL,LOW(sCh1MC) ldi ZH,HIGH(2*KeyTxtM124D) ; Z to text ldi ZL,LOW(2*KeyTxtM124D) rjmp KeySetParam ; set the channel's parameter ; KeyTxtM121D: .DB "Unload set",0,0 ; KeyTxtM122D: .DB "Load set",0,0 ; KeyTxtM123D: .DB "Capac. set",0,0 ; KeyTxtM124D: .DB "Maint. set",0,0 ; ;.EQU sKeyNC = $00ED ; Decimal number input position ;.EQU sKeyNW = $00EE ; Decimal number in and output word ;.EQU sKeyNM = $00F0 ; Decimal number maximum value ;.EQU sKeyJR = $00F2 ; Jump adress on number input ready ;.EQU sKeyJS = $00F4 ; Jump adress on skip number input ;.EQU sKeyJ1 = $00F6 ; Jump adress on key 1 ;.EQU sKeyJ2 = $00F8 ; dto., key 2 ;.EQU sKeyJ3 = $00FA ; dto., key 3 ; ; Select a command ; KeyM13: clr rmp sts sKeyNC,rmp ldi XH,HIGH(2*KeyTxtM13) ; Menue text ldi XL,LOW(2*KeyTxtM13) rcall KeyMOut ; Display menue part KeyM13a: ldi rmp,LOW(KeyM1) ; Set left key jump adress sts sKeyJ1,rmp ldi rmp,HIGH(KeyM1) sts sKeyJ1+1,rmp ldi rmp,LOW(KeyM13Up) ; Set middle key jump adress sts sKeyJ2,rmp ldi rmp,HIGH(KeyM13Up) sts sKeyJ2+1,rmp ret ; ; Menue 13 Up key routine ; KeyM13Up: lds rmp,sKeyNC inc rmp sts sKeyNC,rmp ldi XH,HIGH(2*KeyTxtM13) ; Menue text ldi XL,LOW(2*KeyTxtM13) rjmp KeyMOut ; ; Command Menues, sets sState of the selected channel in sKeyCh ; KeyM131: ; set sState to unload ldi rmp,0x01 rcall KeyChSet clr rmp rcall KeySetPwm rcall KeyClrCap ldi rmp,0x08 ; set the channel's unload bit lds R0,sKeyCh KeyM131b: lsl rmp dec R0 brne KeyM131b or rPwmOut,rmp ; set the channel's unload bit ldi XH,HIGH(KeyM13a) ldi XL,LOW(KeyM13a) ldi ZH,HIGH(2*KeyTxtM131D) ldi ZL,LOW(2*KeyTxtM131D) rjmp KeyMDone ; KeyM132: ; set sState to load ldi rmp,0x01 rcall KeyChSet rcall KeyClrUnl ; clear the channel's unload bit rcall KeyClrCap ldi rmp,128 ; set pwm to 1100 mV rcall KeySetPwm ldi XH,HIGH(KeyM13a) ldi XL,LOW(KeyM13a) ldi ZH,HIGH(2*KeyTxtM132D) ldi ZL,LOW(2*KeyTxtM132D) rjmp KeyMDone ; KeyM133: ; set sState to maintain ldi rmp,0x01 rcall KeyChSet rcall KeyClrUnl ; clear the channel's unload bit ldi rmp,128 ; set the pwm to 1100 mV rcall KeySetPwm ldi XH,HIGH(KeyM13a) ldi XL,LOW(KeyM13a) ldi ZH,HIGH(2*KeyTxtM133D) ldi ZL,LOW(2*KeyTxtM133D) rjmp KeyMDone ; KeyM134: ; clear sState clr rmp rcall KeyChSet rcall KeyClrUnl clr rmp rcall KeySetPwm rcall KeyClrCap ldi XH,HIGH(KeyM13a) ldi XL,LOW(KeyM13a) ldi ZH,HIGH(2*KeyTxtM134D) ldi ZL,LOW(2*KeyTxtM134D) rjmp KeyMDone ; KeyTxtM131D: .DB "Ch unload",0 KeyTxtM132D: .DB "Ch load",0 KeyTxtM133D: .DB "Ch maint ",0 KeyTxtM134D: .DB "Ch clear ",0 ; ; =================== Menue tables =================== ; ; Menue 1 ; KeyTxtM1: .DB "Select...#",0,18 .DW KeyM11 .DB "Set...# ",0,15 .DW KeyM12 .DB "Command...# ",0,19 .DW KeyM13 .DW 0xFFFF ; KeyTxtM11: .DB "Akku...#",0,16 .DW KeyM111 .DB "Channel...# ",0,19 .DW KeyM112 .DB "Directload# ",0,19 .DW KeyM113 .DW 0xFFFF ; KeyTxtM12: .DB "Unload...#",0,18 .DW KeyM121 .DB "Load...#",0,16 .DW KeyM122 .DB "Capacity..# ",0,19 .DW KeyM123 .DB "Maintain..# ",0,19 .DW KeyM124 .DW 0xFFFF ; KeyTxtM13: .DB "Unload...#",0,18 .DW KeyM131 .DB "Load...#",0,16 .DW KeyM132 .DB "Maintain..# ",0,19 .DW KeyM133 .DB "Clear...# ",0,17 .DW KeyM134 .DW 0xFFFF ;