Lab 8: C and the A/D Converter
Introduction
In this lab, we will make a major change and begin programming using the C programming language. For medium to large projects, an embedded program is easier to code in C than assembly, and C is the preferred programming language of the embedded world (as is its closely related cousin, C++). However, programming in C is more complex than programming in assembly, and there are many pitfalls to be aware of. We can't explore all the intricacies of using C in this lab, but we can demonstrate the basics using some simple demo programs. The hardware feature of the lab is the A/D converter, and the goal of the lab is to create a simple C program which uses the A/D converter.
There are many references on using C in embedded systems. One good resource is the online book by Jonathan Valvano at Developing Embedded Software in C Using ICC11/ICC12/Hiware . Another recommended resource is the book Programming Embedded Systems in C and C++ by M. Barr (1999, O'Reilly), ISBN: 1-56592-354-5.
1-Pre-lab
In a few paragraphs, describe the main differences between C and assembly. As part of this, discuss the differences between setting up a C project and an assembly project in Code Warrior. Imagine that you wrote two programs for the hcs12. One program is written in C, and the other in assembly. Both do the same thing (eg, light LEDs in response to button pushes). Which is more portable to other processors such as an 8051 or a PIC, the embedded C program or the embedded assembly program? Why?
2-Tutorials
3-Program
Modify the ADC C program in part (c) above so that:
* The ATD Conversion clock frequency is set to 0.8 MHz (use a system clock frequency of 24 MHz)
* The final sample time is set to 8 A/D clock periods
* The final sample is 8 bits.
* The LED sequence is replaced with the 8 bit binary number from the conversion. The values should range from $00 to $ff depending on the trimpot.
Name your project 'lab8' and the assembly code 'lab8.asm'. The executable should be called 'lab8.abs.s1'. Assemble the program, load it into the Dragon12 using the DBug12 "load" command, and then run the program using "g 1829" under DBug12. Once the program assembles and runs OK, do your check out with the TA.
4-What to Hand In
At the next lab, hand in the commented code from your program from above. Remember to include your: (1) name; (2) date; (3) class (eg, UTEP EE3176);(4) the name of the program (eg, "lab8.asm"); and (5) what the program does. In addition, there should be comments throughout your program that describe what the main sections of code do.