; ************************************************************** ; * Include file LCD routines for Akkuload, Version 0.1 02/05 * ; * (C)2005 by Gerhard Schmidt, info@avr-asm-tutorial.net * ; ************************************************************** ; ; -------------------------------------------------------------- ; Provides Uses Function performed ; -------------------------------------------------------------- ; LcdInit rmp,R0,Z Inits the display from scratch to: ; 8-bit-interface, 4 lines, no shift, ; active cursor and blinking ; LcdR0 rmp outputs the character in R0 on the ; current position of the LCD, R0 is ; preserved ; LcdChar rmp,R0 outputs the character in rmp on the ; current position of the LCD, rmp is ; changed and preserved in R0 ; LcdDisplZ rmp,R0,Z output text in flash at adress Z to Lcd, ; stop at null char ; LcdLine rmp sets input cursor of the LCD to the ; selected line in rmp, expects 0..3 in ; rmp for line 1..4 ; LcdLineCl rmp,R0,Z clears the line that rmp points to by ; writing blanks to it ; LcdPos rmp,Z sets the LCD to the position in Z, ; ZH is the line, ZL is the position in ; that line ; LcdMClr rmp clears the menue part and sets position ; to the beginning of this area ; LcdMStrt rmp,R0,Z Sets the LCD cursor position to the ; menue start ; LcdCursor rmp,Z Sets the LCD cursor to its correct ; current position, position<8: display ; menue ; LcdHex2 rmp writes the content of rmp in Hex to the ; LCD's current position ; LcdDec5 rmp,R0,Z writes the binary number in R3:R2 as ; LcdDec4 decimal to the LCD's current position, ; LcdDec3 5, 4, 3 or 2 digits are displayed ; LcdDec2 ; -------------------------------------------------------------- ; ; Constants ; .EQU pLcdCO = PORTD .EQU pLcdCD = DDRD .EQU pLcdCI = PIND .EQU pLcdDO = PORTB .EQU pLcdDD = DDRB .EQU pLcdDI = PINB .EQU bLcdE = 2 ; E of the display .EQU bLcdRw = 3 ; Read/Write control of the display .EQU bLcdRs = 4 ; Register select of the display ; ; Delays for the LCD display initialisation ; Number of clocks including rcall: 3+7+4*Z-4+7 = 4*Z+13 ; Delay in s: (4*Z+13)/8 ; Calculating Z = (8*t[s]-13)/4 ; ; Delay 15 ms ; .EQU cLcdWt15000 = (8*15000-13)/4 ; = 29996 LcdWt15000: ldi ZH,HIGH(cLcdWt15000) ; 1 ldi ZL,LOW(cLcdWt15000) ; 2 rjmp LcdWt ; 4 ; ; Delay 4,1 ms ; .EQU cLcdWt4100 = (8*4100-13)/4 ; = 8196 LcdWt4100: ldi ZH,HIGH(cLcdWt4100) ; 1 ldi ZL,LOW(cLcdWt4100) rjmp LcdWt ; ; Delay 4.5 ms ; .EQU cLcdWt4500 = (4500*8-13)/4 LcdWt4500: ldi ZH,HIGH(cLcdWt4500) ; 1 ldi ZL,LOW(cLcdWt4500) ; 2 rjmp LcdWt ; 4 ; ; Delay 1.64 ms ; .EQU cLcdWt1640 = (1640*8-13)/4 ; = 3276 LcdWt1640: ldi ZH,HIGH(cLcdWt1640) ; 1 ldi ZL,LOW(cLcdWt1640) ; 2 rjmp LcdWt ; 4 ; ; Delay 100 s ; .EQU cLcdWt100 = (100*8-13)/4 LcdWt100: ldi ZH,HIGH(cLcdWt100) ldi ZL,LOW(cLcdWt100) rjmp LcdWt ; ; Delay 40 s ; .EQU cLcdWt40 = (40*8-13)/4 ; = 76 LcdWt40: ldi ZH,HIGH(cLcdWt40) ; 1 ldi ZL,LOW(cLcdWt40) ; 2 nop ; 3 nop ; 4 ; ; Waits for Z delay ; Number of clocks including ret = 4*(Z-1)+7 ; Delay in s @8Mcs/s: (4*(Z-1)+7)/8 ; LcdWt: sbiw ZL,1 ; 2 brne LcdWt ; 2/1 ret ; 4 ; ; Delay for an active E pulse is 1 s ; LcdDel1: nop ret ; ; Activate E for 1 s ; LcdE: sbi pLcdCO,bLcdE ; set E rcall LcdDel1 ; 1 s Delay cbi pLcdCO,bLcdE ; clear E ret ; ; Check if Lcd is busy after sending a character ; LcdChck: cbi pLcdCO,bLcdRw ; Write data sbi pLcdCO,bLcdRs ; set RS clr rmp ; all data bits to input out pLcdDD,rmp ser rmp ; switch the pullup-resistors on out pLcdDO,rmp cbi pLcdCO,bLcdRs ; clr Rs sbi pLcdCO,bLcdRw ; set Rw sbi pLcdCO,bLcdE ; activate E in rmp,pLcdDI ; read display tst rmp ; jump if adress and busy flag are not zero sbr rFlg,1<2, set line 4 rjmp LcdLine4 LcdLine1: clr rmp ; Line 1 starts at 0 rjmp LcdLine4 LcdLine2: ldi rmp,0x40 ; Line 2 starts at 0x40 rjmp LcdLine4 LcdLine3: ldi rmp,20 ; Line 3 starts at 20 LcdLine4: sbr rmp,0x80 rjmp LcdCtrl ; ; Lcd clear line ; LcdLineCl: mov ZH,rmp ; save line number rcall LcdLine ; set line ldi rmp,' ' ; blank mov R0,rmp ; move to R0 ldi ZL,20 ; ZL is counter LcdLineCl1: rcall LcdR0 ; write blank dec ZL ; next brne LcdLineCl1 ; again mov rmp,ZH ; restore rmp rjmp LcdLine ; ; LcdPos sets the LCD to the position in Z ; LcdPos: cpi ZH,1 ; line = 0 or 1 brcs LcdPos1 ; ZH=0, set line 1 breq LcdPos2 ; ZH=1, set line 2 cpi ZH,2 breq LcdPos3 ; ZH=2, set line 3 ldi rmp,0x54 ; ZH>2, set line 4 rjmp LcdPos4 LcdPos1: clr rmp ; Line 1 starts at 0 rjmp LcdPos4 LcdPos2: ldi rmp,0x40 ; Line 2 starts at 0x40 rjmp LcdPos4 LcdPos3: ldi rmp,20 ; Line 3 starts at 20 LcdPos4: add rmp,ZL ; add position in line sbr rmp,0x80 rjmp LcdCtrl ; ; Sets the LCD cursor to its correct position ; LcdCursor: sbrs rFlg,bLcdOk ; is the Lcd ok? ret lds rmp,sLcdCs ; read cursor position cpi rmp,8 ; minimum position brcc LcdCursor1 rcall KeyMenueFirst ; display menue on line LcdCursor1: ldi ZH,3 ; Line 3 lds ZL,sLcdCs ; read cursor position again rjmp LcdPos ; ; LCDHEX2 writes the content of rmp in Hex ; LcdHex2: push rmp swap rmp rcall LcdHexN pop rmp LcdHexN: andi rmp,0x0F cpi rmp,0x0A brcs LcdHexN1 subi rmp,-7 LcdHexN1: subi rmp,-'0' rcall LcdChar ret ; ; LcdDecDigit subtracts the decimal and writes the digit ; LcdDecDigit: clr rmp ; counts during subtraction LcdDecDigit1: cp R2,ZL ; compare number LSB cpc R3,ZH ; dto., MSB brcs LcdDecDigit2 ; subtraction ended sub R2,ZL ; subtract LSB sbc R3,ZH ; dto., MSB inc rmp ; count number of subtractions rjmp LcdDecDigit1 ; go on LcdDecDigit2: tst rmp ; zero times? brne LcdDecDigit3 ; no tst R0 ; check leading zero still active brne LcdDecDigit3 ldi rmp,' ' ; leading blank rcall LcdChar ; display blank clr R0 ret LcdDecDigit3: subi rmp,-'0' ; add ASCII-null rcall LcdChar ; display digit on Lcd clr R0 ; no leading zeros any more inc R0 ret ; ; LcdDec writes the number in R3:R2 in decimal to the display ; 5, 4, 3 or 2 digits are displayed ; LcdDec5: clr R0 ; leading zero flag ldi ZH,HIGH(10000) ldi ZL,LOW(10000) rcall LcdDecDigit LcdDec4: ldi ZH,HIGH(1000) ldi ZL,LOW(1000) rcall LcdDecDigit LcdDec3: ldi ZH,HIGH(100) ldi ZL,LOW(100) rcall LcdDecDigit LcdDec2: clr ZH ldi ZL,10 rcall LcdDecDigit ldi rmp,'0' add rmp,R2 rjmp LcdChar ; ; End of routines ; ; Lcd texts ; ; Init text on display ; LcdTxtInit1: .DB "Akkuloader V1.0",0 LcdTxtInit2: .DB "(C)2005 by DG4FAC",0 LcdTxtInit3: .DB "Four channel akku",0 LcdTxtInit4: .DB "loader processor ",0 ; ; End of lcd include file ;