Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;******************************************************************************
- ; CS 107: Computer Architecture and Organization
- ;
- ; Project: L03_LCD
- ; Filename: lcd.s
- ; Author: Leonard Euler
- ; Semester: Fall 2049
- ; Description: This is the driver routines for the LCD Keypad Shield. The pinouts for
- ; the board are as follows:
- ;
- ; | LCD Hardware | Arduino Pin | LPC 4088 Port |
- ; |:------------:|:-----------:|:-------------:|
- ; | D4 | D4 | P0.5 |
- ; | D5 | D5 | P5.0 |
- ; | D6 | D6 | P5.1 |
- ; | D7 | D7 | P0.4 |
- ; | RS | D8 | P5.3 |
- ; | E | D9 | P5.4 |
- ; | Backlight | D10 | P0.6 |
- ; | Buttons | A0 | P0.23 |
- ;
- ;******************************************************************************
- BACKLIGHT_ON EQU 0x01
- BACKLIGHT_OFF EQU 0x00
- SET_LOW EQU 0x00
- SET_HIGH EQU 0x01
- GPIO_BASE EQU 0x20098000
- SET0 EQU 0x018
- CLR0 EQU 0x01C
- SET1 EQU 0x038
- CLR1 EQU 0x03C
- SET5 EQU 0x0B8
- CLR5 EQU 0x0BC
- AREA LCDCODE, CODE, READONLY, ALIGN=10
- IMPORT DELAY_1_MS
- IMPORT DELAY_2_MS
- ;******************************************************************************
- ; Initializes the LCD hardware.
- ;
- ; void LCD_INIT()
- ;
- ; D4 - D7 are I/O, RS, E, RW, and backlight are digital I/O outputs only. All
- ; I/O pins are outputs because the LCD Keypad Shield has the R/W* pin grounded
- ; so you can only write to it. Once the pins (and ports) are setup you need to
- ; program a sequence based on the one shown in Figure 24.
- ;******************************************************************************
- LCD_INIT PROC
- EXPORT LCD_INIT [WEAK]
- PUSH {r0-r7, lr}
- MOV r0, #20
- Loop
- CMP r0, #0
- BEQ exit
- PUSH {r0}
- BL DELAY_2_MS ;Wait 40 ms
- POP {r0}
- SUBS r0, #1
- B Loop
- exit
- MOV r0, #0
- LDR r1,=0x4002C014
- STR r0, [r1]
- LDR r1,=0x4002C280
- STR r0, [r1]
- LDR r1,=0x4002C284
- STR r0, [r1]
- LDR r1,=0x4002C010
- STR r0, [r1]
- LDR r1,=0x4002C28C
- STR r0, [r1]
- LDR r1,=0x4002C290
- STR r0, [r1]
- LDR r1,=0x4002C018
- STR r0, [r1]
- LDR r1,=0x4002C05C
- STR r0, [r1]
- LDR r1,=GPIO_BASE
- STR r0, [r1]
- LDR r0,=2_100000000000000001110000
- STR r0, [r1, #0x00]
- LDR r0,=2_11011
- STR r0, [r1, #0xA0]
- BL DELAY_1_MS ;Wait 1 ms
- PUSH {r4}
- MOV r4, #SET_LOW
- BL SET_RS ;Initialize RS
- POP {r4}
- PUSH {r4}
- MOV r4, #SET_HIGH
- BL SET_E ;Initialize RS
- POP {r4}
- PUSH {r4}
- MOV r4, #2_0011 ;Function set 8 bit
- BL WRITE_LS_NYBBLE
- POP {r4}
- BL DELAY_2_MS
- BL DELAY_2_MS ;Wait 6 ms
- BL DELAY_2_MS
- PUSH {r4}
- MOV r4, #2_0011 ;Function set 8 bit
- BL WRITE_LS_NYBBLE
- POP {r4}
- BL DELAY_1_MS ;Wait 1 ms
- PUSH {r4}
- MOV r4, #2_0011 ;Function set 8 bit
- BL WRITE_LS_NYBBLE
- POP {r4}
- BL DELAY_2_MS
- PUSH {r4}
- MOV r4, #2_0010 ;Function 8 bit
- BL WRITE_LS_NYBBLE
- POP {r4}
- BL DELAY_2_MS ;Wait 2 ms
- PUSH {r4}
- MOV r4, #2_00101000 ;Display 2 lines, font size
- BL WRITE_COMMAND
- POP {r4}
- BL DELAY_2_MS ;Wait 2 ms
- PUSH {r4}
- MOV r4, #2_00001000 ;Display Off
- BL WRITE_COMMAND
- POP {r4}
- BL DELAY_2_MS ;Wait 2 ms
- PUSH {r4}
- MOV r4, #2_00000001 ;Clear Display
- BL WRITE_COMMAND
- POP {r4}
- BL DELAY_2_MS ;Wait 2 ms
- PUSH {r4}
- MOV r4, #2_00000110 ;Display increments no write, not shifted
- BL WRITE_COMMAND
- POP {r4}
- BL DELAY_2_MS
- PUSH {r4}
- MOV r4, #2_00001111 ;Display ON, set cursor ON, set cursor to blink
- BL WRITE_COMMAND
- POP {r4}
- BL DELAY_2_MS ;Wait 2ms
- POP {r0-r7, pc}
- ; Your code goes here.
- ENDP
- ;******************************************************************************
- ; Writes a string to the first or second line of the LCD Keypad Shield.
- ;
- ; void WRITE_CSTRING(uchar_32 line, char *string)
- ;
- ; r4 contains which line with 0 being the top line and 1 the bottom. r5
- ; contains the address of the first character to be output. When writing a
- ; character be sure to wait 2 ms between characters.
- ;******************************************************************************
- WRITE_CSTRING PROC
- EXPORT WRITE_CSTRING [WEAK]
- PUSH {r0-r7, lr}
- POP {r0-r7, pc}
- ENDP
- ;******************************************************************************
- ; Writes a command byte to the LCD Keypad Shield
- ;
- ; void WRITE_COMMAND(uint_32 value)
- ;
- ; r4 contains the value to write. This routine simply sets the RS signal and
- ; calls WRITE_BYTE.
- ;******************************************************************************
- WRITE_COMMAND PROC
- EXPORT WRITE_COMMAND [WEAK]
- PUSH {r0-r7, lr}
- PUSH {r4}
- MOV r4, #SET_LOW
- BL SET_RS
- POP {r4}
- BL WRITE_BYTE
- POP {r0-r7, pc}
- ENDP
- ;******************************************************************************
- ; Writes a data byte to the LCD Keypad Shield
- ;
- ; void WRITE_COMMAND(uint_32 value)
- ;
- ; r4 contains the value to write. This routine simply sets the RS signal and
- ; calls WRITE_BYTE.
- ;******************************************************************************
- WRITE_DATA PROC
- EXPORT WRITE_DATA [WEAK]
- PUSH {r0-r7, lr}
- PUSH {r4}
- MOV r4, #SET_HIGH
- BL SET_RS
- POP {r4}
- PUSH {r4}
- BL WRITE_BYTE
- POP {r4}
- POP {r0-r7, pc}
- ENDP
- ;******************************************************************************
- ; Writes a byte to the LCD Keypad Shield
- ;
- ; void WRITE_BYTE(uint_32 value)
- ;
- ; r4 contains the value to write. We should set the RS signal before calling
- ; this routine. Setting RS to LOW gives us a command and setting RS to HIGH
- ; gives us a data command. Since our LCD Keypad Shield is using a 4-bit
- ; interface we need to send out the MS nybble first followed by the LS nybble.
- ;******************************************************************************
- WRITE_BYTE PROC
- EXPORT WRITE_BYTE [WEAK]
- PUSH {r0-r7, lr}
- MOV r3, r4
- LSR r4, r3, #4
- PUSH {r3,r4}
- BL WRITE_LS_NYBBLE
- POP {r3,r4}
- MOV r4, r3
- PUSH {r3,r4}
- BL WRITE_LS_NYBBLE
- POP {r3,r4}
- POP {r0-r7, pc}
- ENDP
- ;******************************************************************************
- ; Writes the LS nybble to the LCD Keypad Shield.
- ;
- ; void WRITE_LS_NYBBLE(uint_32 value)
- ;
- ; r4 contains the value to write. It is assumed that the RS line has already
- ; been set to the proper value. Be sure to set E to HIGH, output the data, and
- ; set E to LOW to write the data to the LCD Keypad Shield.
- ;******************************************************************************
- WRITE_LS_NYBBLE PROC
- EXPORT WRITE_LS_NYBBLE [WEAK]
- ; | LCD Hardware | Arduino Pin | LPC 4088 Port |
- ; |:------------:|:-----------:|:-------------:|
- ; | D4 | D4 | P0.5 |
- ; | D5 | D5 | P5.0 |
- ; | D6 | D6 | P5.1 |
- ; | D7 | D7 | P0.4 |
- PUSH {r0-r7, lr}
- LDR r9,=GPIO_BASE
- MOV r0, #2_110000
- MOV r1, #2_11 ;LSR each bit in the nybble to set the value in the pins D4-D7
- ;example: 1010 -> D4-D7
- ;r1 AND r1 - > 2_100000, 2_1, 2_10, 2_10000
- STR r0, [r9, #CLR0]
- STR r1, [r9, #CLR5]
- PUSH {r4}
- MOV r4, #SET_HIGH
- BL SET_E
- POP {r4}
- MOV r0, #0
- MOV r1, #0
- LSRS r4, r4, #1
- ADDCS r0, #2_100000
- LSRS r4, r4, #1
- ADDCS r1, #2_1
- LSRS r4, r4, #1
- ADDCS r1, #2_10
- LSRS r4, r4, #1
- ADDCS r0, #2_10000
- STR r0, [r9, #SET0]
- STR r1, [r9, #SET5]
- PUSH {r4}
- MOV r4, #SET_LOW
- BL SET_E
- POP {r4}
- POP {r0-r7, pc}
- ENDP
- ;******************************************************************************
- ; Sets the RS data line to the value passed.
- ;
- ; void SET_RS(uint_32 status)
- ;
- ; r4 contains the value to set RS. RS is bit P5.3 which is already set to output.
- ;******************************************************************************
- SET_RS PROC
- EXPORT SET_RS [WEAK]
- PUSH {r0-r7, lr}
- LDR r9,=GPIO_BASE
- LDR r10,=2_1000
- CMP r4, #0
- BEQ set0R
- BNE set1R
- set1R
- STR r10, [r9, #SET5]
- POP {r0-r7, pc}
- set0R
- STR r10, [r9, #CLR5]
- POP {r0-r7, pc}
- ENDP
- ;******************************************************************************
- ; Sets the E data line to the value passed.
- ;
- ; void SET_E(uint_32 status)
- ;
- ; r4 contains the value to set E. E is bit P5.4 which is already set to output.
- ;******************************************************************************
- SET_E PROC
- EXPORT SET_E [WEAK]
- PUSH {r0-r7, lr}
- LDR r9,=GPIO_BASE
- LDR r10,=2_10000
- CMP r4, #0
- BEQ set0E
- BNE set1E
- set1E
- STR r10, [r9, #SET5]
- POP {r0-r7, pc}
- set0E
- STR r10, [r9, #CLR5]
- POP {r0-r7, pc}
- ENDP
- ;******************************************************************************
- ; Turns on or off the LCD backlight. The parameter status is passed on the
- ; stack.
- ;
- ; void LCD_BACKLIGHT(int status)
- ;
- ; status - 1 turn on backlight, 0 - turn off backlight
- ;******************************************************************************
- LCD_BACKLIGHT PROC
- EXPORT LCD_BACKLIGHT [WEAK]
- PUSH {r0-r7, lr}
- LDR r8, [sp, #0x24]
- LDR r9,=GPIO_BASE
- CMP r8, #0
- LDR r10,=2_1000000
- BEQ tOFF
- BNE tON
- tON
- STR r10, [r9, #SET0]
- POP {r0-r7, pc}
- tOFF
- STR r10, [r9, #CLR0]
- POP {r0-r7, pc}
- ENDP
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement