CS210 Lab -- Coding for the AVR, part 2.

In this lab, we'll extend what we did last week. The program will now use a SUBROUTINE to compute the square of a number. Modify the code as needed, compile, and get a hex file. An outline of the program is as follows.

Set up the registers as before, to turn the pins to outputs (so you can drive the LEDS).

Implement the code below in C. This will need to go into your main program.

while (1)
{
 for (i = 0; i < 10; i = i + 1)
   {
 	PORTB = square(i);
	_delay_ms( 20.0);
	}
}

You will need to write a function called square. It will be something like this:
int square(int x) { return x*x; }

 

Build a hex file, and burn this onto the processor. You should see the numbers 1, 4, 9, 16, ... 100, appearing in binary on the LEDs.