data types and directives presentation 8051 c++ c
Post on 11-Jul-2016
239 Views
Preview:
DESCRIPTION
TRANSCRIPT
8051 DIRECTIVESDirectives are commands of assembly language itself and have no
influence on the operation of the microcontroller
DB directive • The DB directive is used for writing specified
value into program memory. If several values are specified, then they are separated by a comma. If ASCII array is specified, it should be enclosed within single quotation marks.• For example : CSEG DB 22,33,’Alarm’,44 If this
directive is preceded by a label, then the label will point to the first element of the array. It is the number 22 in this example.
EQU directive• The EQU directive is used to replace a number by a symbol. • Syntax: Name EQU Constant• For example:• MAXIMUM EQU 99 After using this directive, every appearance of the
label “MAXIMUM” in the program will be interpreted by the assembler as the number 99 (MAXIMUM = 99). Symbols may be defined this way only once in the program. The EQU directive is mostly used at the beginning of the program therefore.
SET directive • The SET directive is also used to replace a number by a
symbol. The significant difference compared to the EQU directive is that the SET directive can be used an unlimited number of times:• SPEED SET 45SPEED SET 46SPEED SET 57
BIT directive• The BIT directive is used to replace a bit address by a symbol. The bit
address must be in the range of 0 to 255 (00 H to FF H).• Syntax: Name BIT 8051 bit • For example:• TRANSMIT BIT PSW.7; Transmit bit (the seventh bit in PSW register); is
assigned the name “TRANSMIT”OUTPUT BIT 6 ;Bit at address 06 is assigned the name “OUTPUT”RELAY BIT 81 ;Bit at address 81 (Port 0)is assigned the name ;”RELAY”
CODE directive
• The CODE directive is used to assign a symbol to a program memory address. Since the maximum capacity of program memory is 64K, the address must be in the range of 0 to 65535(0000 H to FFFF H). • Syntax: Name CODE code address • For example:• RESET CODE 0 ;Memory location 00h called “RESET”TABLE
CODE 1024 ;Memory location 1024h called “TABLE”
DATA directive• The DATA directive is used to assign a symbol to an address within
internal RAM and SFR. The address must be in the range of 0 to 255 (00 H to FF H). It is possible to change or assign a new name to any register. • Syntax: Name DATA data address• For example:• TEMP12 DATA 32 ;Register at address 32 is named ;as
“TEMP12”STATUS_R DATA D0h ;PSW register is assigned the name ;”STATUS_R”
IDATA directive• The IDATA directive is used to change or assign a new name to an
indirectly addressed register. It is an address of entire internal RAM.• Syntax: Name IDATA idata address• For example:• TEMP22 IDATA 32 ;Register whose address is in register ;at address 32
is named as “TEMP22”TEMP33 IDATA T_ADR ;Register whose address is in ;register T_ADR is named as “TEMP33”
XDATA directive • The XDATA directive is used to assign a name to registers
within external (additional) RAM memory. The addresses of these registers cannot be larger than 65535 (0000 h to FFFF H). • Syntax: Name XDATA xdata address• For example:• TABLE_1 XDATA 2048 ;Register stored in external; memory at
address 2048 is named; as “TABLE_1”
ORG directive : Origin• The ORG directive is used to specify a location in program memory
where the program following directive is to be placed. • Syntax: ORG address• Address can be given in either in hex or decimal.• For example:• BEGINNING ORG 100 ... ...ORG 1000hTABLE ... ...This
program starts at location 100. The table containing data is to be stored at location 1024 (1000h).
USING directive • The USING directive is used to define which register bank (registers
R0-R7) is to be used in the program.• Syntax: USING Bank no.• USING 0 ;Bank 0 is used (registers R0-R7 at RAM-addresses 0-7)USING
1 ;Bank 1 is used (registers R0-R7 at RAM-addresses 8-15)USING 2 ,Bank 2 is used (registers R0-R7 at RAM-addresses 16-23)USING 3 ;Bank 3 is used (registers R0-R7 at RAM-addresses 24-31)
END directive : End of program• The END directive is used at the end of every program. The
assembler will stop compiling once the program encounters this directive. • Syntax: END• For example:• END ;End of program
8051 Data TypesData type can be defined as the type of data of variable or constant
store.
DATATYPE
PRIMARY DATATYPE DERIVED DATATYPE USER DEFINED TYPE
INTEGERCHARFLOATVOID
ARRAYPOINTER
STRUCTUREUNION
TYPEDEFENUM
INTEGER DATA TYPEIntegers are whole numbers with a machine dependent range of values. A good programming language as to support the programmer by giving a control on a range of numbers and storage space. C has 3 classes of integer storage namely short int, int and long int. All of these data types have signed and unsigned forms. A short int requires half the space than normal integer values. Unsigned numbers are always positive and consume all the bits for the magnitude of the number. The long and unsigned integers are used to declare a longer range of values.
CHARACTER DATA TYPE
• It can store any member of the C++ implementation's basic character set. If a character from this set is stored in a character variable, its value is equivalent to the integer code of that character. Character data type is often called as integer data type because the memory implementation of char data type is in terms of the number code.
FLOAT DATA TYPEA number having fractional part is a floating- point number. An identifier declared as float becomes a floating-point variable and can hold floating-point numbers. floating point variables represent real numbers. They have two advantages over integer data types:-1. they can represent values between integers.2. they can represent a much greater range of values.Disadvantage:3. their operations are usually slower.
DOUBLE DATA TYPE
The data type double is also used for handling floating-point numbers. But it is treated as a distinct data type because, it occupies twice as much memory as type float, and stores floating-point numbers with much larger range and precision. It is slower that type float.
VOID DATA TYPE
It specifies an empty set of values. It is used as the return type for functions that do not return a value. No object of type void may be declared. It is used when program or calculation does not require any value but the syntax needs it.
Keyword Format Specifier Size Data Range
char %c 1 Byte -128 to +127unsigned char %c 1 Bytes 0 to 255
int %d 2 Bytes -32768 to +32767
long int %ld 4 Bytes -231 to +231
unsigned int %u 2 Bytes 0 to 65535
float %f 4 Bytes -3.4e38 to +3.4e38
double %lf 8 Bytes -1.7e38 to +1.7e38
long double %Lf 10Bytes -3.4e38 to +3.4e38
User defined type declaration• C language supports a feature where user can define an identifier that
characterizes an existing data type.• This user defined data type identifier can later be used to declare
variables. • In short its purpose is to redefine the name of an existing data type.
Example Syntax:
• typedef <type> <identifier>;• typedef int marks;• marks batch1,batch2;
Enumeration(Enum)- user defined datatype• The identifier is a user defined enumerated datatype which helps to
declare variables that can have one of the value enclosed in braces.
• Syntax-
• enum identifier {value1,value2….valuen};
top related