Embedded System - Unit II (Prepared by N.Shanmugasundaram)

56
Embedded System Unit II – Mixing C & Assembly Prepared by Prof. N.Shanmugasundaram HOD / ECE, VVCET.

description

Embedded system - Unit II, BE-ECE, Anna university of Technology, Coimbatore, R2008)

Transcript of Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Page 1: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded SystemUnit II – Mixing C & Assembly

Prepared by

Prof. N.ShanmugasundaramHOD / ECE, VVCET.

Page 2: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Programming Embedded system can be accomplished

in three different ways, by using programming languages like …

1. High level languages (like C, C++, Java…)

2. Assembly language (using Mnemonics, Eg. ADD, MOV, etc.)

3. Machine level language (using OPCODES, Eg. 80H for ADD B)

Embedded System – Unit II

Page 3: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Advantages of different level programming …

High level language (like C ) i) easy understandable program ii) portability into diff processor

Assembly level language i) compact code (compared to C) ii) access to the special features of

the processor hardware.

Machine level language i) Highly compact code ii) Fast execution

Embedded System – Unit II

Page 4: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Data Type Conversion

Page 5: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 6: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 7: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Manipulating Bits in Memory

Page 8: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 9: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 10: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 11: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 12: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 13: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Testing of Bits

Page 14: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Setting, Clearing and Inverting of Bits

Page 15: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 16: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 17: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Extracting of Bits

Page 18: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Inserting of Bits

Page 19: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Manipulating of Bits in I/O Ports

Page 20: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 21: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Write-only I/O Ports

Page 22: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 23: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Ports differentiated by Sequential Access

Page 24: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Ports differentiated by Bits in written data

Page 25: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Accessing Memory mapped I/O Devices

Most modern microprocessors are capable of addressing GBs of Memory, but embedded systems need only a few KBs of memory.

By assigning few unused memory address to I/O devices, these devices can be accessed as if a memory is being accessed.

A typical example of memory mapped I/O device is Display buffer (each character position in screen is assigned with one / more unique address).

In IBM-PC, color display buffer is mapped with memory address B8000H.

Each charater is assigned with 2 bytes, first byte for ASCII code of that character and second byte for the foreground and back ground color information.

The address of the first byte of a specific row & column is calculated as

B8000H + 2 (80 x Row + Column)

Page 26: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Accessing data through a pointer

In C,

We create a variable (ie., allocate memory for it) by declaring it;And then manipulate its content by referring to its identifier.

Example: int a;a = 5;

Alternate method to access a memory location is by using a pointer(Pointer is a variable that holds an address of memory location)

Example: int a, b;int *c ;

a = 5 ;c = &a;b = *c;

Page 27: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Typical programming to access display buffer through pointer variable is ...

Declarationchar *p ; /* “p” is a pointer to a char */

Initializationp = (char *) (0xB8000 + 2 * (80 * row + col)) ; /* p is intialized */

Declaration & Initializationchar *p = (char *) (0xB8000 + 2 * (80 * row + col)) ; /* declaration & initialization */

Assigning a value to pointer variable*p = ‘ A ‘ ; /* char ‘A’ is assigned to addr of p */

Embedded System – Unit II

Page 28: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

To display a text on screen; we can use a Pointer.

Page 29: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 30: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 31: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 32: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Structures

Page 33: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 34: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Packed Structures

Page 35: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Packed Structures

Page 36: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Bit Fields

Page 37: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 38: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 39: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 40: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 41: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 42: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 43: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 44: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 45: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 46: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 47: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 48: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 49: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 50: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 51: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 52: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 53: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 54: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 55: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II

Page 56: Embedded System - Unit II (Prepared by N.Shanmugasundaram)

Embedded System – Unit II