Pfad: Home => AVR-Übersicht

Assembler-Quellcode der LCD-Include-Routinen für das STK200

; ***********************************************
; * LCD-Interface routines for multi-purpose *
; * use with the ATMEL STK200 board, Version *
; * 0.1 Beta, (C) 1999 Gerhard Schmidt *
; * Report bugs to info!at!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
©2002 by http://www.avr-asm-tutorial.net