Presentation is loading. Please wait.

Presentation is loading. Please wait.

Embedded Programming in C

Similar presentations


Presentation on theme: "Embedded Programming in C"— 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 Type Size (bits) Dynamic Range unsigned char 8 0…255
-128…127 unsigned int 16 0…65,535 signed int -32,678…32,677 unsigned long 32 0…4,294,967,295 signed long -2,147,483,647… 2,147,483,647

4 Number Representation
In C, numbers can be expressed in decimal, hexadecimal, or octal: Decimal 2 63 83 Octal 00 02 077 0123 Hexadecimal 0x0 0x2 0x3F 0x53

5 Bit Manipulation <<, >> - shifts value k bits to the left or right ex. 0x08 >> // 0x01 & - bitwise ANDs two operands together ex. 0x08 & 0xF0 // 0x00 | - bitwise ORs two operands together ex. 0x08 | 0xF // 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 }


Download ppt "Embedded Programming in C"

Similar presentations


Ads by Google