Hi, I am trying to write a program for a timer. The operation is given as follows:
- The diodes show the number of seconds/minutes elapsed since start/restart.
- By pressing Switch2 the diodes show the number of minutes.
- By pressing Switch3 the diodes show the number of seconds.
- After 60 minutes the timer is reset.
I am pretty much a complete beginner when it comes to Assembler programming, so I feel like this is way out of my league. But I think I figured out which registers to set at least. And I also know that I need to set the program up for interrupts and initialize the stack pointer. The following is what I have so far.
.include "M32def.inc"
.def temp=R16
.org 0 jmp start
.org 2 jmp Sw2
.org 4 jmp Sw3
start:
;---PortB as out-port---
ldi temp, 0xFF
out DDRB, temp
;---Initialize for interrupts INT0 and INT1---
ldi temp, 0xC0
out GICR, temp ; set bits 6 and 7 to enable interrupts from INT0 and INT1
ldi temp, 0x0A
out MCUCR, temp ;set bits 3 and 1 to trigger interrupts when the switches are pressed down
;---other registers---
ldi temp, 0x0B
out TCCR1B, temp ; count frequency = 65.5k (0xF424)
ldi temp, 0xF4
out OCR1AH, temp
ldi temp, 0x24
out OCR1AL, temp ; interrupt every second, when the contents of the count registers
ldi temp, 0x0f ; is equal to the "output compare" registers.
out TIMSK, temp ; set bit 4 to enable Timer1 CompA match interrupt.
;---Initialize stack pointer-----
ldi temp, HIGH (RAMEND)
out sph, temp
ldi temp, LOW (RAMEND)
out spl, temp
sei ; global interrupt enable
Of course, I have neither the main program nor the two subroutines. Is what I have so far correct, though? And how should I approach writing the stuff that I'm missing?
Bit of a long question here, but hopefully someone who knows this stuff can give me a few pointers.
Thanks!
- The diodes show the number of seconds/minutes elapsed since start/restart.
- By pressing Switch2 the diodes show the number of minutes.
- By pressing Switch3 the diodes show the number of seconds.
- After 60 minutes the timer is reset.
I am pretty much a complete beginner when it comes to Assembler programming, so I feel like this is way out of my league. But I think I figured out which registers to set at least. And I also know that I need to set the program up for interrupts and initialize the stack pointer. The following is what I have so far.
.include "M32def.inc"
.def temp=R16
.org 0 jmp start
.org 2 jmp Sw2
.org 4 jmp Sw3
start:
;---PortB as out-port---
ldi temp, 0xFF
out DDRB, temp
;---Initialize for interrupts INT0 and INT1---
ldi temp, 0xC0
out GICR, temp ; set bits 6 and 7 to enable interrupts from INT0 and INT1
ldi temp, 0x0A
out MCUCR, temp ;set bits 3 and 1 to trigger interrupts when the switches are pressed down
;---other registers---
ldi temp, 0x0B
out TCCR1B, temp ; count frequency = 65.5k (0xF424)
ldi temp, 0xF4
out OCR1AH, temp
ldi temp, 0x24
out OCR1AL, temp ; interrupt every second, when the contents of the count registers
ldi temp, 0x0f ; is equal to the "output compare" registers.
out TIMSK, temp ; set bit 4 to enable Timer1 CompA match interrupt.
;---Initialize stack pointer-----
ldi temp, HIGH (RAMEND)
out sph, temp
ldi temp, LOW (RAMEND)
out spl, temp
sei ; global interrupt enable
Of course, I have neither the main program nor the two subroutines. Is what I have so far correct, though? And how should I approach writing the stuff that I'm missing?
Bit of a long question here, but hopefully someone who knows this stuff can give me a few pointers.
Thanks!
Last edited: