Basics of Embedded C Languagae
Basics of Embedded C Languagae
presents
Basics of Embedded
C Language
Email : [email protected]
Web : www.roboindia.com
Phase 1 | Fundamentals of
Embedded C
Benefits of C language:
o Easier and less time consuming
o Easier to modify and update.
o Codes available in function libraries.
o Portable
www.roboindia.c
Phase 1 | Fundamentals of
Embedded C
Variables
unsigned int x;
x = 10;
Data Type
Size in Bits
0 to 255
Signed char
8 - bit
-128 to +127
Unsigned int
16 - bit
0 to 65535
Signed int
16 - bit
-32768 to 32767
sbit
1 - bit
bit
1 - bit
sfr
8 - bit
www.roboindia.c
Phase 1 | Fundamentals of
Embedded C
Constant
a=20;
#define delay_time 184
Bit Addressable I/O Programming
sbit mybit = P1^5;
www.roboindia.c
Phase 1 | Fundamentals of
Embedded C
HEX Numbers in C
P1 = 0x10; (10 in HEX is 16 in decimal)
P2 = 0xFF; (Set all bits of port 2 to 11111111 or
decimal 255)
www.roboindia.c
Phase 1 | Fundamentals of
Embedded C
Bit-Wise Operations in 8051-C
AND OR
EX-
Inverter
OR
A
X=~B
0
www.roboindia.c
Phase 1 | Fundamentals of
Embedded C
Bit-Wise Logic Operators in C
P0 = 0x35 & 0x0F; // ANDing, now P0=0x05
P1 = 0x04 | 0x68; // ORing, now P1=0x6C
www.roboindia.c
Phase 1 | Fundamentals of
Embedded C
Conditions and Loops
1. If Else
if ( conditions )
{ code to be executed }
2. For loop
for(start ; condition ; step)
{code to be executed}
3. While loop
while( Condition)
{ code to be executed }
www.roboindia.c
http://roboindia.com
[email protected]