04 8051 Programming in C - 2018
04 8051 Programming in C - 2018
04 8051 Programming in C - 2018
Programming in
C
Introduction
• The C-compiler uses internal data RAM area to store
variables declared in program.
• The most general allocation of data RAM is as below
– Register Bank 0 – Addresses 00 to 07.
– Individual Variables – Address 08 and beyond.
– Array elements – Addresses right after the variables.
– Stack – Addresses right after the variables.
• The above allocation may change depending on the compiler.
• Advantage of using C is easy development, easy debugging of
application software and portability with little or no
modification.
• The hex code generated by the C-compilers are usually much
larger than the code obtained through assembly language
program.
8051 Programming in C – Manish Tiwari 2
Data Types
• Since limited amount of data RAM (128B) and Code space
(4KB) is available, efficient use of data types for variables
are essential.
• Following are the most common & preferred data types
– unsigned char – An 8-bit variable declaration in data RAM. Same
as using an 8-bit register or 8-bit memory location in 8051.
– bit – A single bit variable declaration in data RAM within the bit
addressable area (address 20H to 2FH).
– sbit – A single bit of bit addressable SFR may be defined.
– Use of int/long int etc are seldom observed. Even though they
may be used any time in program, but takes larger RAM area and
processing time. Hence these variables are used only and only
when our program must deal with the larger data length.
Equivalent ASCII
0 0 1 1 0 1 0 1
3 6
0 0 1 1 0 1 0 1
3 5