Embedded C For MP
Embedded C For MP
6.1 Introduction
C versus Assembly
Advantages of C
High-level, structured programming language
Compiler relieves programmer from some of the
hardware details
Easier to write large, complex software
Programs more readable
Disadvantages of C
Generally larger machine code
Less control and ability to interact with hardware
Unclear number of cycles to do something
6.2 Data types
Copy Q. 4( c) May 2016 & Part I of Q. 6( c) Dec. 2016 here.
A good understanding of C data types for 8051 can help programmers to create smaller
hex files.
unsigned char
signed char
unsigned int
signed int
sbit (single bit)
bit and sfr
1. unsigned char:
Table 6.1
Programs
6.3
6.4.1
6.4.2 Bit-addressable I/O Programming
The I/O ports of P0-P3 are bit addressable. This means a single bit of the port can
be accessed without disturbing the other bits.
The bit can be accessed using the data type sbit. One way to do that is to use the
format Px^y, where x is the port 0, 1, 2, 3 and y is the bit 0-7 of that port.
For example P1^3 indicates P1.3.
6.4.3 Accessing SFR Addresses 80 FFH
The sfr data type can be used to access the SFR RAM space 80H-FFH.
When this data type is used no need of using the header file reg51.h.
Table 6.2 shows the single bit addresses of ports.
6.5 Logic Operation
Copy Q. 6(b), Dec. 2016 here.
The ability to perform bit manipulation is one of the most important and powerful
features of the C language .
The bitwise operators used in C are AND (&), OR ( | ), EX-OR ( ^ ), inverter (~),
Shift right (>>) and Shift left (<<).
These are widely used in software engineering for embedded systems and
control; consequently, understanding them is important in microprocessor and
microcontroller-based system design and interfacing.
Data
step b
To use the code space, we need to put the keyword code in front of the variable
declaration.
Ex. Compile and run the following program on the 8051 simulator and examine the
contents of the code space to locate the ASCII values.
The code space locates the values 41H, 42H, 43H, 44H, etc. the hex values for ASCII
characters of A, B, C, D,
In many new generations of devices such as LCD, ADC, and ROM the serial versions are
becoming popular since they take less space on a PCB.