Embedded Programming in C

Slides:



Advertisements
Similar presentations
1 Storage Duration and Scope –Local and global variables Storage classes –automatic, static, external, register Todays Material.
Advertisements

OPTIMIZING C CODE FOR THE ARM PROCESSOR Optimizing code takes time and reduces source code readability Usually done for functions that are critical for.
C Language Programming. C has gradually replaced assembly language in many embedded applications. Data types –C has five basic data types: void, char,
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1.
Assignment Operators =, +=, *= A += B means (A+B) --->A or A = (A+B) Similarly true for -=, *=, /=, and %=. The basic rule is from right to left. Never.
CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.
Bit Operations C is well suited to system programming because it contains operators that can manipulate data at the bit level –Example: The Internet requires.
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
Railway Foundation Electronic, Electrical and Processor Engineering.
Bitwise Operations CSE 2451 Rong Shi. Working with bits – int values Decimal (not a power of two – used for human readability) – No preceding label –
Development. Development Environment Editor Assembler or compiler Embedded emulator/debugger IAR Embedded Workbench Kickstart Code Composer Essentials.
Bit Manipulation when every bit counts. Questions on Bit Manipulation l what is the motivation for bit manipulation l what is the binary, hexadecimal,
1 CS103 Guest Lecture Number Systems & Conversion Bitwise Logic Operations.
Lecture12. Outline Binary representation of integer numbers Operations on bits –The Bitwise AND Operator –The Bitwise Inclusive-OR Operator –The Bitwise.
Bitwise Operators in C. Bitwise operators are used to manipulate one or more bits from integral operands like char, int, short, long.
Bitwise Operators Fall 2008 Dr. David A. Gaitros
These notes were originally developed for CpSc 210 (C version) by Dr. Mike Westall in the Department of Computer Science at Clemson.
IFT 201: Unit 1 Lecture 1.3: Processor Architecture-3
CS1372: HELPING TO PUT THE COMPUTING IN ECE CS1372 Some Basics.
CS415 C++ Programming Takamitsu Kawai x4212 G11 CERC building WV Virtual Environments Lab West Virginia University.
Basic Types CGS 3460, Lecture 19 Feb 22, 2006 Hen-I Yang.
INTRODUCTION TO ‘C’ PROGRAMMING BY Prof. P. PADMANABHAM M.Tech (AE), M.Tech(CS), Ph.D(CS)-FIETE, FIE Director Academics, Bharat Institute Of Engineering.
C Language 1 Program Looping. C Language2 Topics Program looping Program looping Relational operators / expressions Relational operators / expressions.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Presentation By :- Nikhil R. Anande ( ) Electronic & Communication Engineering. 3 nd Year / 5 th Semester FACULTY GUIDE : RAHIUL PATEL SIR MICROCONTROLLER.
Windows Programming Lecture 06. Data Types Classification Data types are classified in two categories that is, – those data types which stores decimal.
Course Contents KIIT UNIVERSITY Sr # Major and Detailed Coverage Area
CSE 220 – C Programming Bitwise Operators.
The Machine Model Memory
Chapter 12 Variables and Operators
Week 3 - Friday CS222.
Programming in Java Sachin Malhotra, Chairperson, PGDM-IT, IMS Ghaziabad Saurabh Chaudhary, Dean, Academics, IMS Ghaziabad.
Morgan Kaufmann Publishers
Instructor: David Ferry
COM S 326X Deep C Programming for the 21st Century Prof. Rozier
EPSII 59:006 Spring 2004.
Bit Operations Horton pp
Chapter 3 Bit Operations
C Short Overview Lembit Jürimägi.
The University of Adelaide, School of Computer Science
CS 240 – Lecture 8 Bitwise Operations, Bit Manipulation, Type Conversion, Conditional Expression.
8051 Programming in C rhussin.
Chapter 12 Variables and Operators
Introduction to Programming and the C Language
Chapter 1 C for Embedded Systems.
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Chapter 1 C for Embedded Systems.
CS 240 – Lecture 9 Bit Shift Operations, Assignment Expressions, Modulo Operator, Converting Numeric Types to Strings.
Computer Architecture & Operations I
AVR Programming in C Chapter 7
Bitwise Operations C includes operators that permit working with the bit-level representation of a value. You can: - shift the bits of a value to the left.
AVR Programming in C Chapter 7
Embedded Programming in C
Homework Homework Continue Reading K&R Chapter 2 Questions?
Semantic Analysis Chapter 6.
Comp Org & Assembly Lang
Operations and Arithmetic
Comp Org & Assembly Lang
CS334: Number Systems Lab 1.
Module 10 Operations on Bits
Module 2 Variables, Data Types and Arithmetic
OPERATORS in C Programming
C Language B. DHIVYA 17PCA140 II MCA.
Lecture 2: Bits, Bytes, Ints
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Bit Manipulations CS212.
OPERATORS in C Programming
Bit Operations Horton pp
Chapter 12 Variables and Operators
Presentation transcript:

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. Higher level language constructs allow designs to be more complicated, reduce the number of bugs, and help get more done per unit of time.

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

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

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

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”

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.

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 }