1 / 12

Basic Overview of C and Overview of Project 1

Basic Overview of C and Overview of Project 1. Matthew Murach. Sample Program. /* A sample program */ void main() { int a = 5; /* Variable a */ while(1) /* Infinite Loop */ { while(!start_button()); /* Program stalls until start button is pressed */

toddbeaver
Download Presentation

Basic Overview of C and Overview of Project 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Basic Overview of C andOverview of Project 1 Matthew Murach

  2. Sample Program /* A sample program */ void main() { int a = 5; /* Variable a */ while(1) /* Infinite Loop */ { while(!start_button()); /* Program stalls until start button is pressed */ while(start_button()); /* Program stalls until start button is released */ printf(“The value of a is %d”, a); a++; if (a > 10) fd(0); else bk(0); } }

  3. Fundamentals of C • Comments in C should use /* and corresponding */ to mark comment regions in code • // is not allowed in C • Proper usage of comments is essential for your understanding as well as fellow team members working on your code

  4. Fundamentals of C (cont) • printf is C’s equivalent to cout in C++ • There are a number of special characters for the printf function. • %d indicates that an unsigned decimal integer will follow. • \n denotes a new line should be called • For example printf(“\n Hello %d”, 5); will print Hello 5 at the prompt

  5. Fundamentals of C (cont.) • Basic loop operations are the same as C++ • For instance, while(a == b) {do something here} • As a shortcut while and for loops that have no functional elements can be written as follows while(a == b); /* Same as while(a == b){} */

  6. Fundamentals of C • If/Else If/Else are the same in C as in C++ • Note that Case/Switch statements are NOT supported in Interactive C • For Example /* Assign Greater of A or B to C */ if(a < b) c=b; else c=a; • Note that if you only execute one instruction you may omit the {} and use a ; instead.

  7. Structure of C • Note that C REQUIRES that variables be declared before the start of the body for instance, void main() void main() { { int a = 5; int a = 5; printf(\n %i); int b; /* correct */ int b; /* ERROR! */ printf(\n %i); } }

  8. Handyboard Caveats to C • Scanf is a disallowed feature in interactive C • Single char declarations are illegal but char strings are okay. Example char a; /* wrong */ char a[1]; /* okay */ • As mentioned before case and switch is not allowed. • Octal notation is not supported

  9. Notes on IC • IC requires DOS old style naming conventions for files i.e. 8 plus 3 for extension. load test_comb.c /* error unscore */ load testconverter.c /* error too long */ load comlock.c /* Correct */ • When Working with IC, Verify that the libraries have been properly loaded.

  10. Project 1 overview • Essentially you are designing a very combinational lock that accepts one bit at a time (serial input) • At each iteration or state the program should run a compare operation between the actual combination and the user input.

  11. How does the user input values? • A bank of digital inputs 7-15 is located on the handyboard. • A short between the top most pin and bottom most pin indicates a logic ‘1’ • An open port denotes a logic ‘0’ • For example, a = digital(7); /* grabs value from port 7 */

  12. State Machine 1 1 1 1 1 1 1 0 0 1 1 0 1 0 0 0 0 0 0 0 Test Passed Test Failed

More Related