; ******************************************** ; * LCD-Interface routines for multi-purpose * ; * use with the ATMEL STK200 board, Version * ; * 0.1 Beta, (C) 1999 Gerhard Schmidt * ; * Report bugs to info@avr-asm-tutorial.net * ; ******************************************** ; ; Purpose: ; Include file for the AVR assembler ; Supplies the common routines to drive an ; LCD connected to the ATMEL STK200 board ; Works best and is compatible to external ; SRAM on that board (up to 32 kB) ; ; Requires: ; mpr ... Multipurpose register, anything ; between R16 and R31, unchanged ; after all routines ; Memory-mapped operation of the LCD ; Setup of the software stack due to the use ; of relative subroutines and PUSH/POP ; LCD properly connected to the board, otherwise ; processor hangs around and waits for ; the busy flag to go down! (no timeout!) ; 39 words of program space ; ; Interfaces: ; lcd_wt Waits indefinately until the busy ; flag of the LCD is off ; lcd_fc Sends the command byte in register ; mpr to the LCD after busy is off ; lcd_cl Clears the LCD and sets cursor to ; the home position, after busy is off ; lcd_st Sets the LCD to 8-bit-transfer, ; freezes the display window and sets ; cursor to increment after busy is off ; lcd_sc Sets cursor to the display position ; in register mpr (Line 1: 00 .. 0F hex, ; Line 2: 40 .. 4F hex) ; lcd_ch Outputs the character in register ; mpr to the LCD after busy is off ; lcd_on Sets display on, cursor on and blink ; ; Adress definitions: .equ lcd_rs = 0x8000 ; Register select = 0 adress .equ lcd_ds = 0xC000 ; Register select = 1 adress ; ; Subroutines ; ; Wait until LCD is not busy any more ; lcd_wt: push mpr ; save register lcd_wt1: lds mpr,lcd_rs ; read busy flag rol mpr ; Busy = Bit 7 into Carry brcs lcd_wt1 ; still busy, repeat pop mpr ; restore register ret ; ; Outputs the function command in mpr to the LCD ; lcd_fc: rcall lcd_wt ; Wait until not busy any more sts lcd_rs,mpr ; Command byte to LCD ret ; ; Clears LCD and sets cursor to home position ; lcd_cl: push mpr ; save register ldi mpr,0x01 ; the clear command rcall lcd_fc ; output to LCD command pop mpr ; restore register ret ; ; Sets LCD to 8-bit-mode, display window freeze and ; cursor incrementation (standard mode) ; lcd_st: push mpr ; save register ldi mpr,0b00111000 ; 8-Bit-transfer rcall lcd_fc ; to LCD command ldi mpr,0b00000110 ; Increment, display freeze rcall lcd_fc ; to LCD ldi mpr,0b00010000 ; Cursor move, not shift rcall lcd_fc ; to LCD pop mpr ; restore register ret ; ; Sets cursor on the LCD to a certain display position in mpr ; lcd_sc: push mpr ; save position ori mpr,0x80 ; set bit 7 of the position rcall lcd_fc ; position to LCD pop mpr ; restore register ret ; ; Sends a character in mpr to the display at the current ; position, position is incremented after write ; lcd_ch: rcall lcd_wt ; wait for not busy sts lcd_ds,mpr ; transfer character to LCD-Display ret ; ; Sets LCD display on, cursor on and blink on ; lcd_on: push mpr ; save register ldi mpr,0b00001111 ; command byte rcall lcd_fc ; to LCD pop mpr ; restore register ret