Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Write a program that makes all LEDs blink with a 0.5 second period(in assembly). Use the 16-bit timer 1uit (a) to determine the interval. Generate an interrupt every 0.5 seconds by counting the counter until an "output compare match" is reached. Indicate in your answer how you calculated the value of OCR1A.


What I have tried:

i have tried with some interupts but its still not working
Posted
Updated 4-Oct-19 2:56am
Comments
Richard MacCutchan 3-Oct-19 13:51pm    
Please show your code and explain what "not working" means.

Start by reading up on the timer - and we have no idea which one that is, we don;t even know what processor family you are using, much less the actual model, or the rest of your hardware - and work out how to program it to a 0.5 second interval.
This calculation will complete the last part of the question: "Indicate in your answer..."

When you have that value, program the timer and cause it to generate the interrupt.
Write the interrupt handler, and add it to the interrupt vectors (or however the interrupts in your processor are handled: they aren't all the same but yoru course notes should cover it)
Then it's a simple matter to turn the LEDs on for one tick, and then off on the second. Time the blink (count ten "on" blicks and see how close to ten seconds you are) to verify the counter values you calculated to start with.

Sorry, but we can't do any of that for you: the assembler code for my processors would probably not work at all in yours! (In fact, it probably wouldn't even compile :laugh: )
 
Share this answer
 
It appears you're using an Atmel chip, possibly an ATmega328P?

Look in the datasheet, it will become your best friend, in the section on 16-bit timers (TIMER1) under the Modes of operation/Clear Timer on Compare section 13.9.2 page 125 and you will find the formula for the values you will need for OCR1A and prescale. Even if not an ATmega328P the formula will be similar for other chips.
 
Share this answer
 
Comments
Member 14611851 3-Oct-19 15:10pm    
thnx
<pre>
	.include "m328Pdef.inc"
	.def saveSR=r17
	.def temp=r18
	.org 0x0000
	rjmp init

	.org OC1Aaddr
	rjmp TIMER


init:
	ldi R16,high(RAMEND)
	out SPH, R16
	ldi r16, low(RAMEND)
	out SPL, R16

	ldi temp, high(31250)
	sts OCR1AH, temp
	ldi temp, low(31250)
	sts OCR1AL, temp
	ldi temp, (1 << CS12) | (1 << WGM12)
	sts TCCR1B, temp
	ldi temp, (1 << OCIE1A)
	sts TIMSK1, temp
	ser temp
	out DDRB, temp
	out PORTB, temp

	sei

loop:
	rjmp loop

TIMER:
	in saveSR, SREG
	in r16, PORTB
	com r16
	out PORTB, r16
	out SREG, saveSR
	reti


now i have this code, and its works! somebody with some tips for better code?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900