The purpose of this assignment is to gain experience with the mixing C and assembly code in one project. The assignment is designed to demonstrate that it is more efficient to write some code in a high level language that has support for things like floating point arithmetic while it other things, like I/O maniuplation and interrupt handling, are more easily written in assembly language.
In this lab, you will design, code, assemble, link, simulate, download and run a program. The main project will be written in C, and a function called from C will be written in assembly. Your program should act as a floating point voltmeter.
You should use some of your code from previous assignments. In particular, the getADC from lab 6 should already be compatible with the C parameter passing conventions since the parameter passed to the function was passed in R24 and the resulting ADC conversion is returned via R24.
In order to display the digital value in volts, you will need to multiply the ADC result by the appropriate scaling factor. The variable that holds the result of this multiplication should be a floating point value. Doing floating point arithmetic in assembly is tedious and error prone, but it's pretty simple to do in C. You should write this function in C.
Displaying a floating point result on the LCD is not trivial regardless of whether it's implement this in assembly or C. You may use the function provided in the stk200.zip library files with the following prototype:
void lcd_print_float(float value);
You should unzip the stk200.zip file in the D:/Atmel/winavr/avr/include directory so that you now have a new directory: D:/Atmel/winavr/avr/include/stk200 that contains the following files: bit.c, delay.c, delay.h, globaldef.h, lcd.c, lcd.h, lcdconf.h, uart.c, and uart.h.
You should write one adc.s file that contains the following functions:
The following should be included at the beginning of the assembly file:
/** * General source file documentation goes here. TODO */ #define _SFR_ASM_COMPAT 1 #define __SFR_OFFSET 0 /* User 0 for the offset of the I/O registers */ #include <avr/io.h> /* Contains I/O label declarations, like m32def.inc */ .global getADC ; Makes getADC visible to other source files .global initADC ; Makes initADC visible to other source files .section .text
You should write one lab8.c file that contains the following functions:
The following should be included at the beginning of the C file:
/** * General source file documentation goes here. TODO */ #include <inttypes.h> /* Contains C 99 type declarations */ #include <avr/interrupt.h> /* Contains interrupt related functions. */ #include <stk200/bit.c> /* Contains macros used by lcd.c */ #include <stk200/lcd.c> /* Contains LCD library functions. */ /* Documentation for initADC TODO */ extern void initADC(uint8_t channel); /* Prototypes for: TODO getADC assembly function convertToVoltage C function */
See the wiki article on Configuring GCC Projects in AVR Studio.
Students in need of an additional challenge may wish to modify the provided lcd.c so that it makes use of the 4-bit LCD mode. In 4-bit mode, data and commands are sent to the the LCD on pins 4-7 of PORTA. Using the 4-bit mode avoids the problems associated with tying PORTA3 to the potentiometer.
Submit your FAST time for week 9 (see below) and smile.
Also, you must log the time you spent on this assignment each week in FAST (in the week 9 and week 10 columns).
You must create the GCC based project described above. You should be able to compile, assemble, and link your two source files. Your assembly code should be completely operational. At a minimum, your main C function should call the two assembly functions and then call lcd_print_float() function passing the raw result from the getADC() function (cast as a float).
You should submit the following files:
using the online submission form.
In addition to the standard documentation, your C source file should contain an explanation of how/where the C compiler stores local variables for the C functions it compiles. You may find it helpful to include selections from the resulting lab8.lss to aid in your explanation.
You must demonstrate your program working on your board.
This assignment is based on a similar assignment developed by Prof. Bill Barnekow.
© 2001-2007 Dr. Christopher C. Taylor | Office: L-343 | Phone: 277-7339 |