Last active
May 8, 2017 14:20
-
-
Save gusaa960/4677ec1f3e57ab8ac9aed19514289c58 to your computer and use it in GitHub Desktop.
LABB 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; | |
; Labb3.asm | |
; | |
; Created: 2017-05-08 15:16:55 | |
; Author : Gustav Aaro | |
; | |
.def zeroReg = r17 | |
.def currentNumber = r18 | |
.def currentDisplay = r19 | |
.def minHigh = r20 | |
.def minLow = r21 | |
.def secHigh = r22 | |
.def secLow = r23 | |
; Replace with your application code | |
.org $0000 | |
jmp COLD | |
.org INT0addr | |
jmp INT_0 | |
.org INT1addr | |
jmp INT_1 | |
; −−− Cold Start | |
COLD: | |
ldi r16,HIGH(RAMEND) | |
out SPH,r16 | |
ldi r16,LOW(RAMEND) | |
out SPL,r16 | |
; −−− Configure and enable interrupts | |
; Configure. Here rising edge triggered | |
ldi r16,(1<<ISC01) | (1<<ISC00) | (1<<ISC11) | (1<<ISC10) | |
out MCUCR,r16 | |
; Activate. Here INT1 and INT0 | |
ldi r16,(1<<INT0) | (1<<INT1) | |
out GICR,r16 | |
; Enable Interrupts Globally | |
sei | |
;Set port A and B as output | |
ldi r16, $FF | |
out DDRB, r16 | |
ldi r16, $03 | |
out DDRA, r16 | |
WAIT: | |
jmp WAIT | |
; | |
; −−− ISR’s, Interrupt Service Routines | |
; | |
UPDATE_DISPLAY: | |
ldi currentDisplay, 0 | |
mov currentNumber, secLow | |
call LOOKUP_DISPLAY_VALUE | |
call SEND_TO_DISPLAY | |
ldi currentDisplay, 1 | |
mov currentNumber, secHigh | |
call LOOKUP_DISPLAY_VALUE | |
call SEND_TO_DISPLAY | |
ldi currentDisplay, 2 | |
mov currentNumber, minLow | |
call LOOKUP_DISPLAY_VALUE | |
call SEND_TO_DISPLAY | |
ldi currentDisplay, 3 | |
mov currentNumber, minHigh | |
call LOOKUP_DISPLAY_VALUE | |
call SEND_TO_DISPLAY | |
SEND_TO_DISPLAY: | |
out PORTA, currentDisplay | |
out PORTB, currentNumber | |
ret | |
LOOKUP_DISPLAY_VALUE: | |
ldi ZL, LOW(TABLE*2) | |
ldi ZH, HIGH(TABLE*2) | |
add ZL, currentNumber ; Offsets the Z-pointer to the position of our value | |
adc ZH, zeroReg | |
lpm currentNumber, Z | |
ret | |
INC_TIME: | |
inc secLow | |
cpi secLow, 10 | |
brne DONE_INC | |
clr secLow | |
inc secHigh | |
cpi secHigh, 6 | |
brne DONE_INC | |
clr secHigh | |
inc minLow | |
cpi minLow, 10 | |
brne DONE_INC | |
clr minLow | |
inc minHigh | |
cpi minHigh, 6 | |
brne DONE_INC | |
clr minHigh | |
DONE_INC: | |
ret | |
INT_0: | |
; 1 Hz-avbrottet, kopplad till pin 2 på port D | |
call INC_TIME | |
reti | |
INT_1: | |
call UPDATE_DISPLAY | |
reti | |
TABLE: ;tabell för siffror 1-9 | |
.db $7E, $30, $5D, $79, $33, $5B, $5F, $70, $7F, $73 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment