Guest User

Untitled

a guest
Apr 16th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; code ex ample for lab 20
  2. .nolist ;quartz assumption 4Mhz
  3. .include "m128def.inc"
  4. .list
  5. .ESEG ; EEPROM memory segment
  6.  
  7. .DSEG ; SRAM memory.segment
  8.  
  9. .ORG 0x100; may be omitted this is default value
  10.  
  11. .CSEG ; CODE Program memory. Remember that it is "word" address space
  12. .org 0x0000
  13.  
  14. RESET:
  15.     ldi r16, high(RAMEND); Main program start
  16.     out SPH,r16 ; Set stack pointer to top of RAM
  17.     ldi r16, low(RAMEND)
  18.     out SPL,r16
  19.     cli ; Disable all interrupts
  20. ;
  21.  
  22. ; place here code related to initialization of ports and interrupts
  23. ;; <instr> xxx ; End of port initialization
  24.  
  25.     ldi r16,0x00
  26.     out PORTC,r16 ; PORTC - wejscie
  27.     ldi r16,0xFF ;
  28.     out PORTC,r16 ; PORTC - wejscia PULL-UP
  29.     ldi r16,0xFF ;
  30.     out PORTB,r16 ; PORTB - jako wyjscie
  31.     out DDRB,r16 ; PORTB - wyjscie w stanie wysokim
  32.  
  33.     ;sei ; Enable interrupts
  34. ;
  35. ; Main program code place here
  36.  
  37.     ldi zh, high(tab_ROM<<1)
  38.     ldi zl, low(tab_ROM<<1)
  39.  
  40. Main_2:
  41.     ; sprawdzanie przycisku
  42.     in r16, PINC ; pobierz wartosc
  43.     cpi r16, 0xFF ; porownaj z 1
  44.     brsh Main_2 ; brak przycisku
  45.  
  46. Main_1:
  47.     movw r18:r19, z ; zapisz z 
  48.  
  49.     ;test for bacaface
  50.     lpm r16, z+
  51.     cpi r16, 0xba ;test na BA
  52.     brne Main_12 ;nie ma BA
  53.    
  54.     lpm r16, z+
  55.     cpi r16, 0xca ;test na CA
  56.     brne Main_12 ;nie ma CA
  57.  
  58.     lpm r16, z+
  59.     cpi r16, 0xfa ;test na FA
  60.     brne Main_12 ;nie ma FA
  61.  
  62.     lpm r16, z
  63.     cpi r16, 0xce ;test na CE
  64.     breq End ;jest CE
  65.  
  66. Main_12:
  67.     movw z, r18:r19 ; wczytaj z
  68.  
  69.     lpm r0, z+
  70.     com r0 ; negacja
  71.     out PORTB, r0 ; wyswietl wartosc
  72.  
  73. rjmp Main_1
  74.  
  75. ;jmp End ; koniec petli
  76.  
  77. ; First load initial values of index registers
  78. ; Z, X, Y
  79. ;
  80. ;----------------------------------------------------------
  81. ; Ending loop
  82. ;----------------------------------------------------------
  83. End:
  84. rjmp End
  85. ; place here test values
  86. ; Test with value 0x8000 also ;
  87. tab_ROM: .db 0xba, 0xca, 0xfa, 0xce
  88. .EXIT
  89. ;b.!face
Add Comment
Please, Sign In to add comment