Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. ;-------------------------------------------------------------------
  2. ; Created by: Oslejsek Stepan A3
  3. ; Uloha 9 - dynamicky displej
  4. ; s casovacem
  5. ; Date: 11.1.2019
  6. ;-------------------------------------------------------------------
  7. .NOLIST
  8. .INCLUDE "m128def.inc"
  9. .LIST
  10. .CSEG
  11.  
  12. .DEF tcycles = R16
  13. .DEF parameter = R17
  14. .DEF null = R18
  15. .DEF two = R19
  16. .DEF position = R22
  17. .DEF number = R23
  18. .DEF value = R24
  19. .DEF pcycles = R25
  20.  
  21. .MACRO Timer ;timer macro
  22. LDI tcycles,@0
  23. LDI parameter,@1
  24. OUT TCCR2,parameter
  25. LDI parameter,@2
  26. OUT OCR2,parameter
  27. LDI two,2
  28. @3:
  29. IN null,TIFR
  30. CALL TIMER1ms ;calling timer for 1ms
  31. CP null,two
  32. BRNE @3
  33. OUT TIFR,two
  34. DEC tcycles
  35. BRNE @3
  36. RET
  37. .ENDMACRO
  38.  
  39. .MACRO Program ;program macro
  40. Init1: ;first init
  41. CALL SETTINGS1
  42. LD pcycles,Y
  43. LDI position,0
  44. LDI number,8
  45. Fill: ;filling register X with values from table CODE
  46. LPM value,Z+
  47. ST X+,value
  48. DEC pcycles
  49. BRNE Fill
  50. Init2: ;second init
  51. CALL SETTINGS1
  52. LD pcycles,Y+ ;here is post increment, because I don't need to increment pcycles
  53. Lightup: ;light up segments on display
  54. LD value,X+ ;load value from X, post increment
  55. OUT PORTB,value ;send value to portb
  56. OUT PORTD,position ;send position to portd
  57. INC position ;increment position
  58. CALL @0 ;call timer 200/500 ms
  59. DEC pcycles ;repeat
  60. BRNE Lightup
  61. LD pcycles,Y
  62. CALL SETTINGS1
  63. DEC number
  64. BRNE Fill
  65. OUT PORTB,null ;turn off display
  66. .ENDMACRO
  67.  
  68. LDI R20,low(RAMEND) ;init
  69. OUT SPL,R20
  70. LDI R20,high(RAMEND)
  71. OUT SPH,R20
  72. LDI R20,0xFF
  73. OUT DDRB,R20
  74. OUT DDRD,R20
  75. RJMP Main
  76. Main: ;whole program
  77. CALL SETTINGS2
  78. LDI pcycles,8
  79. Main1:
  80. LPM two,Z+
  81. ST Y+,two
  82. DEC pcycles
  83. BRNE Main1
  84. Program TIMER200
  85. CALL SETTINGS2
  86. Program TIMER500
  87. RJMP Main
  88.  
  89. SETTINGS1: ;set address for register X + code
  90. LDI XL,0x20
  91. LDI XH,0x01
  92. LDI ZL,low(CODE*2)
  93. LDI ZH,high(CODE*2)
  94. RET
  95. SETTINGS2: ;set address for register Y + cycles
  96. LDI YL,0x00
  97. LDI YH,0x01
  98. LDI ZL,low(CYCLES*2)
  99. LDI ZH,high(CYCLES*2)
  100. RET
  101.  
  102. TIMER200: ;timer for "200ms"
  103. Timer 50,0b00001110,188,TIMER200
  104. RET
  105.  
  106. TIMER500: ;timer for "500ms"
  107. Timer 100,0b00001110,250,TIMER500
  108. RET
  109.  
  110. TIMER1ms: ;timer 1ms for dynamic display
  111. LDI R20, 21
  112. LDI R21, 199
  113. L1:
  114. DEC R21
  115. BRNE L1
  116. DEC R20
  117. BRNE L1
  118. RET
  119.  
  120. CYCLES: ;numbers of cycles
  121. .DB 1,2,3,4
  122. .DB 5,6,7,8
  123. CODE: ;codes for display
  124. .DB 0b11010111,0b11010111
  125. .DB 0b11010111,0b11010111
  126. .DB 0b11010111,0b11010111
  127. .DB 0b11010111,0b11010111
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement