ET254 C Programming for Technology

I. CATALOG DESCRIPTION:

ET254 C Programming for Technology C-2, P-2, CR-3
This is an Electrical Engineering Technology elective detailing the C programming language and how it is applied to problems in the technology field. A complete examination of the language is presented. Laboratory exercises are concerned with typical problems encountered in the electrical field. The focus is on desktop and embedded system development.

Corequisites: ET181 Digital Electronics 1 or permission of departmental advisor.

Prerequisites: ET154 Computer Programming or equivalent, or permission of departmental advisor.

II. MATERIALS:

Text: C for PICMicro CD-ROM V3, Rob Miles, Matrix Multimedia

 III. STUDENT LEARNING OUTCOMES:

The student will demonstrate a basic proficiency in the C programming language.

The student will demonstrate an understanding of the differences between programming a desktop computer and a microcontroller.

The student will demonstrate a basic knowledge of how to use a host computer to program a microcontroller or other external target.

The student will demonstrate problem analysis and solution techniques using the computer as a tool.

The student will demonstrate knowledge of the use of high level software development tools.

Through the laboratory, the student will demonstrate practical insight and knowledge of microcontroller systems and input/output devices.



Link to Course Assessment Standards

Background

This course assumes proficiency in at least one high level language such as BASIC, FORTRAN, or Pascal. Familiarity with basic Boolean algebra and numbering systems (hex, binary) is required. If you've completed ET154 Computer Programming and ET181 Digital Electronics, you're all set (for EST majors, that would be ET105 Computer Control Fundamentals and ET235 Digital Logic). It is helpful if you've also taken a course in microprocessors. Unlike most courses in the C language, this course focuses on those topics of primary interest to electrical engineers and technicians. The language as a whole is covered, but extra emphasis is placed on issues such as embedded development systems and microprocessor optimizations. We will not be covering Windows GUI programming in this course.

This course was revamped starting with the Fall 2003 semester and is now available as an on-line (Web-based) course. We will be shifting over to a PIC microcontroller after the first few weeks of class in order to get into embedded controller programming. If you opt to purchase your own controller board, you can do the lab portion of the course on the Web as well, otherwise labs are on campus. We will use the PICmicro board (version 2) made by Matrix Multimedia (www.matrixmultimedia.co.uk). This hooks into an ordinary PC. The board costs about $250 and can be purchased in the US at Electronix Express (www.elexp.com/am_matr.htm) or Rentron (www.rentron.com/C2C.htm). We will also use the companion CD-ROM "C for PICmicro Controllers V3" by Rob Miles. This CD-ROM is a bargain as it contains the PIC compiler plus an on-line book on C programming with examples. If you opt for on-line labs, you will need a desktop C compiler (just about any will do, including Visual C/C++, Borland, Code Warrior, or even GCC). Several development systems are available, ranging from free to >$1k. We use Microsoft Visual C++ 6.0 in lab simply because it's widely available. (It has many bells and whistles that we don't really need for this course, but which are useful for Windows GUI programming). The standard edition can be had for under $100, and sometimes as little as $50 with rebate. You might consider a freeware system such as gcc.

If you like print books, there are many good books on C available (just make sure it's C and not C++) including Kochan's book (Programming in ANSI C) and the one by Deitel & Deitel (C-How to Program). One final comment regarding this and all courses I teach: Remember, plagiarism is grounds for failure.

 

Week-by-week progress and assignments

1

Introduction to C language: keywords, variable types, math operators, function calls, simple examples such as Hello World.

  • Reading: C For PICmicros: Introduction, first half of Programming section, and C Progamming-What Is A C Program? Lecture Notes: CourseIntro and CBasics. Start the CWorkBasics worksheet.
  • Lab: CLabIntro
  • This week's friendly hint: Don't forget those semi-colons!
2

Beginning programming examples. We will also take a look at the Preprocessor, including the #include and #define directives, and a peak at scanf(). We will also look at bitwise operators including OR, AND, and XOR

  • Reading: C For PICmicros: Variables. Lecture Notes: CBasics2, CStorage. Complete the CWorkBasics worksheet.
  • Lab: CLabStdIO
  • This week's friendly hint: Don't forget those #includes!
3

We examine basic decision/branching constructs, including if/else, switch/case and Boolean connectives (i.e, logical AND and OR).

  • Reading: C For PICmicros: Conditionals, Switch, and begin Statements & Blocks. Lecture Notes: CArch, CIfLoop (first half). Do the CWorkMath worksheet.
  • Lab: CLabConditionals
  • This week's friendly hint: Remember, C uses "=" for assignment and "==" for comparisons. The code snippet if ( x = y ) does not compare x to y. Rather, it assigns the value of y to x and then checks to see if that value is non-zero. This is a common beginner's error (even seasoned pros do it). Here is a coding technique which can save your butt from time to time when comparing a variable against a constant: Instead of saying if ( x == 2 ), say if ( 2 == x ). The compiler will cough up an error if you accidentally forget the double = and type in if ( 2 = x ), since you can't assign a value to a constant.
4

We examine basic looping constructs, including for, while, and do/while. Conceptually, much of this should be review with only the C peculiarities and syntax being new.

  • Reading: C For PICmicros: Finish Statements & Blocks, read Loops and Functions. Lecture Notes: CIfLoop (second half), CArch
  • Lab: CLabLoops
  • This week's friendly hint: Don't compare directly against numeric constants. Instead, use the #define directive to make symbolic constants as the resulting code will be self-documenting. For example, use #define VOLTAGE_DIVIDER 1 and then form the switch statement as follows: case VOLTAGE_DIVIDER:
5

This is the approximate time of our first test. Time for review.

  • Reading: C For PICmicros: Compiling & Running C Programs. Also, if you're doing on-line labs, make sure you have read and followed the instructions in the second half of the Intro regarding the development board hardware. Lecture Notes: CEmbedded
  • Lab: We begin using the PICmicro. #1 Flashing Lights.
  • This week's friendly hint: By now you've probably gotten into the habit of dropping semi-colons at the end of every statement. A loop is s one place you don't want to do this. The code fragment x=1; while( x<10 ); {...useful stuff here... x++; } will loop forever! The semi-colon immediately after the while() effectively signifies the end of the section to be looped, and the section in braces is never reached.
6

We begin a detailed examination of arrays. Perhaps the most popular array in C is the character array, or string.

  • Reading: C For PICmicros: Begin Arrays. Lecture Notes: Begin CArrays.
  • Lab: #2 Switches and Torches
  • This week's friendly hint: Always, always, always make sure that your strings are null-terminated.
7

We examine pointers and handles. Fun and danger await! C's strange but useful interrelation between arrays and pointers. More on arrays.

  • Reading: C For PICmicros: Finish Arrays and begin Pointers. Lecture Notes: Finish CArrays, start CPointers. Start the CWorkPointers worksheet.
  • Lab: #3 Sound Software
  • This week's friendly hint: Don't confuse * and &. * is used to declare pointers and to get the value of a pointer (i.e., that which is stored at that address). & is used to get the address of a "normal" variable (i.e., one that wasn't declared as a pointer). * is never used with normal variables (except to represent multiplication, of course). If a variable is declared as a pointer and you use & on it, then you get the address of the pointer (i.e., doubly indirect). Pointers that are double indirect are commonly known as handles.
8

We wrap up our work on pointers and arrays.

  • Reading: C For PICmicros: Finish Pointers. Lecture Notes: Finish CPointers. Finish the CWorkPointers worksheet.
  • Lab: CLabPointers
  • This week's friendly hint: The string array declarations char *x[] and char y[][] are not entirely equivalent, although they can be accessed similarly. This makes some people crazy. Here's an exercise which should clarify things: Think about what each declaration means, and then draw a corresponding memory map. Now, pretend that you're a compiler and consider the following: Must the elements x refers to be contiguous in memory? What about y? That is, can you find (access) any given element (in this case, char strings) if they are non-contiguous?
9

Even more fun with data types- adventures with structures.

  • Reading: C For PICmicros: Start Structures. Lecture Notes: Start CStructures. Start the CWorkStructures worksheet.
  • Lab: #4 LEDs and Clocks
  • This week's friendly hint: There is another, though less often used aggregate data type known as the union. We won't be studying it, but suffice to say that if you understand how structures work, you should have no problem with unions. Think of them as structures that have more than one name for the same field.
10

More on structures, including structures within structures, arrays within structures, and arrays of structures.

  • Reading: C For PICmicros: Finish Structures. Lecture Notes: Finish CStructures.
  • Lab: #5 LCDs and Libraries
  • This week's friendly hint: There is no such thing as a universal "best" solution for all cases. Smart designers look at their design requirements and limitations and then choose an optimal solution. For example, sometimes nested if/else are better than switch/case and sometimes they're not. It all depends on what you need to do.
11

Fun with linked lists. We examine their pros and cons. Around here we'll have a test.

  • Reading: C For PICmicros: Software Engineering in C. Lecture Notes: CLinkedLists. Finish the CWorkStructures worksheet.
  • Lab: #6 Mystic LCD
  • This week's friendly hint: There are no limits to how data types are intertwined. It is possible (and in fact, quite useful) to create something like an array of pointers to structures where the structures themselves contain pointers to other structures and/or arrays or lists.
12

Memory allocation- how to dynamically create variable space.

  • Reading: Lecture Notes: CMemory
  • Lab: #7 PICing a Lock
  • This week's friendly hint: Always, always, always test the return value from a memory allocation routine for a null pointer. The system may not be able to honor your allocation request, and your code should fail gracefully (i.e., not chase the null pointer!)
13

File I/O. How to read and write data to and from disk.

  • Reading: Lecture Notes: CFileIO
  • Lab: #8 Reaction Timer
  • This week's friendly hint: Beware the different "levels" of file access. Some are designed for easy handling of text or formatted data, others work best for "bit twiddling". Since we tend to work closer to the hardware, we'll focus on the nitty gritty bit twiddling level.
14

We finish FileI/O. We also look at command line arguments and conditional compilation.

  • Reading: Lecture Notes: CCmdLine
  • Lab: #9 Inspect Your Morse
  • This week's friendly hint: When dealing with multi-byte sized values (e.g., ints, floats, etc.), you need to consider the byte ordering of the file. For example, files originally written on a Mac tend to be reversed compared to those written under Windows. If you plan to write code which will run on multiple platforms, you need to consider both the byte ordering of the file and the (now variable) byte ordering of the target CPU.
15

Course wrap-up and review.

  • Reading: Check out Embedded Systems Journal for real-world applications.
  • Lab: Open time.
  • This week's friendly hint: No matter how much you know about programming, there will always be something else to learn about it.

[Home] [MVCC Home]

© 2008 Jim Fiore