; ************************************************ ; TestLcd clears the LCD-Display and outputs ; a test text in line 1 and 2 of the display ; ************************************************ ; Basics of the LCD operation on the STK200 boad ; Hardware: The 2-line-LCD-Display must be mounted ; on the board and connected correctly. It is recommended ; to connect a 14-pin female connector to the backside ; of the LCD display board that fits the male connector ; on the STK200. That's all for the hardware, all other ; hardware is already on board of the STK200 (lousy ; documentation of this!). ; Software: The access to the LCD is in this case programmed ; in memory-mapped mode, not via I/O commands. This ; has the advantage that the same commands of the RAM ; access can be used, complicated port bits programming ; is avoided and external 32 kB memory can be used in ; parallel. (Example programs for LCD access found in the ; internet are all I/O-mapped and do not run correct with ; the 32 kB memory on board the STK200 in parallel. ; The adress for LCD access is $8000 for commands and ; $C000 for access to the charcater generator and the ; display lines (both read and write). ; As memory-mapped access is too fast for most LCDs ; the WAIT-Bit in the MCUCR register has to be set to insert ; a wait state. This slows down the RAM access, too, but ; should not be a problem in most cases. To speed-up ; RAM access the WAIT-bit could be set to zero during ; times where only RAM access is made and set to 1 again ; when access to the LCD follows. ; Used Ports: The following ports are used, both by LCD and RAM ; access: ; Port A: Alternate use as LSB adress bus and data bus; not ; used during LCD access, but blocked by memory- ; mapped access ; Port C: MSB adress bus for SRAM access; used for LCD ; access: Bit 7 (Adress signal) and 6 (RS signal of ; the LCD) ; Port D: Bit 6 is /RD (Read) on the SRAM, not used by LCD ; access, Bit 7 is /WR (Write) on the SRAM and on the ; LCD ; ; Test program sequence: Sequentially the following steps are ; executed: ; 0. Wait until the LCD is not busy any more ; 1. Clear the LCD ; 2. Set the transfer mode to 8-bit, a fixed display window and ; define other display properties ; 3. Output to lines of text on the LCD window ; Before each operation takes place a LED is switched on ; to allow debugging the single steps. If all steps are executed ; correct LED 4 is on and the text on the LCD is visible ; (if not visible: correct contrast setting of the LCD). ; ; Structure of the software: All LCD operations are programmed as ; subroutines and so can be exported and used in other programs ; easily. Used registers are: mp=Allround register for handing ; values to subroutines; R26/27=XL/XH is a 16-bit-adress ; for SRAM/LCD-access commands ST X and LD X ; ; ; 8515-definitions load .NOLIST .INCLUDE "8515def.inc" .LIST ; Registers .def mp = R16 ; Multi-Purpose .def test = R17 ; Counts the different test phases ; Reset-/Interrupt-Vector rjmp main ; Subroutines for memory-mapped LCD access LcdWt: ; Wait until the LCD-busy-flag is zero ldi XH,0x80 ; Upper Byte of the RAM adress of the LCD ldi XL,0x00 ; Lower Byte of the RAM adress of the LCD ld mp,X ; Read busy flag and AC-Adress rol mp ; Shift bit 7 of the LCD status to the carry flag brcs LcdWt ; If one then LCD is still busy, repeat ret LcdCl: ; Clear the LCD ldi mp,0x01 ; Clear command of the LCD display = 01h LcdBef: ; LCD command in register mp to LCD, if ready push mp ; Command byte in mp is used later, save on stack rcall LcdWt ; Wait until display is not busy any more pop mp ; Recall command byte from stack st X,mp ; Send command to LCD ret ; End of the subroutine LcdInit: ; Init mode of the LCD ldi mp,0b00111000 ; 8-Bit-mode, not 4-Bit-mode rcall LcdBef ; command byte to the LCD ldi mp,0b00000110 ; Increment, display freeze rcall LcdBef ; commad byte to the LCD ldi mp,0b00010000 ; Cursor move, not shift rcall LcdBef ; command byte to the LCD ret ; Return from subroutine LcdBu: ; Write character in register mp on the LCD push mp ; Character used later, save on stack rcall LcdWt ; Wait until LCD is ready to receive pop mp ; Pop character from stack ldi XH,0xC0 ; LCD adress to register pair X st X,mp ; Write character to LCD ret ; Return from subroutine LcdTs: ; Write the word "Test" to the current LCD display line push mp ; Save the line adress in mp rcall LcdWt ; Wait until the LCD is ready pop mp ; Pop line Adress ori mp,0x80 ; Set bit 7 of the line adress rcall LcdBef ; and send to LCD ldi mp,'T' ; Load character T rcall LcdBu ; Write character to the LCD ldi mp,'e' ; Load character e rcall LcdBu ; Write to LCD ldi mp,'s' ; Load charcater s rcall LcdBu ; Write to LCD ldi mp,'t' ; Load character t rcall LcdBu ; Write to LCD ret ; Ready, return back LcdTst: ; Write "Test" to line 1 and 2 of the display ldi mp,0x00 ; Line 1 starts at adress 00h of the display rcall LcdTs ; Write test to line 1 ldi mp,0x40 ; Line 2 starts at adress 40h of the display rcall LcdTs ; Write test to line 2 ldi mp,0b00001111 ; Command for display On, Cursor On and Blink rcall LcdBef ; Command byte to LCD ret ; Return from subroutine ; Main program main: ldi mp,LOW(RAMEND) ;Initiate Stackpointer out SPL,mp ; for the use with subroutines ldi mp,HIGH(RAMEND) out SPH,mp ; Port B is the LED driver ldi mp,0xFF ; All outputs out DDRB,mp ; to data direction register of port B in mp,MCUCR ; Read MCU-Control-Register ori mp,0xC0 ; Set Bit 7 (SRAM) and Bit 6 (WAIT-STATE) out MCUCR,mp ; Here the test of the LCD starts ldi test,0xFE ; Set Bit 0 to 0 = LED 0 on out PORTB,test ; LED 0 on rcall LcdWt ; Wait until LCD isn't busy any more ; if an error happens here, the LED 0 won't go off sec ; Set Carry Flag to 1 rol test ; Shift the zero in test one position left to switch LED 1 on out PORTB,test rcall LcdCl ; Clear the LCD sec ; Set Carry flag to 1 rol test ; and shift test again one position left to switch LED 2 on out PORTB,test rcall LcdInit ; Some intiialisation of the LCD sec ; Set Carry Flag again to 1 rol test ; and shift test left to switch LED 3 on out PORTB,test rcall LcdTst ; Write the testlines sec ; Set Carry flag again to 1 rol test ; and shift test to set LED 4 on out PORTB,test; Test is successfuly completed ende: rjmp ende ; Loop for always