Assembly Language Programming

Course Index 
Dr. Margush's page 

Lab 1

Write a program for the STK500 / ATMega16 that flashes the LED's (connected on port B) alternating between these two patterns: xxxxoooo and ooooxxxx (where x represents on and o is off). (Hint: Look up the swap instruction.) The ATMega16 must be configured to operate using its internal RC Oscillator running at 1 MHz. Your program must cause the LEDs to change every 0.5 seconds (approximate). 

You will need to create several loops (maybe even nested loops). Here is a simple example of a loop that executes 100 times and then goes on to the next statement in memory. The BRNE instruction branches back to the label if the previous DEC yields a result that is not equal to zero.

  ;begin with a statement to initialize the loop counter
ldi r20, 100 ;number of iterations (max is 256 iterations if you start at 0)
lp:
nop ;you can add or remove nops to adjust timing
dec r20 ;any free register may be used
brne lp ;this loop consumes 4 cycles per iteration
;statement to be executed on termination goes here
The above loop requires 100 * 4 cycles which is 400 microseconds if 1MHz clock is used. You need to introduce a 500 millisecond delay in your program.

A printed copy of the nicely formatted program is due at the conclusion of the lab. Be sure to document the program, including the setup of the STK500 and the required ATMega16 fuse setting. Include an extensive comment explaining how the .5 second delay is accomplished. If working in pairs, submit only one printout with both names on it.

Return to Dr. Margush's page