1 / 8

Embedded Programming in C

Embedded Programming in C. Presented by: Jered Aasheim Tom Cornelius January 11, 2000. Why Use C?. C allows the programming low-level access to the machine architecture. Compiled C programs are memory efficient and can execute very fast.

kenaj
Download Presentation

Embedded Programming in C

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. Embedded Programming in C Presented by: Jered Aasheim Tom Cornelius January 11, 2000

  2. Why Use C? • C allows the programming low-level access to the machine architecture. • Compiled C programs are memory efficient and can execute very fast. • Higher level language constructs allow designs to be more complicated, reduce the number of bugs, and help get more done per unit of time.

  3. Data Types

  4. Number Representation In C, numbers can be expressed in decimal, hexadecimal, or octal:

  5. Bit Manipulation <<, >> - shifts value k bits to the left or right ex. 0x08 >> 3 // 0x01 & - bitwise ANDs two operands together ex. 0x08 & 0xF0 // 0x00 | - bitwise ORs two operands together ex. 0x08 | 0xF0 // 0xF8 ^ - bitwise XORs two operands together ex. 0xAA ^ 0xFF // 0x55

  6. Reading/Writing Individual Bits The bitwise AND and OR operators can be used to read/write individual bits in a variable: Ex. unsigned char reg = 0xB5; if(reg & 0x08) // Is the 4th bit a “1”? … else // 4th bit is not a “1” … reg = reg | 0x02; // Set the 2nd bit to a “1” reg = reg & 0xFE; // Set the 1st bit to a “0”

  7. Scope There are 3 ways to declare a variable – global, local, static: ex. unsigned char inputStatus; // global ex. void f(void) { int sum; … } // local ex. void g(void) { static char ttlLine; … } // static The static keyword means that the variable will retain its value across function calls; there are situations where this is very useful for retaining state in a subroutine/function.

  8. Infinite Program Loop Embedded systems are usually meant to always execute the same program for the duration of the time the device is on. This can be done using a “forever loop”: void main(void) { … for(;;) { // main program loop } }

More Related