Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; code ex ample for lab 20
- .nolist ;quartz assumption 4Mhz
- .include "m128def.inc"
- .list
- .ESEG ; EEPROM memory segment
- .DSEG ; SRAM memory.segment
- .ORG 0x100; may be omitted this is default value
- RAMTAB: .BYTE 100 ; Destination table (xlengthx bytes).
- .CSEG ; CODE Program memory. Remember that it is "word" address space
- .org 0x0000
- jmp RESET ; Reset Handler
- RESET: ldi r16, high(RAMEND); Main program start
- out SPH,r16 ; Set stack pointer to top of RAM
- ldi r16, low(RAMEND)
- out SPL,r16
- cli ; Disable all interrupts
- ;
- ; place here code related to initialization of ports and interrupts
- ;; <instr> xxx
- .equ KeyDDR = DDRA
- .equ LEDDDR = DDRB
- .equ KeyPort = PORTA
- .equ LEDPort = PORTB
- .equ KeyPin = PINA
- ;.equ LEDPin = PINB
- .def licznik = r16
- .def licznik2= r23
- .def licznikm= r24
- .def ostan = r17
- .def nstan = r18
- .def wyjscie = r19
- .def tmp = r20
- .def tmp2 = r21
- .def tmp3 = r22
- ldi tmp, 0x00
- out KeyDDR, tmp
- ldi tmp, 0xFF
- out LEDDDR, tmp
- out KeyPort, tmp
- ; End of port initialization
- ;
- ; Main program code place here
- sei ; Enable interrupts
- ldi ostan, 0x00
- ldi wyjscie, 0xFF
- out LEDPort, wyjscie
- ldi licznikm, 0xFF
- rjmp main
- Delay: ;opóźniacz
- ldi licznik, 0xFF
- delay_p:
- dec licznik
- brne delay_p
- dec tmp
- ldi licznik, 0xFF
- brne delay_p
- ret
- czysc_wyjscie:
- ldi wyjscie, 0xFF
- mov licznikm, wyjscie
- rjmp powrot_wyjscie
- main:
- in nstan, KeyPin ;zczytujemy stan
- ldi tmp, 0x0A
- rcall Delay ; delay 2 ms
- dec licznikm ; decrementujemy licznik maski
- breq czysc_wyjscie
- mov tmp, nstan ; kopiujemy nstan do tmpa
- sub tmp, ostan; testujemy, czy sie czyms roznia
- breq main ; zmiany, pomijamy i rozpoczynamy przepisanie na wyjście
- ldi tmp, 0xA0 ; wychodzi przy tej wartosci mniej wiecej 30ms
- rcall Delay ; delay 30 ms
- powrot_wyjscie:
- mov ostan, nstan ; kopiujemy nowy stan do ostatniego
- mov tmp, nstan ; kopiujemy nowy stan do tmp
- and tmp, wyjscie ; wykonujemy and, dzieki temu pominiemy te, ktore byly niedawno zmieniane
- sub tmp, wyjscie ; sprawdzamy czy są takie same
- out LEDPort, wyjscie ; zapisujemy na ledach [jeśli nie nastąpiło czyszczenie wyjscia to tylko na chwile]
- breq main ; są takie same, pomijamy
- add tmp, wyjscie ; przywracamy tmp
- mov wyjscie, tmp ; wrzucamy to na wyjście
- ldi licznikm, 0xFF ; resetujemy licznik
- out LEDPort, wyjscie ; zapisujemy na ledach
- rjmp main ; petla
- ; First load initial values of index registers
- ; Z, X, Y
- ;
- ;----------------------------------------------------------
- ;© 2009 Laboratorium SMiW Strona 34 ; Ending loop
- ;----------------------------------------------------------
- End:
- rjmp END
- ; place here test values
- ; Test with value 0x8000 also
- ;
- ROMTAB: .db 0x01, 0x00 , 0xffff
- .EXIT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement