Advertisement
Guest User

Untitled

a guest
Dec 7th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 11.64 KB | None | 0 0
  1. ;******************************************************************************
  2. ; CS 107: Computer Architecture and Organization
  3. ;
  4. ; Project: L03_LCD
  5. ; Filename: lcd.s
  6. ; Author: Jesus Zuniga
  7. ; Semester: Fall 2018
  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.                 ;Initialize IOCON
  70.                 LDR     r1,=0x4002C014
  71.                 STR     r0, [r1]
  72.  
  73.                 LDR     r1,=0x4002C280
  74.                 STR     r0, [r1]
  75.  
  76.                 LDR     r1,=0x4002C284
  77.                 STR     r0, [r1]
  78.  
  79.                 LDR     r1,=0x4002C010
  80.                 STR     r0, [r1]
  81.  
  82.                 LDR     r1,=0x4002C28C
  83.                 STR     r0, [r1]
  84.  
  85.                 LDR     r1,=0x4002C290
  86.                 STR     r0, [r1]
  87.  
  88.                 LDR     r1,=0x4002C018
  89.                 STR     r0, [r1]
  90.  
  91.                 LDR     r1,=0x4002C05C
  92.                 STR     r0, [r1]
  93.  
  94.                 ;Set Pin Direction
  95.                 LDR     r1,=GPIO_BASE
  96.                 STR     r0, [r1]
  97.  
  98.                 LDR     r0,=2_100000000000000001110000
  99.                 STR     r0, [r1, #0x00]
  100.  
  101.                 LDR     r0,=2_11011
  102.                 STR     r0, [r1, #0xA0]
  103.  
  104.                 BL      DELAY_1_MS          ;Wait 1 ms
  105.  
  106.                 PUSH    {r4}
  107.                 MOV     r4, #SET_LOW
  108.                 BL      SET_RS              ;Initialize RS
  109.                 POP     {r4}
  110.  
  111.                 PUSH    {r4}
  112.                 MOV     r4, #SET_LOW
  113.                 BL      SET_E               ;Initialize RS
  114.                 POP     {r4}
  115.                
  116.  
  117.                 PUSH    {r4}
  118.                 MOV     r4, #2_00010011                    ;Function set 8 bit
  119.                 BL      WRITE_COMMAND
  120.                 POP     {r4}
  121.                
  122.                 BL      DELAY_2_MS
  123.                 BL      DELAY_2_MS                         ;Wait 6 ms
  124.                 BL      DELAY_2_MS
  125.  
  126.                 PUSH    {r4}
  127.                 MOV     r4, #2_00010011                    ;Function set 8 bit
  128.                 BL      WRITE_COMMAND
  129.                 POP     {r4}
  130.  
  131.                 BL      DELAY_1_MS                         ;Wait 1 ms
  132.  
  133.                 PUSH    {r4}
  134.                 MOV     r4, #2_00000010                    ;Function 4 bit
  135.                 BL      WRITE_COMMAND
  136.                 POP     {r4}
  137.  
  138.                 BL      DELAY_2_MS                         ;Wait 2 ms
  139.  
  140.                 PUSH    {r4}
  141.                 MOV     r4, #2_00101000                     ;Display 2 lines, font size
  142.                 BL      WRITE_COMMAND
  143.                 POP     {r4}
  144.  
  145.                 BL      DELAY_2_MS                         ;Wait 2 ms
  146.  
  147.                 PUSH    {r4}
  148.                 MOV     r4, #2_00001000                     ;Display Off
  149.                 BL      WRITE_COMMAND
  150.                 POP     {r4}
  151.  
  152.                 BL      DELAY_2_MS                         ;Wait 2 ms
  153.  
  154.                 PUSH    {r4}
  155.                 MOV     r4, #2_00000001                     ;Clear Display
  156.                 BL      WRITE_COMMAND
  157.                 POP     {r4}
  158.  
  159.                 BL      DELAY_2_MS                          ;Wait 2 ms
  160.  
  161.                 PUSH    {r4}
  162.                 MOV     r4, #2_00000110                     ;Display increments no write, not shifted
  163.                 BL      WRITE_COMMAND
  164.                 POP     {r4}
  165.  
  166.                 BL      DELAY_2_MS
  167.  
  168.                 PUSH    {r4}
  169.                 MOV     r4, #2_00001111                     ;Display ON, set cursor ON, set cursor to blink
  170.                 BL      WRITE_COMMAND
  171.                 POP     {r4}
  172.  
  173.                 BL      DELAY_2_MS                          ;Wait 2ms
  174.  
  175.                 POP     {r0-r7, pc}
  176.                 ; Your code goes here.
  177.  
  178.                 ENDP
  179.  
  180.  
  181. ;******************************************************************************
  182. ; Writes a string to the first or second line of the LCD Keypad Shield.
  183. ;
  184. ; void WRITE_CSTRING(uchar_32 line, char *string)
  185. ;
  186. ; r4 contains which line with 0 being the top line and 1 the bottom. r5
  187. ; contains the address of the first character to be output. When writing a
  188. ; character be sure to wait 2 ms between characters.
  189. ;******************************************************************************
  190. WRITE_CSTRING   PROC
  191.                 EXPORT  WRITE_CSTRING                   [WEAK]
  192.  
  193.                 PUSH    {r0-r7, lr}
  194.                
  195.                 ;Determine address for line in DDRAM
  196.                 MOV     r3, #2_10000000
  197.                 CMP     r4, #0
  198.                 ADDNE   r3, #2_1000000
  199.                
  200.                 PUSH    {r3,r4}
  201.                 MOV     r4, r3
  202.                 BL      WRITE_COMMAND
  203.                 POP     {r3,r4}
  204.                
  205.                 ;Write Characters
  206.                 MOV     r1, #0
  207. Loopie         
  208.                 ;Loop that writes characters
  209.                 ;By taking each byte at a time
  210.                 BL      DELAY_2_MS
  211.                
  212.                 LDRB    r0, [r5, r1]
  213.                
  214.                 CMP     r0, #0
  215.                 BEQ     OUTTIE
  216.                 PUSH    {r0, r1, r4}
  217.                 MOV     r4, r0
  218.                 BL      WRITE_DATA
  219.                 POP     {r0, r1, r4}
  220.                
  221.                 ADD     r1, #1
  222.                 B       Loopie
  223.                
  224. OUTTIE
  225.  
  226.                 POP     {r0-r7, pc}
  227.  
  228.                 ENDP
  229.  
  230.  
  231. ;******************************************************************************
  232. ; Writes a command byte to the LCD Keypad Shield
  233. ;
  234. ; void WRITE_COMMAND(uint_32 value)
  235. ;
  236. ; r4 contains the value to write. This routine simply sets the RS signal and
  237. ; calls WRITE_BYTE.
  238. ;******************************************************************************
  239. WRITE_COMMAND   PROC
  240.                 EXPORT  WRITE_COMMAND                   [WEAK]
  241.  
  242.                 PUSH    {r0-r7, lr}
  243.                
  244.                 ;Set RS to low when writing commands
  245.                 PUSH    {r4}
  246.                 MOV     r4, #SET_LOW
  247.                 BL      SET_RS
  248.                 POP     {r4}
  249.                
  250.                 ;Write the command byte
  251.                 BL      WRITE_BYTE
  252.  
  253.                 POP     {r0-r7, pc}
  254.  
  255.                 ENDP
  256.  
  257. ;******************************************************************************
  258. ; Writes a data byte to the LCD Keypad Shield
  259. ;
  260. ; void WRITE_COMMAND(uint_32 value)
  261. ;
  262. ; r4 contains the value to write. This routine simply sets the RS signal and
  263. ; calls WRITE_BYTE.
  264. ;******************************************************************************
  265. WRITE_DATA      PROC
  266.  
  267.                 EXPORT  WRITE_DATA                  [WEAK]
  268.  
  269.                 PUSH    {r0-r7, lr}
  270.                
  271.                 ;Set RS to high when writing commands
  272.                 PUSH    {r4}
  273.                 MOV   r4, #SET_HIGH
  274.                 BL      SET_RS
  275.                 POP   {r4}
  276.                 ;Write byte
  277.                 PUSH    {r4}
  278.                 BL      WRITE_BYTE
  279.                 POP   {r4}
  280.  
  281.                 POP     {r0-r7, pc}
  282.  
  283.                 ENDP
  284.  
  285. ;******************************************************************************
  286. ; Writes a byte to the LCD Keypad Shield
  287. ;
  288. ; void WRITE_BYTE(uint_32 value)
  289. ;
  290. ; r4 contains the value to write. We should set the RS signal before calling
  291. ; this routine. Setting RS to LOW gives us a command and setting RS to HIGH
  292. ; gives us a data command. Since our LCD Keypad Shield is using a 4-bit
  293. ; interface we need to send out the MS nybble first followed by the LS nybble.
  294. ;******************************************************************************
  295. WRITE_BYTE      PROC
  296.  
  297.                 EXPORT  WRITE_BYTE                  [WEAK]
  298.  
  299.                 PUSH    {r0-r7, lr}
  300.                
  301.                 ;Splits the byte into two nybbles and
  302.                 ;Passes them sepparately to WRITE_LS_NYBBLE
  303.                 MOV     r3, r4
  304.                 LSR     r4, r3, #4
  305.  
  306.                 PUSH    {r3,r4}
  307.                 BL      WRITE_LS_NYBBLE
  308.                 POP     {r3,r4}
  309.  
  310.                 MOV     r4, r3
  311.  
  312.                 PUSH    {r3,r4}
  313.                 BL      WRITE_LS_NYBBLE
  314.                 POP     {r3,r4}
  315.  
  316.                 POP     {r0-r7, pc}
  317.  
  318.  
  319.  
  320.  
  321.                 ENDP
  322.  
  323. ;******************************************************************************
  324. ; Writes the LS nybble to the LCD Keypad Shield.
  325. ;
  326. ; void WRITE_LS_NYBBLE(uint_32 value)
  327. ;
  328. ; r4 contains the value to write. It is assumed that the RS line has already
  329. ; been set to the proper value. Be sure to set E to HIGH, output the data, and
  330. ; set E to LOW to write the data to the LCD Keypad Shield.
  331. ;******************************************************************************
  332. WRITE_LS_NYBBLE PROC
  333.                 EXPORT  WRITE_LS_NYBBLE                 [WEAK]
  334.  
  335. ;  | LCD Hardware | Arduino Pin | LPC 4088 Port |
  336. ;  |:------------:|:-----------:|:-------------:|
  337. ;  |     D4       |     D4      |      P0.5     |
  338. ;  |     D5       |     D5      |      P5.0     |
  339. ;  |     D6       |     D6      |      P5.1     |
  340. ;  |     D7       |     D7      |      P0.4     |
  341.  
  342.  
  343.                 PUSH    {r0-r7, lr}
  344.  
  345.                 LDR     r9,=GPIO_BASE
  346.  
  347.                 MOV     r0, #2_110000
  348.                 MOV     r1, #2_11                       ;LSR each bit in the nybble to set the value in the pins D4-D7
  349.                                                         ;example: 1010 -> D4-D7
  350.                                                         ;r1 AND r1 - > 2_100000, 2_1, 2_10, 2_10000
  351.                
  352.                 ;Clear the pins before writing to them         
  353.                 STR     r0, [r9, #CLR0]
  354.                 STR     r1, [r9, #CLR5]
  355.                
  356.                 ;Set E to HIGH since data will be written
  357.                 PUSH    {r4}
  358.                 MOV     r4, #SET_HIGH
  359.                 BL      SET_E
  360.                 POP     {r4}
  361.  
  362.  
  363.                 MOV     r0, #0
  364.                 MOV     r1, #0
  365.                
  366.                 ;Set r0 and r1 deppending on the carry flag
  367.                 ;Each time the register is shifted
  368.                 LSRS    r4, r4, #1
  369.                 ADDCS   r0, #2_100000
  370.  
  371.                 LSRS    r4, r4, #1
  372.                 ADDCS   r1, #2_1
  373.  
  374.                 LSRS    r4, r4, #1
  375.                 ADDCS   r1, #2_10
  376.  
  377.                 LSRS    r4, r4, #1
  378.                 ADDCS   r0, #2_10000
  379.                
  380.                 ;Set corresponding bits
  381.                 STR     r0, [r9, #SET0]
  382.                 STR     r1, [r9, #SET5]
  383.                
  384.                 ;Set E to LOW since data has been output
  385.                 PUSH    {r4}
  386.                 MOV     r4, #SET_LOW
  387.                 BL      SET_E
  388.                 POP     {r4}
  389.  
  390.                 POP     {r0-r7, pc}
  391.  
  392.                 ENDP
  393.  
  394. ;******************************************************************************
  395. ; Sets the RS data line to the value passed.
  396. ;
  397. ; void SET_RS(uint_32 status)
  398. ;
  399. ; r4 contains the value to set RS. RS is bit P5.3 which is already set to output.
  400. ;******************************************************************************
  401. SET_RS          PROC
  402.                 EXPORT  SET_RS                  [WEAK]
  403.                
  404.                 PUSH    {r0-r7, lr}
  405.                
  406.                
  407.                 ;Simple loop that sets or clears RS pin
  408.                 ;Depending on the value of R4
  409.                 ;r4 = 0 -> RS : LOW , r4 = 1 -> RS : HIGH
  410.                
  411.                
  412.                 LDR     r9,=GPIO_BASE
  413.                 LDR     r10,=2_1000
  414.                 CMP     r4, #0
  415.                 BEQ     set0R
  416.                 BNE     set1R
  417. set1R
  418.                 STR     r10, [r9, #SET5]
  419.                 POP     {r0-r7, pc}
  420. set0R
  421.                 STR     r10, [r9, #CLR5]
  422.                 POP     {r0-r7, pc}
  423.  
  424.  
  425.                 ENDP
  426.  
  427. ;******************************************************************************
  428. ; Sets the E data line to the value passed.
  429. ;
  430. ; void SET_E(uint_32 status)
  431. ;
  432. ; r4 contains the value to set E. E is bit P5.4 which is already set to output.
  433. ;******************************************************************************
  434. SET_E           PROC
  435.                 EXPORT  SET_E                   [WEAK]
  436.  
  437.                 PUSH    {r0-r7, lr}
  438.                
  439.                
  440.                
  441.                 ;Simple loop that sets or clears E pin
  442.                 ;Depending on the value of R4
  443.                 ;r4 = 0 -> E : LOW  , r4 = 1 -> E : HIGH
  444.                 LDR     r9,=GPIO_BASE
  445.                 LDR     r10,=2_10000
  446.                 CMP     r4, #0
  447.                 BEQ     set0E
  448.                 BNE     set1E
  449. set1E
  450.                 STR     r10, [r9, #SET5]
  451.                 POP     {r0-r7, pc}
  452. set0E
  453.                 STR     r10, [r9, #CLR5]
  454.                 POP     {r0-r7, pc}
  455.  
  456.                 ENDP
  457.  
  458. ;******************************************************************************
  459. ; Turns on or off the LCD backlight. The parameter status is passed on the
  460. ; stack.
  461. ;
  462. ; void LCD_BACKLIGHT(int status)
  463. ;
  464. ; status - 1 turn on backlight, 0 - turn off backlight
  465. ;******************************************************************************
  466. LCD_BACKLIGHT   PROC
  467.  
  468.                 EXPORT  LCD_BACKLIGHT                   [WEAK]
  469.  
  470.                 PUSH    {r0-r7, lr}
  471.                
  472.                 ;Get the value into r8 from the stack
  473.                 LDR     r8, [sp, #0x24]
  474.                 LDR     r9,=GPIO_BASE
  475.                
  476.                 ;Check r8 and branch accordingly
  477.                 CMP     r8, #0
  478.                 LDR     r10,=2_1000000
  479.                
  480.                 BEQ     tOFF
  481.                 BNE     tON
  482. tON
  483.                 STR     r10, [r9, #SET0]
  484.                 POP     {r0-r7, pc}
  485. tOFF
  486.                 STR     r10, [r9, #CLR0]
  487.                 POP     {r0-r7, pc}
  488.  
  489.  
  490.                 ENDP
  491.  
  492.                 END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement