Advertisement
Guest User

Untitled

a guest
Nov 27th, 2019
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 10.70 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_LOW
  112.                 BL      SET_E               ;Initialize RS
  113.                 POP     {r4}
  114.                
  115.  
  116.                 PUSH    {r4}
  117.                 MOV     r4, #2_00010011                        ;Function set 8 bit
  118.                 BL      WRITE_COMMAND
  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_00010011                        ;Function set 8 bit
  127.                 BL      WRITE_COMMAND
  128.                 POP     {r4}
  129.  
  130.                 BL      DELAY_1_MS                         ;Wait 1 ms
  131.  
  132.                 PUSH    {r4}
  133.                 MOV     r4, #2_00000010                        ;Function 8 bit
  134.                 BL      WRITE_COMMAND
  135.                 POP     {r4}
  136.  
  137.                 BL      DELAY_2_MS                         ;Wait 2 ms
  138.  
  139.                 PUSH    {r4}
  140.                 MOV     r4, #2_00101000                  ;Display 2 lines, font size
  141.                 BL      WRITE_COMMAND
  142.                 POP     {r4}
  143.  
  144.                 BL      DELAY_2_MS                         ;Wait 2 ms
  145.  
  146.                 PUSH    {r4}
  147.                 MOV     r4, #2_00001000                  ;Display Off
  148.                 BL      WRITE_COMMAND
  149.                 POP     {r4}
  150.  
  151.                 BL      DELAY_2_MS                         ;Wait 2 ms
  152.  
  153.                 PUSH    {r4}
  154.                 MOV     r4, #2_00000001                ;Clear Display
  155.                 BL      WRITE_COMMAND
  156.                 POP     {r4}
  157.  
  158.                 BL      DELAY_2_MS                         ;Wait 2 ms
  159.  
  160.                 PUSH    {r4}
  161.                 MOV     r4, #2_00000110                  ;Display increments no write, not shifted
  162.                 BL      WRITE_COMMAND
  163.                 POP     {r4}
  164.  
  165.                 BL      DELAY_2_MS
  166.  
  167.                 PUSH    {r4}
  168.                 MOV     r4, #2_00001111                ;Display ON, set cursor ON, set cursor to blink
  169.                 BL      WRITE_COMMAND
  170.                 POP     {r4}
  171.  
  172.                 BL      DELAY_2_MS                         ;Wait 2ms
  173.  
  174.                 POP     {r0-r7, pc}
  175.                 ; Your code goes here.
  176.  
  177.                 ENDP
  178.  
  179.  
  180. ;******************************************************************************
  181. ; Writes a string to the first or second line of the LCD Keypad Shield.
  182. ;
  183. ; void WRITE_CSTRING(uchar_32 line, char *string)
  184. ;
  185. ; r4 contains which line with 0 being the top line and 1 the bottom. r5
  186. ; contains the address of the first character to be output. When writing a
  187. ; character be sure to wait 2 ms between characters.
  188. ;******************************************************************************
  189. WRITE_CSTRING   PROC
  190.                 EXPORT  WRITE_CSTRING                   [WEAK]
  191.  
  192.                 PUSH    {r0-r7, lr}
  193.                
  194.                 ;Determine address for line in DDRAM
  195.                 MOV     r3, #2_10000000
  196.                 CMP     r4, #0
  197.                 ADDNE   r3, #2_1000000
  198.                
  199.                 PUSH    {r3,r4}
  200.                 MOV     r4, r3
  201.                 BL      WRITE_COMMAND
  202.                 POP     {r3,r4}
  203.                
  204.                 ;Write Characters
  205.                 MOV     r1, #0
  206. Loopie         
  207.                 BL      DELAY_2_MS
  208.                
  209.                 LDRB    r0, [r5, r1]
  210.                
  211.                 CMP     r0, #0
  212.                 BEQ     OUTTIE
  213.                 PUSH    {r0, r1, r4}
  214.                 MOV     r4, r0
  215.                 BL      WRITE_DATA
  216.                 POP     {r0, r1, r4}
  217.                
  218.                 ADD     r1, #1
  219.                 B       Loopie
  220.                
  221. OUTTIE
  222.  
  223.                 POP     {r0-r7, pc}
  224.  
  225.                 ENDP
  226.  
  227.  
  228. ;******************************************************************************
  229. ; Writes a command byte to the LCD Keypad Shield
  230. ;
  231. ; void WRITE_COMMAND(uint_32 value)
  232. ;
  233. ; r4 contains the value to write. This routine simply sets the RS signal and
  234. ; calls WRITE_BYTE.
  235. ;******************************************************************************
  236. WRITE_COMMAND   PROC
  237.                 EXPORT  WRITE_COMMAND                   [WEAK]
  238.  
  239.                 PUSH    {r0-r7, lr}
  240.  
  241.                 PUSH    {r4}
  242.                 MOV     r4, #SET_LOW
  243.                 BL      SET_RS
  244.                 POP     {r4}
  245.  
  246.                 BL      WRITE_BYTE
  247.  
  248.                 POP     {r0-r7, pc}
  249.  
  250.                 ENDP
  251.  
  252. ;******************************************************************************
  253. ; Writes a data byte to the LCD Keypad Shield
  254. ;
  255. ; void WRITE_COMMAND(uint_32 value)
  256. ;
  257. ; r4 contains the value to write. This routine simply sets the RS signal and
  258. ; calls WRITE_BYTE.
  259. ;******************************************************************************
  260. WRITE_DATA      PROC
  261.  
  262.                 EXPORT  WRITE_DATA                  [WEAK]
  263.  
  264.                 PUSH    {r0-r7, lr}
  265.  
  266.                 PUSH    {r4}
  267.                 MOV   r4, #SET_HIGH
  268.                 BL      SET_RS
  269.                 POP   {r4}
  270.  
  271.                 PUSH    {r4}
  272.                 BL      WRITE_BYTE
  273.                 POP   {r4}
  274.  
  275.                 POP     {r0-r7, pc}
  276.  
  277.                 ENDP
  278.  
  279. ;******************************************************************************
  280. ; Writes a byte to the LCD Keypad Shield
  281. ;
  282. ; void WRITE_BYTE(uint_32 value)
  283. ;
  284. ; r4 contains the value to write. We should set the RS signal before calling
  285. ; this routine. Setting RS to LOW gives us a command and setting RS to HIGH
  286. ; gives us a data command. Since our LCD Keypad Shield is using a 4-bit
  287. ; interface we need to send out the MS nybble first followed by the LS nybble.
  288. ;******************************************************************************
  289. WRITE_BYTE      PROC
  290.  
  291.                 EXPORT  WRITE_BYTE                  [WEAK]
  292.  
  293.                 PUSH    {r0-r7, lr}
  294.  
  295.                 MOV     r3, r4
  296.                 LSR     r4, r3, #4
  297.  
  298.                 PUSH    {r3,r4}
  299.                 BL      WRITE_LS_NYBBLE
  300.                 POP     {r3,r4}
  301.  
  302.                 MOV     r4, r3
  303.  
  304.                 PUSH    {r3,r4}
  305.                 BL      WRITE_LS_NYBBLE
  306.                 POP     {r3,r4}
  307.  
  308.                 POP     {r0-r7, pc}
  309.  
  310.  
  311.  
  312.  
  313.                 ENDP
  314.  
  315. ;******************************************************************************
  316. ; Writes the LS nybble to the LCD Keypad Shield.
  317. ;
  318. ; void WRITE_LS_NYBBLE(uint_32 value)
  319. ;
  320. ; r4 contains the value to write. It is assumed that the RS line has already
  321. ; been set to the proper value. Be sure to set E to HIGH, output the data, and
  322. ; set E to LOW to write the data to the LCD Keypad Shield.
  323. ;******************************************************************************
  324. WRITE_LS_NYBBLE PROC
  325.                 EXPORT  WRITE_LS_NYBBLE                 [WEAK]
  326.  
  327. ;  | LCD Hardware | Arduino Pin | LPC 4088 Port |
  328. ;  |:------------:|:-----------:|:-------------:|
  329. ;  |     D4       |     D4      |      P0.5     |
  330. ;  |     D5       |     D5      |      P5.0     |
  331. ;  |     D6       |     D6      |      P5.1     |
  332. ;  |     D7       |     D7      |      P0.4     |
  333.  
  334.  
  335.                 PUSH    {r0-r7, lr}
  336.  
  337.                 LDR     r9,=GPIO_BASE
  338.  
  339.                 MOV     r0, #2_110000
  340.                 MOV     r1, #2_11                      ;LSR each bit in the nybble to set the value in the pins D4-D7
  341.                                                      ;example: 1010 -> D4-D7
  342.                                                    ;r1 AND r1 - > 2_100000, 2_1, 2_10, 2_10000
  343.                 STR     r0, [r9, #CLR0]
  344.                 STR     r1, [r9, #CLR5]
  345.  
  346.                 PUSH    {r4}
  347.                 MOV     r4, #SET_HIGH
  348.                 BL      SET_E
  349.                 POP     {r4}
  350.  
  351.  
  352.                 MOV     r0, #0
  353.                 MOV     r1, #0
  354.  
  355.                 LSRS    r4, r4, #1
  356.                 ADDCS   r0, #2_100000
  357.  
  358.                 LSRS    r4, r4, #1
  359.                 ADDCS   r1, #2_1
  360.  
  361.                 LSRS    r4, r4, #1
  362.                 ADDCS   r1, #2_10
  363.  
  364.                 LSRS    r4, r4, #1
  365.                 ADDCS   r0, #2_10000
  366.  
  367.                 STR     r0, [r9, #SET0]
  368.                 STR     r1, [r9, #SET5]
  369.  
  370.                 PUSH    {r4}
  371.                 MOV     r4, #SET_LOW
  372.                 BL      SET_E
  373.                 POP     {r4}
  374.  
  375.                 POP     {r0-r7, pc}
  376.  
  377.                 ENDP
  378.  
  379. ;******************************************************************************
  380. ; Sets the RS data line to the value passed.
  381. ;
  382. ; void SET_RS(uint_32 status)
  383. ;
  384. ; r4 contains the value to set RS. RS is bit P5.3 which is already set to output.
  385. ;******************************************************************************
  386. SET_RS          PROC
  387.                 EXPORT  SET_RS                  [WEAK]
  388.  
  389.                 PUSH    {r0-r7, lr}
  390.                 LDR     r9,=GPIO_BASE
  391.                 LDR     r10,=2_1000
  392.                 CMP     r4, #0
  393.                 BEQ     set0R
  394.                 BNE     set1R
  395. set1R
  396.                 STR     r10, [r9, #SET5]
  397.                 POP     {r0-r7, pc}
  398. set0R
  399.                 STR     r10, [r9, #CLR5]
  400.                 POP     {r0-r7, pc}
  401.  
  402.  
  403.                 ENDP
  404.  
  405. ;******************************************************************************
  406. ; Sets the E data line to the value passed.
  407. ;
  408. ; void SET_E(uint_32 status)
  409. ;
  410. ; r4 contains the value to set E. E is bit P5.4 which is already set to output.
  411. ;******************************************************************************
  412. SET_E           PROC
  413.                 EXPORT  SET_E                   [WEAK]
  414.  
  415.                 PUSH    {r0-r7, lr}
  416.                 LDR     r9,=GPIO_BASE
  417.                 LDR     r10,=2_10000
  418.                 CMP     r4, #0
  419.                 BEQ     set0E
  420.                 BNE     set1E
  421. set1E
  422.                 STR     r10, [r9, #SET5]
  423.                 POP     {r0-r7, pc}
  424. set0E
  425.                 STR     r10, [r9, #CLR5]
  426.                 POP     {r0-r7, pc}
  427.  
  428.                 ENDP
  429.  
  430. ;******************************************************************************
  431. ; Turns on or off the LCD backlight. The parameter status is passed on the
  432. ; stack.
  433. ;
  434. ; void LCD_BACKLIGHT(int status)
  435. ;
  436. ; status - 1 turn on backlight, 0 - turn off backlight
  437. ;******************************************************************************
  438. LCD_BACKLIGHT   PROC
  439.  
  440.                 EXPORT  LCD_BACKLIGHT                   [WEAK]
  441.  
  442.                 PUSH    {r0-r7, lr}
  443.  
  444.                 LDR     r8, [sp, #0x24]
  445.                 LDR     r9,=GPIO_BASE
  446.  
  447.                 CMP     r8, #0
  448.                 LDR     r10,=2_1000000
  449.  
  450.                 BEQ     tOFF
  451.                 BNE     tON
  452. tON
  453.                 STR     r10, [r9, #SET0]
  454.                 POP     {r0-r7, pc}
  455. tOFF
  456.                 STR     r10, [r9, #CLR0]
  457.                 POP     {r0-r7, pc}
  458.  
  459.  
  460.                 ENDP
  461.  
  462.                 END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement