Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. ; 1DT301
  2. ; Lab 5, Initialize display JHD202A.
  3. ;
  4. ; Date: 2017-10-11
  5. ; Author, Christian Fagerholm, Amelie Löwe
  6.  
  7. ; Modified: prints a Characters inputed from the keyboard to the display
  8. ;
  9. ; Function
  10. ; --------
  11. ; Initialize display JHD202 connected to PORTE
  12. ;
  13. ; (run @ 1.8432 MHz clk frequency)
  14. ;
  15.  
  16. .include "m2560def.inc"
  17. .def Temp = r16
  18. .def Data = r17
  19. .def RS = r18
  20. .def char = r20
  21. .equ ubbrval = 12
  22.  
  23. .equ BITMODE4 = 0b00000010 ; 4-bit operation
  24. .equ CLEAR = 0b00000001 ; Clear display
  25. .equ DISPCTRL = 0b00001111 ; Display on, cursor on, blink on.
  26.  
  27. .cseg
  28. .org 0x0000 ; Reset vector
  29. jmp reset
  30.  
  31. .org URXC1addr
  32. rjmp loop1
  33.  
  34. .org 0x0072
  35.  
  36. reset:
  37. ldi Temp, 0b0000_0001
  38. sts EICRA, Temp
  39. ldi Temp, 0b0000_0001
  40. out EIMSK, Temp
  41.  
  42. ldi Temp, HIGH(RAMEND) ; Temp = high byte of ramend address
  43. out SPH, Temp ; sph = Temp
  44. ldi Temp, LOW(RAMEND) ; Temp = low byte of ramend address
  45. out SPL, Temp ; spl = Temp
  46.  
  47. ser Temp ; r16 = 0b11111111
  48. out DDRE, Temp ; port E = outputs ( Display JHD202A)
  49. clr Temp ; r16 = 0
  50. out PORTE, Temp
  51.  
  52. ldi Temp, ubbrval ; store prescaler value
  53. sts UBRR1L, temp
  54.  
  55. ldi Temp, 0b10011000
  56. sts UCSR1B, temp ; setting TX and RX flags enabled and allowing interrupts
  57.  
  58.  
  59. ldi Temp, 0x00
  60. out DDRD, Temp
  61. sei
  62.  
  63.  
  64. ; **
  65. ; ** init_display
  66. ; **
  67. init_disp:
  68. rcall power_up_wait ; wait for display to power up
  69.  
  70. ldi Data, BITMODE4 ; 4-bit operation
  71. rcall write_nibble ; (in 8-bit mode)
  72. rcall short_wait ; wait min. 39 us
  73. ldi Data, DISPCTRL ; disp. on, blink on, curs. On
  74. rcall write_cmd ; send command
  75. rcall short_wait ; wait min. 39 us
  76.  
  77.  
  78. loop: nop
  79. rjmp loop ; loop forever
  80.  
  81.  
  82. clr_disp:
  83. ldi Data, CLEAR ; clr display
  84. rcall write_cmd ; send command
  85. rcall long_wait ; wait min. 1.53 ms
  86. ret
  87.  
  88. ; **
  89. ; ** write char/command
  90. ; **
  91.  
  92. write_char:
  93. ldi RS, 0b00100000 ; RS = high
  94. rjmp write
  95. write_cmd:
  96. clr RS ; RS = low
  97. write:
  98. mov Temp, Data ; copy Data
  99. andi Data, 0b11110000 ; mask out high nibble
  100. swap Data ; swap nibbles
  101. or Data, RS ; add register select
  102. rcall write_nibble ; send high nibble
  103. mov Data, Temp ; restore Data
  104. andi Data, 0b00001111 ; mask out low nibble
  105. or Data, RS ; add register select
  106.  
  107. write_nibble:
  108. rcall switch_output ; Modify for display JHD202A, port E
  109. nop ; wait 542nS
  110. sbi PORTE, 5 ; enable high, JHD202A
  111. nop
  112. nop ; wait 542nS
  113. cbi PORTE, 5 ; enable low, JHD202A
  114. nop
  115. nop ; wait 542nS
  116. ret
  117.  
  118. ; **
  119. ; ** busy_wait loop
  120. ; **
  121. short_wait:
  122. clr zh ; approx 50 us
  123. ldi zl, 30
  124. rjmp wait_loop
  125. long_wait:
  126. ldi zh, HIGH(1000) ; approx 2 ms
  127. ldi zl, LOW(1000)
  128. rjmp wait_loop
  129. dbnc_wait:
  130. ldi zh, HIGH(4600) ; approx 10 ms
  131. ldi zl, LOW(4600)
  132. rjmp wait_loop
  133. power_up_wait:
  134. ldi zh, HIGH(9000) ; approx 20 ms
  135. ldi zl, LOW(9000)
  136.  
  137. wait_loop:
  138. sbiw z, 1 ; 2 cycles
  139. brne wait_loop ; 2 cycles
  140. ret
  141.  
  142. ; **
  143. ; ** modify output signal to fit LCD JHD202A, connected to port E
  144. ; **
  145.  
  146. switch_output:
  147. push Temp
  148. clr Temp
  149. sbrc Data, 0 ; D4 = 1?
  150. ori Temp, 0b00000100 ; Set pin 2
  151. sbrc Data, 1 ; D5 = 1?
  152. ori Temp, 0b00001000 ; Set pin 3
  153. sbrc Data, 2 ; D6 = 1?
  154. ori Temp, 0b00000001 ; Set pin 0
  155. sbrc Data, 3 ; D7 = 1?
  156. ori Temp, 0b00000010 ; Set pin 1
  157. sbrc Data, 4 ; E = 1?
  158. ori Temp, 0b00100000 ; Set pin 5
  159. sbrc Data, 5 ; RS = 1?
  160. ori Temp, 0b10000000 ; Set pin 7 (wrong in previous version)
  161. out porte, Temp
  162. pop Temp
  163. ret
  164.  
  165.  
  166.  
  167. loop1:
  168. lds temp, UCSR1A ; read input
  169. lds char, UDR1 ;Read character in UDR
  170.  
  171. putChar:
  172. lds Temp, UCSR1A
  173. sts UDR1, char ;write character to UDR
  174.  
  175. output:
  176. clr Data
  177. mov Data, char
  178. rcall write_char
  179.  
  180. reti
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement