Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;
- ; zahlenschloss.asm
- ;
- ; Created: 15/06/2019 14:18:32
- ; Author : winshit
- ;
- ; naming definitions
- .def Temp = R23
- .def Temp2 = R24
- .def Digit = R16
- .def Fail = R17
- .def ButtonStates = R18
- .def digit1 = R19
- .def digit2 = R20
- .def digit3 = R21
- .def digit4 = R22
- ; input and output pins
- ldi Temp, 0b00111111
- out DDRB, Temp
- ldi Temp, 0b00001111
- out DDRD, Temp
- clr Temp
- out DDRA, Temp
- ; init vars
- ldi digit1, 0b00000000
- ldi digit2, 0b00001000
- ldi digit3, 0b00000001
- ldi digit4, 0b00000101
- ; init stackpointer
- ldi Temp, high(RAMEND)
- out SPH, Temp
- ldi Temp, low(RAMEND)
- out SPL, Temp
- ; endless loop
- MAIN: ldi Fail, 0b00000000
- ; set light, read digit #1
- ldi Temp, 0b00000001
- out PORTB, Temp
- call POLL_BUTTONS
- cpse digit, digit1
- call INC_FAIL
- ; set light, read digit #2
- ldi Temp, 0b00000011
- out PORTB, Temp
- call POLL_BUTTONS
- cpse digit, digit2
- call INC_FAIL
- ; set light, read digit #3
- ldi Temp, 0b00000111
- out PORTB, Temp
- call POLL_BUTTONS
- cpse digit, digit3
- call INC_FAIL
- ; set light, read digit #4
- ldi Temp, 0b00001111
- out PORTB, Temp
- call POLL_BUTTONS
- cpse digit, digit4
- call INC_FAIL
- clr Temp
- cpse Fail, Temp
- call SUCCESS_WAIT
- rjmp MAIN
- INC_FAIL:
- inc Fail
- POLL_BUTTONS:
- ; check if increment was pressed
- in Temp, PINA
- ldi Temp2, 0b10000000
- and Temp, Temp
- ldi Temp2, 1
- cpse Temp, Temp2
- call HANDLE_ITS_ZERO
- mov ButtonStates, Temp
- HANDLE_ITS_ZERO:
- ; compare with previous button state
- ldi Temp2, 0
- cpse ButtonStates, Temp2
- inc digit
- SUCCESS_WAIT:
- ldi Temp, 0b00010000
- out PORTB, Temp
- LED_ERROR:
- ldi Temp, 0b00100000
- out PORTB, Temp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement