Advertisement
Guest User

Untitled

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