Advertisement
Guest User

tgi lol

a guest
Jun 18th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. ;
  2. ; zahlenschloss.asm
  3. ;
  4. ; Created: 15/06/2019 14:18:32
  5. ; Author : winshit
  6. ;
  7.  
  8. ; naming definitions
  9. .def Temp = R23
  10. .def Temp2 = R24
  11. .def Digit = R16
  12. .def Fail = R17
  13. .def ButtonStates = R18
  14. .def digit1 = R19
  15. .def digit2 = R20
  16. .def digit3 = R21
  17. .def digit4 = R22
  18.  
  19.  
  20. ; input and output pins
  21. ldi Temp, 0b00111111
  22. out DDRB, Temp
  23.  
  24. ldi Temp, 0b00001111
  25. out DDRD, Temp
  26.  
  27. clr Temp
  28. out DDRA, Temp
  29.  
  30.  
  31. ; init vars
  32. ldi digit1, 0b00000000
  33. ldi digit2, 0b00001000
  34. ldi digit3, 0b00000001
  35. ldi digit4, 0b00000101
  36.  
  37. ; init stackpointer
  38. ldi Temp, high(RAMEND)
  39. out SPH, Temp
  40. ldi Temp, low(RAMEND)
  41. out SPL, Temp
  42.  
  43.  
  44. ; endless loop
  45. MAIN: ldi Fail, 0b00000000
  46.  
  47. ; set light, read digit #1
  48. ldi Temp, 0b00000001
  49. out PORTB, Temp
  50. call POLL_BUTTONS
  51. cpse digit, digit1
  52. call INC_FAIL
  53.  
  54. ; set light, read digit #2
  55. ldi Temp, 0b00000011
  56. out PORTB, Temp
  57. call POLL_BUTTONS
  58. cpse digit, digit2
  59. call INC_FAIL
  60.  
  61. ; set light, read digit #3
  62. ldi Temp, 0b00000111
  63. out PORTB, Temp
  64. call POLL_BUTTONS
  65. cpse digit, digit3
  66. call INC_FAIL
  67.  
  68. ; set light, read digit #4
  69. ldi Temp, 0b00001111
  70. out PORTB, Temp
  71. call POLL_BUTTONS
  72. cpse digit, digit4
  73. call INC_FAIL
  74.  
  75. clr Temp
  76. cpse Fail, Temp
  77. call SUCCESS_WAIT
  78.  
  79. rjmp MAIN
  80.  
  81. INC_FAIL:
  82. inc Fail
  83.  
  84. POLL_BUTTONS:
  85. ; check if increment was pressed
  86. in Temp, PINA
  87. ldi Temp2, 0b10000000
  88. and Temp, Temp
  89.  
  90. ldi Temp2, 1
  91. cpse Temp, Temp2
  92. call HANDLE_ITS_ZERO
  93.  
  94. mov ButtonStates, Temp
  95.  
  96.  
  97. HANDLE_ITS_ZERO:
  98. ; compare with previous button state
  99. ldi Temp2, 0
  100. cpse ButtonStates, Temp2
  101. inc digit
  102.  
  103. SUCCESS_WAIT:
  104. ldi Temp, 0b00010000
  105. out PORTB, Temp
  106.  
  107.  
  108. LED_ERROR:
  109. ldi Temp, 0b00100000
  110. out PORTB, Temp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement