|
Course Index Dr. Margush's page |
Homework 1: Complete all exercises in chapter 1 of Some Assembly Required. This is due Tuesday, Sept 4, at the start of class.
Homework 2: Complete all exercises (not programming exercises - although you should read these and think) in chapter 2 (see sar2.pdf) of Some Assembly Required. This is due Thursday, Sept 13 (evening) and Friday, Sept 14 (noon), at the start of class. No late assignments are accepted.
Lab assignment 1: Write a program for the STK500 / ATMega16 that flashes the LED's (connected on port B) cycling between these three patterns: xxxooooo, ooxxxxoo, and oooooxxx (where x represents on and o is off). 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.33 seconds. A printed copy of the nicely formatted program is due Monday, Sept 17, at the start of class. Be sure to document the program, including the setup of the STK500 and assumed ATMega16 fuse setting. If working in pairs, submit only one printout with both names on it.
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 255 if you ldi r20, 0) lp:The above loop requires 100 * 4 cycles which is 400 microseconds if 1MHz clock is used. You need to introduce a 333 millisecond delay in your program.
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
Homework 3 : Complete all exercises (1-24) (not programming exercises - although you should read these and think) in chapter 3 (see sar3.pdf) of Some Assembly Required. This is due Thursday the 21st (evening class) and Friday the 22nd (noon class), at the start of class. No late assignments are accepted.
Program 1 : Bit Walker. This program will use switch 0 and the 8 LED's to display the position of a 1 bit in a byte of otherwise all 0's. The other switches should be ingored. The byte begins with the unsigned value 1 (bit 0 is the only one set, so LED 0 should be illuminated). Each press of SW 0 walks the bit to the next highest position within the byte; the LED display follows the bit. When the bit "falls out" into the proverbial bit bucket (from position 7), the program stops (enters an infinite loop). You can restart the program by resetting the processor. You must deal with switch bounce in this program so the bit does not walk two steps with one button press. There are several ways to make the bit "walk." Look at the bit patterns of x+x compared to x (where x is any byte) for one clue. Provide adequate documentation and an elegant solution for full credit. You may work in pairs to complete this assignment. Due date: Thursday/Friday, Sept 27/28.
Homework 4 : Complete exercises (1-27) in chapter 4 (see sar4.pdf) of Some Assembly Required. This is due Thursday the 27th (evening class) and Friday the 28th (noon class), at the start of class. No late assignments are accepted.
Homework 5 : Complete exercises (28-46) in chapter 4 (see sar4.pdf) of Some Assembly Required. This is due Tuesday, Oct 2nd, at the start of class. No late assignments are accepted.
Homework 6 : Complete exercises (1-29) in chapter 5 (see sar5.pdf) of Some Assembly Required. This is due Friday, Oct 12th (Thursday Oct 11th for the evening class), at the start of class. No late assignments are accepted.
Program 2 : Due Friday, Oct 19 (Please email a copy of the source file: something.asm) LED Patterns. In this program you are to store LED patterns in EEPROM memory. When your application starts up, it will display the patterns sequentially forever, wrapping around to the first pattern when needed. The display rate will be variable and the patterns can be modified over time. While the patterns are cycling, pressing button 0 will slow the pattern change rate, increasing the time between changes by 0.5 seconds for each press. Pressing button 1 will increase the change rate, decreasing the time between changes (by 0.5 seconds for each press with a minimum of 0.5 seconds). The display rate must be remembered when power off occurs. Each display pattern can be modified by following this procedure. Press button 7 briefly to halt the cycling and display the current pattern. Allow button presses to toggle the associated LED in the pattern The toggle should occur when the button is released (not when it is depressed). When the desired pattern is displayed on the LEDs, press and hold button 7 for at least one second to store the currently displayed pattern and resume cycling. The processor must be set to run at 1MHz using the internal R/C oscillator. I highly recommend that you try using simple function calls for this project.
Writing simple functions in assembly language is fairly straightforward. To define a function, create a label representing the function name. Write the function body, ending it with a RET instruction. To invoke the function from elsewhere in your code, use an RCALL instruction. This instruction requires the address of the function which is just the label you placed at the start of the function's code.
The function definition is usually placed after the main part of the application. There is no need to use any type of forward declaration. Here is a skeleton of a program using functions.
.cseg
;stack initialization code must be located here
main:
;place your main application code here
…
rcall my_function
…
rjmp main ;assuming the main application repeats forever
my_function:
;function body goes here
…
ret
;place more function definitions here
The program begins by initializing the stack and then enters the main loop. When execution reaches the RCALL instruction, the return address is pushed on the stack and the address of the function is placed in the program counter. He next instruction will be fetched from the function body. Execution continues in the function until RET is reached. At this point, the return address is popped off the stack into the program counter, causing execution to resume with the instruction immediately after the RCALL.
Homework 7 : Complete exercises (1-16) in chapter 6 (see sar6.pdf) of Some Assembly Required. This is due Tuesday, Oct 30th , at the start of class. No late assignments are accepted.
Homework 8 : Complete exercises 19-26, 29-37 in chapter 6 (see sar6.pdf) of Some Assembly Required. This is due Tuesday, Nov 6th , at the start of class. No late assignments are accepted.
Program 3: Programming Lab exercise on parameter passing (counts as a program). Due Thursday, Nov 8th (Friday for Day class). Turn in a well documented printed copy.
Homework 9: Complete exercises 1-10, 17, 18 in chapter 7. Due Tuesday, Nov 13 at the start of class.
Interrupts lab: Get it here! Due Tuesday, Nov 20th
Program 4: Solve the serial I/O problem . Email the completed files (application.asm and serial.asm) by the due date which is Nov 27th.
Homework 10: Complete exercises 1-5, 7, 10, 14-18, 25 in chapter 10. Due Wednesday, November 28 / Thursday, Nov 29 at the start of class.