The document outlines various data types and their sizes in programming, including char, int, float, and special types like sbit and bit. It also covers constants, arithmetic, relational, and logical operators, as well as memory types such as program memory, external data memory, and special function registers (SFRs) in the 8051 microcontroller. Additionally, it provides exercise programs for developing 8051 C code to manipulate data and control peripherals.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
3 views17 pages
8051 Ppt-Module
The document outlines various data types and their sizes in programming, including char, int, float, and special types like sbit and bit. It also covers constants, arithmetic, relational, and logical operators, as well as memory types such as program memory, external data memory, and special function registers (SFRs) in the 8051 microcontroller. Additionally, it provides exercise programs for developing 8051 C code to manipulate data and control peripherals.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 17
Data-types & Sizes
• Char – a single byte, used to store one
character. • Int – an integer, typically reflecting the natural size ( 2 or 4 bytes) of integers on the host machine. • Float – single precision floating point (4 bytes). • Double – double-precision floating point (8 bytes). • Short int – always 2 bytes. • Long int – always 4 bytes. Data-types & Sizes • The qualifier signed or unsigned can be used for char or any integer. • Unsigned numbers are always +ve or zero & obey the laws of arithmetic modulo 2n. • Signed numbers have the range -2n-1 to (+2n-1 – 1). • The type long double specifies extended precision floating point. Constants • A leading 0 (zero) on an integer constant means octal, a leading 0x or 0X means hexadecimal.
• A character constant is an integer written as one character
within single quotes (eg: ‘x’). – The value of a character constant is the numeric value of the character in the machine’s character set. Eg: In ASCII character set, ‘0’ has the value 0x30.
• A string constant or string literal is a sequence of zero or
more characters surrounded by double quotes. Eg: “I am a string”
• The internal representation of a string has a null character (‘\
0’) at the end, so the physical storage required is one more than the number of characters written between the quotes. Arithmetic Operators • The binary arithmetic operators are: +, -, *, / and the modulus operator %. • Integer division truncates any fractional part. • The expression x % y produces the remainder when x is divided by y. • The % operator cannot be applied to float or double. • The direction of truncation for / and the sign of the result for % are machine dependent for negative operands, as is the action taken on overflow & underflow. Relational & Logical Operators • The relational operators are: >, >=, <, <=, ==, and !=. • Relational operators have lower precedence than arithmetic operators so an expression like I < lim -1 is taken as I < (lim – 1). • The logical operators are: && (logical and) and || (logical or). • Expressions connected by && or || are evaluated left to right, and evaluation stops as soon as the falsehood or truth of the result is known respectively. • By definition the numeric value of a relational or logical expression is 1 if the relation is true & 0 if the relation is false. • The unary negation operator (!) converts a non zero operand into 0 & a zero operand into 1. A common use of ! is in constructions like: • if (!valid) rather than if(valid==0) sbit Data Type • It is often necessary to access individual bits within an SFR, the Cx51 Compiler makes this possible with the sbit data type which provides access to bit-addressable SFRs and other bit-addressable objects.
Ex: sbit LED = P0^0;
• Note: – Not all SFRs are bit-addressable.
– Only those SFRs whose address is evenly divisible by 8 are bit-
addressable.
– sbit variables may not be declared inside a function. They must
be declared outside of the function body. Bit Types • he Cx51 Compiler provides a bit data type that may be used for variable declarations, argument lists, and function-return values.
• A bit variable is declared like other C data types.
• All bit variables are stored in a bit segment located in
the internal memory area of the 8051. – Because this area is only 16 bytes long, a maximum of 128 bit variables may be declared within any one scope. Bit Types • Restrictions: – A bit cannot be declared as a pointer
– An array of type bit is invalid.
– Functions that disable interrupts and functions
that are declared using an explicit register bank (using n) cannot return a bit value. Program Memory • Program code, including all functions, library routines and constant variables, is stored in program memory. • The 8051 executes programs stored in program memory only. • Program (CODE) memory is read only. • Program memory may reside – within the 8051 CPU – externally – in both, depending upon the 8051 derivative and the hardware design. • There may be up to 64K Bytes of program memory. • Program memory may be accessed using the code memory type specifier in the Cx51 Compiler. External Data Memory • External data memory is read/write. – indirectly accessed through a data pointer register – slower than access to internal data memory. • There may be up to 64K Bytes of external data memory; though, this address space does not necessarily have to be used as memory. • The C51 Compiler offers two memory types that access external data: xdata and pdata. SFR Memory • The 8051 provides 128 bytes of memory for Special Function Registers (SFRs).
• SFRs are bit, byte, or word-sized registers that
are used to control timers, counters, serial I/O, port I/O, and peripherals. Special Function Registers • The 8051 family of microcontrollers provides a distinct memory area for accessing Special Function Registers (SFRs).
• SFRs are used in your program to control timers,
counters, serial I/Os, port I/Os, and peripherals.
• SFRs reside from address 0x80 to 0xFF and can be
accessed as bits, bytes, and words.
• Within the 8051 family, the number and type of SFRs
vary. Note that no SFR names are predefined by the Cx51 Compiler. However, declarations for SFRs are provided in include files (Ex: reg52.h). Header Files • Header files or include files are included and processed by the pre-processor.
• They provide you with a convenient way to
publish global variables, function prototypes, manifest constants, and macro definitions that are used throughout a large development effort. Exercise Programs 1. Develop an 8051 C code to send data 48 H to P0,P1,P2 and P3 continuously. 2. Develop an 8051 C code to send data 00 H and FF H alternatively to P0,P1,P2 and P3 continuously. 3. Develop an 8051 C code to send single bit ‘0’ and ‘1’ to P0.0 continuously. 4. Develop an 8051 C code to send data 48 H serially to P0.0 continuously. Exercise Programs 5. A switch is connected to P0.0 and one LED is connected to P0.1. Develop a code to read the status of switch and display it on LED.
6. 8 keys are connected to P0 and display is
connected to P1, Develop a code to read the keys and send status to display.