Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; code ex ample for lab 20
  2.  
  3. .nolist ;quartz assumption 4Mhz
  4.  
  5. .include "m128def.inc"
  6.  
  7. .list
  8.  
  9. .ESEG ; EEPROM memory segment
  10. .DSEG ; SRAM memory.segment
  11. .ORG 0x100; may be omitted this is default value
  12.  
  13. RAMTAB: .BYTE 100 ; Destination table (xlengthx bytes).
  14.  
  15. .CSEG ; CODE Program memory. Remember that it is "word" address space
  16.  
  17. .org 0x0000
  18.  
  19. jmp RESET ; Reset Handler
  20.  
  21.  
  22. RESET: ldi r16, high(RAMEND); Main program start
  23. out SPH,r16 ; Set stack pointer to top of RAM
  24. ldi r16, low(RAMEND)
  25. out SPL,r16
  26. cli ; Disable all interrupts
  27. ;
  28. ; place here code related to initialization of ports and interrupts
  29. ;; <instr> xxx
  30. .equ    KeyDDR  =       DDRA
  31. .equ    LEDDDR  =       DDRB
  32.  
  33. .equ    KeyPort =       PORTA
  34. .equ    LEDPort =       PORTB
  35.  
  36. .equ    KeyPin  =       PINA
  37. ;.equ    LEDPin  =       PINB
  38.  
  39. .def    licznik =       r16
  40. .def    licznik2=       r23
  41. .def    licznikm=       r24
  42. .def    ostan   =       r17
  43. .def    nstan   =       r18
  44. .def    wyjscie =       r19
  45. .def    tmp     =       r20
  46. .def    tmp2    =       r21
  47. .def    tmp3    =       r22
  48.  
  49. ldi     tmp, 0x00
  50. out     KeyDDR, tmp
  51. ldi     tmp, 0xFF
  52. out     LEDDDR, tmp
  53. out     KeyPort, tmp
  54.  
  55. ; End of port initialization
  56.  
  57. ;
  58. ; Main program code place here
  59.  
  60. sei ; Enable interrupts
  61. ldi     ostan, 0x00
  62. ldi     wyjscie, 0xFF
  63. out     LEDPort, wyjscie
  64. ldi     licznikm, 0xFF
  65. rjmp    main
  66.  
  67. Delay: ;opóźniacz
  68.     ldi     licznik, 0xFF
  69. delay_p:
  70.     dec     licznik
  71.     brne    delay_p
  72.     dec     tmp
  73.     ldi     licznik, 0xFF
  74.     brne    delay_p
  75.     ret
  76.  
  77. czysc_wyjscie:
  78.     ldi     wyjscie, 0xFF
  79.     mov     licznikm, wyjscie
  80.     rjmp powrot_wyjscie
  81.  
  82. main:
  83.     in      nstan, KeyPin ;zczytujemy stan
  84.     ldi     tmp, 0x0A
  85.     rcall   Delay   ; delay 2 ms
  86.     dec     licznikm ; decrementujemy licznik maski
  87.     breq    czysc_wyjscie
  88.     mov     tmp, nstan ; kopiujemy nstan do tmpa
  89.     sub     tmp, ostan; testujemy, czy sie czyms roznia
  90.     breq    main ; zmiany, pomijamy i rozpoczynamy przepisanie na wyjście
  91.     ldi     tmp, 0xA0 ; wychodzi przy tej wartosci mniej wiecej 30ms
  92.     rcall   Delay   ; delay 30 ms
  93. powrot_wyjscie:
  94.     mov     ostan, nstan ; kopiujemy nowy stan do ostatniego
  95.     mov     tmp, nstan ; kopiujemy nowy stan do tmp
  96.     and     tmp, wyjscie ; wykonujemy and, dzieki temu pominiemy te, ktore byly niedawno zmieniane
  97.     sub     tmp, wyjscie ; sprawdzamy czy są takie same
  98.     out     LEDPort, wyjscie ; zapisujemy na ledach [jeśli nie nastąpiło czyszczenie wyjscia to tylko na chwile]
  99.     breq    main ; są takie same, pomijamy
  100.     add     tmp, wyjscie ; przywracamy tmp
  101.     mov     wyjscie, tmp ; wrzucamy to na wyjście
  102.     ldi     licznikm, 0xFF ; resetujemy licznik
  103.     out     LEDPort, wyjscie ; zapisujemy na ledach
  104.     rjmp    main ; petla
  105. ; First load initial values of index registers
  106. ; Z, X, Y
  107. ;
  108. ;----------------------------------------------------------
  109. ;© 2009 Laboratorium SMiW Strona 34 ; Ending loop
  110. ;----------------------------------------------------------
  111. End:
  112. rjmp END
  113. ; place here test values
  114. ; Test with value 0x8000 also
  115. ;
  116. ROMTAB: .db 0x01, 0x00 , 0xffff
  117. .EXIT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement