Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- ; 1DT301, Computer Technology I
- ; Date: 2017-09-289
- ; Author:
- ; Christian Fagerholm
- ; Amelie Löwe
- ;
- ; Lab number: 4
- ; Title: How to use the PORTs. Digital input/output. Subroutine call.
- ;
- ; Hardware: STK600, CPU ATmega2560
- ;
- ; Function: Describe the function of the program, so that you can understand it,
- ; even if you're viewing this in a year from now!
- ;
- ; Input ports: None
- ;
- ; Output ports: example on-board LEDsonnected to PORTB.
- ;
- ;
- ; Subroutines: If applicable.
- ; Included files: m2560def.inc
- ;
- ; Other information:
- ;
- ; Changes in program: (Description and date)
- ;
- ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- ; Replace with your application code
- .org 0x00
- rjmp setup
- .org OVF1addr
- rjmp timer1_int
- .org 0x72
- setup:
- .equ timer_start = 65036
- .def temp = r16
- .include "m2560def.inc"
- ldi r20, HIGH(RAMEND) ;Initiating Stack
- out SPH, r20 ;
- ldi r20, LOW(RAMEND)
- out SPL, r20
- ldi r19, 0x00
- ldi r17, 0xFF ;Outputs, Port B
- out DDRB, r17
- ldi temp, 0x05 ; prescaler value 1024
- sts TCCR1B, temp
- ldi temp, (1<<TOIE1) ; Timer 1 enable flag, TOIE1
- sts TIMSK1, temp ; to register TIMSK
- ldi temp , HIGH(timer_start)
- sts TCNT1H, temp
- ldi temp, LOW(timer_start)
- sts TCNT1L, temp
- sei ; enable global interrupt
- start:
- nop
- rjmp start
- timer1_int:
- push temp ; timer interrupt routine
- in temp, SREG ; save SREG on stack
- push temp
- ldi temp, HIGH(timer_start)
- sts TCNT1H, temp
- ldi temp, LOW(timer_start)
- sts TCNT1L, temp
- com r19
- out PORTB, r19
- pop temp ; restore SREG
- out SREG, temp
- pop temp ; restore register
- reti
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement