Advertisement
Guest User

Untitled

a guest
Dec 5th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 10.37 KB | None | 0 0
  1. ;******************************************************************************
  2. ; CS 107: Computer Architecture and Organization
  3. ;
  4. ; Project: L03_LCD
  5. ; Filename: lcd.s
  6. ; Author: Leonard Euler
  7. ; Semester: Fall 2049
  8. ; Description: This is the driver routines for the LCD Keypad Shield. The pinouts for
  9. ; the board are as follows:
  10. ;
  11. ;  | LCD Hardware | Arduino Pin | LPC 4088 Port |
  12. ;  |:------------:|:-----------:|:-------------:|
  13. ;  |     D4       |     D4      |      P0.5     |
  14. ;  |     D5       |     D5      |      P5.0     |
  15. ;  |     D6       |     D6      |      P5.1     |
  16. ;  |     D7       |     D7      |      P0.4     |
  17. ;  |     RS       |     D8      |      P5.3     |
  18. ;  |     E        |     D9      |      P5.4     |
  19. ;  |  Backlight   |    D10      |      P0.6     |
  20. ;  |  Buttons     |    A0       |      P0.23    |
  21. ;
  22. ;******************************************************************************
  23. BACKLIGHT_ON    EQU 0x01
  24. BACKLIGHT_OFF   EQU 0x00
  25. SET_LOW         EQU 0x00
  26. SET_HIGH        EQU 0x01
  27.  
  28. GPIO_BASE   EQU 0x20098000
  29. SET0        EQU 0x018
  30. CLR0        EQU 0x01C
  31. SET1        EQU 0x038
  32. CLR1        EQU 0x03C
  33. SET5        EQU 0x0B8
  34. CLR5        EQU 0x0BC
  35.  
  36.                 AREA    LCDCODE, CODE, READONLY, ALIGN=10
  37.                 IMPORT  DELAY_1_MS
  38.                 IMPORT  DELAY_2_MS
  39.  
  40. ;******************************************************************************
  41. ; Initializes the LCD hardware.
  42. ;
  43. ; void LCD_INIT()
  44. ;
  45. ; D4 - D7 are I/O, RS, E, RW, and backlight are digital I/O outputs only. All
  46. ; I/O pins are outputs because the LCD Keypad Shield has the R/W* pin grounded
  47. ; so you can only write to it. Once the pins (and ports) are setup you need to
  48. ; program a sequence based on the one shown in Figure 24.
  49. ;******************************************************************************
  50. LCD_INIT        PROC
  51.                 EXPORT  LCD_INIT                    [WEAK]
  52.  
  53.  
  54.                 PUSH    {r0-r7, lr}
  55.  
  56.                 MOV     r0, #20
  57.  
  58. Loop
  59.                 CMP     r0, #0
  60.                 BEQ     exit
  61.                 PUSH    {r0}
  62.                 BL      DELAY_2_MS          ;Wait 40 ms
  63.                 POP     {r0}
  64.                 SUBS    r0, #1
  65.                 B       Loop
  66. exit
  67.                 MOV     r0, #0
  68.  
  69.                 LDR     r1,=0x4002C014
  70.                 STR     r0, [r1]
  71.  
  72.                 LDR     r1,=0x4002C280
  73.                 STR     r0, [r1]
  74.  
  75.                 LDR     r1,=0x4002C284
  76.                 STR     r0, [r1]
  77.  
  78.                 LDR     r1,=0x4002C010
  79.                 STR     r0, [r1]
  80.  
  81.                 LDR     r1,=0x4002C28C
  82.                 STR     r0, [r1]
  83.  
  84.                 LDR     r1,=0x4002C290
  85.                 STR     r0, [r1]
  86.  
  87.                 LDR     r1,=0x4002C018
  88.                 STR     r0, [r1]
  89.  
  90.                 LDR     r1,=0x4002C05C
  91.                 STR     r0, [r1]
  92.  
  93.  
  94.                 LDR     r1,=GPIO_BASE
  95.                 STR     r0, [r1]
  96.  
  97.                 LDR     r0,=2_100000000000000001110000
  98.                 STR     r0, [r1, #0x00]
  99.  
  100.                 LDR     r0,=2_11011
  101.                 STR     r0, [r1, #0xA0]
  102.  
  103.                 BL      DELAY_1_MS          ;Wait 1 ms
  104.  
  105.                 PUSH    {r4}
  106.                 MOV     r4, #SET_LOW
  107.                 BL      SET_RS              ;Initialize RS
  108.                 POP     {r4}
  109.  
  110.                 PUSH    {r4}
  111.                 MOV     r4, #SET_HIGH
  112.                 BL      SET_E               ;Initialize RS
  113.                 POP     {r4}
  114.  
  115.  
  116.                 PUSH    {r4}
  117.                 MOV     r4, #2_0011                        ;Function set 8 bit
  118.                 BL      WRITE_LS_NYBBLE
  119.                 POP     {r4}
  120.  
  121.                 BL      DELAY_2_MS
  122.                 BL      DELAY_2_MS                         ;Wait 6 ms
  123.                 BL      DELAY_2_MS
  124.  
  125.                 PUSH    {r4}
  126.                 MOV     r4, #2_0011                        ;Function set 8 bit
  127.                 BL      WRITE_LS_NYBBLE
  128.                 POP     {r4}
  129.  
  130.                 BL      DELAY_1_MS                         ;Wait 1 ms
  131.  
  132.         PUSH    {r4}
  133.                 MOV     r4, #2_0011                        ;Function set 8 bit
  134.                 BL      WRITE_LS_NYBBLE
  135.                 POP     {r4}
  136.  
  137.         BL   DELAY_2_MS
  138.  
  139.                 PUSH    {r4}
  140.                 MOV     r4, #2_0010                        ;Function 8 bit
  141.                 BL      WRITE_LS_NYBBLE
  142.                 POP     {r4}
  143.  
  144.                 BL      DELAY_2_MS                         ;Wait 2 ms
  145.  
  146.                 PUSH    {r4}
  147.                 MOV     r4, #2_00101000                  ;Display 2 lines, font size
  148.                 BL      WRITE_COMMAND
  149.                 POP     {r4}
  150.  
  151.                 BL      DELAY_2_MS                         ;Wait 2 ms
  152.  
  153.                 PUSH    {r4}
  154.                 MOV     r4, #2_00001000                  ;Display Off
  155.                 BL      WRITE_COMMAND
  156.                 POP     {r4}
  157.  
  158.                 BL      DELAY_2_MS                         ;Wait 2 ms
  159.  
  160.                 PUSH    {r4}
  161.                 MOV     r4, #2_00000001                ;Clear Display
  162.                 BL      WRITE_COMMAND
  163.                 POP     {r4}
  164.  
  165.                 BL      DELAY_2_MS                         ;Wait 2 ms
  166.  
  167.                 PUSH    {r4}
  168.                 MOV     r4, #2_00000110                  ;Display increments no write, not shifted
  169.                 BL      WRITE_COMMAND
  170.                 POP     {r4}
  171.  
  172.                 BL      DELAY_2_MS
  173.  
  174.                 PUSH    {r4}
  175.                 MOV     r4, #2_00001111                ;Display ON, set cursor ON, set cursor to blink
  176.                 BL      WRITE_COMMAND
  177.                 POP     {r4}
  178.  
  179.                 BL      DELAY_2_MS                         ;Wait 2ms
  180.  
  181.                 POP     {r0-r7, pc}
  182.                 ; Your code goes here.
  183.  
  184.                 ENDP
  185.  
  186.  
  187. ;******************************************************************************
  188. ; Writes a string to the first or second line of the LCD Keypad Shield.
  189. ;
  190. ; void WRITE_CSTRING(uchar_32 line, char *string)
  191. ;
  192. ; r4 contains which line with 0 being the top line and 1 the bottom. r5
  193. ; contains the address of the first character to be output. When writing a
  194. ; character be sure to wait 2 ms between characters.
  195. ;******************************************************************************
  196. WRITE_CSTRING   PROC
  197.                 EXPORT  WRITE_CSTRING                   [WEAK]
  198.  
  199.                 PUSH    {r0-r7, lr}
  200.                 POP     {r0-r7, pc}
  201.  
  202.                 ENDP
  203.  
  204.  
  205. ;******************************************************************************
  206. ; Writes a command byte to the LCD Keypad Shield
  207. ;
  208. ; void WRITE_COMMAND(uint_32 value)
  209. ;
  210. ; r4 contains the value to write. This routine simply sets the RS signal and
  211. ; calls WRITE_BYTE.
  212. ;******************************************************************************
  213. WRITE_COMMAND   PROC
  214.                 EXPORT  WRITE_COMMAND                   [WEAK]
  215.  
  216.                 PUSH    {r0-r7, lr}
  217.  
  218.                 PUSH    {r4}
  219.                 MOV     r4, #SET_LOW
  220.                 BL      SET_RS
  221.                 POP     {r4}
  222.  
  223.                 BL      WRITE_BYTE
  224.  
  225.                 POP     {r0-r7, pc}
  226.  
  227.                 ENDP
  228.  
  229. ;******************************************************************************
  230. ; Writes a data byte to the LCD Keypad Shield
  231. ;
  232. ; void WRITE_COMMAND(uint_32 value)
  233. ;
  234. ; r4 contains the value to write. This routine simply sets the RS signal and
  235. ; calls WRITE_BYTE.
  236. ;******************************************************************************
  237. WRITE_DATA      PROC
  238.  
  239.                 EXPORT  WRITE_DATA                  [WEAK]
  240.  
  241.                 PUSH    {r0-r7, lr}
  242.  
  243.                 PUSH    {r4}
  244.         MOV   r4, #SET_HIGH
  245.                 BL      SET_RS
  246.         POP   {r4}
  247.  
  248.                 PUSH    {r4}
  249.                 BL      WRITE_BYTE
  250.         POP   {r4}
  251.  
  252.                 POP     {r0-r7, pc}
  253.  
  254.                 ENDP
  255.  
  256. ;******************************************************************************
  257. ; Writes a byte to the LCD Keypad Shield
  258. ;
  259. ; void WRITE_BYTE(uint_32 value)
  260. ;
  261. ; r4 contains the value to write. We should set the RS signal before calling
  262. ; this routine. Setting RS to LOW gives us a command and setting RS to HIGH
  263. ; gives us a data command. Since our LCD Keypad Shield is using a 4-bit
  264. ; interface we need to send out the MS nybble first followed by the LS nybble.
  265. ;******************************************************************************
  266. WRITE_BYTE      PROC
  267.  
  268.                 EXPORT  WRITE_BYTE                  [WEAK]
  269.  
  270.                 PUSH    {r0-r7, lr}
  271.  
  272.                 MOV     r3, r4
  273.                 LSR     r4, r3, #4
  274.  
  275.                 PUSH    {r3,r4}
  276.                 BL      WRITE_LS_NYBBLE
  277.                 POP     {r3,r4}
  278.  
  279.                 MOV     r4, r3
  280.  
  281.                 PUSH    {r3,r4}
  282.                 BL      WRITE_LS_NYBBLE
  283.                 POP     {r3,r4}
  284.  
  285.                 POP     {r0-r7, pc}
  286.  
  287.  
  288.  
  289.  
  290.                 ENDP
  291.  
  292. ;******************************************************************************
  293. ; Writes the LS nybble to the LCD Keypad Shield.
  294. ;
  295. ; void WRITE_LS_NYBBLE(uint_32 value)
  296. ;
  297. ; r4 contains the value to write. It is assumed that the RS line has already
  298. ; been set to the proper value. Be sure to set E to HIGH, output the data, and
  299. ; set E to LOW to write the data to the LCD Keypad Shield.
  300. ;******************************************************************************
  301. WRITE_LS_NYBBLE PROC
  302.                 EXPORT  WRITE_LS_NYBBLE                 [WEAK]
  303.  
  304. ;  | LCD Hardware | Arduino Pin | LPC 4088 Port |
  305. ;  |:------------:|:-----------:|:-------------:|
  306. ;  |     D4       |     D4      |      P0.5     |
  307. ;  |     D5       |     D5      |      P5.0     |
  308. ;  |     D6       |     D6      |      P5.1     |
  309. ;  |     D7       |     D7      |      P0.4     |
  310.  
  311.  
  312.                 PUSH    {r0-r7, lr}
  313.  
  314.                 LDR     r9,=GPIO_BASE
  315.  
  316.                 MOV     r0, #2_110000
  317.                 MOV     r1, #2_11                      ;LSR each bit in the nybble to set the value in the pins D4-D7
  318.                                                      ;example: 1010 -> D4-D7
  319.                                                    ;r1 AND r1 - > 2_100000, 2_1, 2_10, 2_10000
  320.                 STR     r0, [r9, #CLR0]
  321.                 STR     r1, [r9, #CLR5]
  322.  
  323.                 PUSH    {r4}
  324.                 MOV     r4, #SET_HIGH
  325.                 BL      SET_E
  326.                 POP     {r4}
  327.  
  328.  
  329.                 MOV     r0, #0
  330.                 MOV     r1, #0
  331.  
  332.                 LSRS    r4, r4, #1
  333.                 ADDCS   r0, #2_100000
  334.  
  335.                 LSRS    r4, r4, #1
  336.                 ADDCS   r1, #2_1
  337.  
  338.                 LSRS    r4, r4, #1
  339.                 ADDCS   r1, #2_10
  340.  
  341.                 LSRS    r4, r4, #1
  342.                 ADDCS   r0, #2_10000
  343.  
  344.                 STR     r0, [r9, #SET0]
  345.                 STR     r1, [r9, #SET5]
  346.  
  347.                 PUSH    {r4}
  348.                 MOV     r4, #SET_LOW
  349.                 BL      SET_E
  350.                 POP     {r4}
  351.  
  352.                 POP     {r0-r7, pc}
  353.  
  354.                 ENDP
  355.  
  356. ;******************************************************************************
  357. ; Sets the RS data line to the value passed.
  358. ;
  359. ; void SET_RS(uint_32 status)
  360. ;
  361. ; r4 contains the value to set RS. RS is bit P5.3 which is already set to output.
  362. ;******************************************************************************
  363. SET_RS          PROC
  364.                 EXPORT  SET_RS                  [WEAK]
  365.  
  366.                 PUSH    {r0-r7, lr}
  367.                 LDR     r9,=GPIO_BASE
  368.                 LDR     r10,=2_1000
  369.                 CMP     r4, #0
  370.                 BEQ     set0R
  371.                 BNE     set1R
  372. set1R
  373.                 STR     r10, [r9, #SET5]
  374.                 POP     {r0-r7, pc}
  375. set0R
  376.                 STR     r10, [r9, #CLR5]
  377.                 POP     {r0-r7, pc}
  378.  
  379.  
  380.                 ENDP
  381.  
  382. ;******************************************************************************
  383. ; Sets the E data line to the value passed.
  384. ;
  385. ; void SET_E(uint_32 status)
  386. ;
  387. ; r4 contains the value to set E. E is bit P5.4 which is already set to output.
  388. ;******************************************************************************
  389. SET_E           PROC
  390.                 EXPORT  SET_E                   [WEAK]
  391.  
  392.                 PUSH    {r0-r7, lr}
  393.                 LDR     r9,=GPIO_BASE
  394.                 LDR     r10,=2_10000
  395.                 CMP     r4, #0
  396.                 BEQ     set0E
  397.                 BNE     set1E
  398. set1E
  399.                 STR     r10, [r9, #SET5]
  400.                 POP     {r0-r7, pc}
  401. set0E
  402.                 STR     r10, [r9, #CLR5]
  403.                 POP     {r0-r7, pc}
  404.  
  405.                 ENDP
  406.  
  407. ;******************************************************************************
  408. ; Turns on or off the LCD backlight. The parameter status is passed on the
  409. ; stack.
  410. ;
  411. ; void LCD_BACKLIGHT(int status)
  412. ;
  413. ; status - 1 turn on backlight, 0 - turn off backlight
  414. ;******************************************************************************
  415. LCD_BACKLIGHT   PROC
  416.  
  417.                 EXPORT  LCD_BACKLIGHT                   [WEAK]
  418.  
  419.                 PUSH    {r0-r7, lr}
  420.  
  421.                 LDR     r8, [sp, #0x24]
  422.                 LDR     r9,=GPIO_BASE
  423.  
  424.                 CMP     r8, #0
  425.                 LDR     r10,=2_1000000
  426.  
  427.                 BEQ     tOFF
  428.                 BNE     tON
  429. tON
  430.                 STR     r10, [r9, #SET0]
  431.                 POP     {r0-r7, pc}
  432. tOFF
  433.                 STR     r10, [r9, #CLR0]
  434.                 POP     {r0-r7, pc}
  435.  
  436.  
  437.                 ENDP
  438.  
  439.                 END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement