DEVELOPMENT TOOLS
Having a programming language is usually not enough to develop a program for a microcontroller. Some way of debugging the program is needed.
Simulators
A simulator runs microcontroller program on a host machine (such as PC). One can step through the code to see exactly what is happening as the program runs. Contents of registers or variables can be altered to change the way the program runs. One can work out ideas or learn about microcontrollers by experimenting with small code fragments and watching 0n the screen what happens. A simulator can't support real interrupts or devices, and usually runs much slower than the real device the program is intended for.
Resident Dbuggers
A resident debugger runs program on the micro controller itself, while showing the progress on host machine (such as a PC). Has many of the same advantages as simulator, with the additional benefit of seeing how the program runs on the real target machine. A resident debugger needs to "steal" some resources from the target machine, including: a communications port to communicate with the host, an interrupt to handle single stepping, and a certain amount of memory for the resident part (on the target) of the debugger.
Emulators
An emulator is a device that can capture information and at the same time work as a
microprocessor. It provides full and total control over the target, while at the same time not requiring any resources from the target. The emulator can either be a stand alone device with its own display, or it can be interface to a PC.
ASSEMBLY LANGUAGE PROGRAMMING
Assembly language programs are written as a sequence of text lines. Each line of text is an instruction to the CPU, a directive to the assembler, or a combination of the two. The Complete syntax of a line of program code is as
|
label: |
instruction |
;comment(s) |
An Assembly Language Instruction Line
LABELS IN ASSEMBLY LANGUAGE
By choosing label names that are meaningful, a programmer can make a program readable and easier to maintain. There are several rules that names must follow.
-
First, each label name must be unique. The names used for labels in Assembly language programming consist of alphabetic letters in both upper and lower case, the digits 0 to 9, and the special characters question mark (?), period (.), at (@), underline (_), and dollar sign ($).
-
The first character of the label must be an alphabetic character. In other words it cannot be a number.
-
Every assembler has some reserved words which must not be used as labels in the program. Foremost among the reserved words are the mnemonics for the instructions. For example, "MOV" and "ADD" are reserved since they are instruction mnemonics. Aside from the mnemonics there are some other reserved words. Programmer should check assembler for the list of reserved words.
INSTRUCTIONS
Each instructions is generally made up of three distinct parts, as shown
|
Instruction Part |
1
mov (mnemonic) |
2 destination, (operands) |
3
source |
An 8051 Instruction
COMMENTS
Comments begin with a semicolon (;) to indicate that they are not one of the operands. Anything written after semicolon is a comment.
8051 DATA TYPE AND DIRECTIVES
Assembler program at concerns deal with such things as setting the PC contents, assigning names to numbers, and defining fixed numbers. The title given to an assembler program language instruction is a directive.
The 8051 microcontroller has only one data type. It is 8 bits, and the size of each register is also 8 bits. It is the job of the programmer to break down data larger than 8 bits (00 to FFH, or 0 to 255 in decimal) into byte sized datas so that it can be processed by the CPU.
DB (DEFINE BYTE)
The DB directive is the most widely used data directive in the -assembler. It is used to define the 8-bit data. When DB is used to define data, the numbers can be in decimal, binary, hex, or ASCII formats. For decimal, the "D" after the decimal number is optional, but using "B" (binary)
and "H" (hexadecimal) for the others is requisite. Regardless of which is used, the assembler will convert the numbers into hex. To indicate ASCII, simply place it in quotation marks (' '). The assembler will assign the ASCII code for the numbers or characters automatically. The DB directive is the only directive that can be used to define ASCII strings larger than two characters; therefore, it should be used for all ASCII data definitions.
NOTE: Either single or double quotes can be used around ASCII strings. This can be useful for strings, which contain a single quote such as "A'Singh". DB is also used to allocate memory in byte-sized chunks. .
ASSEMBLER DIRECTIVES
Most frequently used directives of the 8051 are as follows.
ORG (origin)/.ORG
The ORG/.ORG directive is used to indicate the beginning of the address. The number that comes after ORG can be either in hex or in decimal. If the number is not followed by H, it is decimal and the assembler will convert it to hex.
EQU (equate)
This is used to define a constant without occupying a memory location. The EQU directive does not set aside storage for a data item but associates a constant value with a data label so that when the label appears in the program, its constant value will be substituted for the label. The following uses EQU for the counter constant and then the constant is used to load the R3 register.
COUNT
EQU
100
.....
.....
MOV
R3, #COUNT
When executing the instruction "MOV R3, #COUNT", the register R3 will be loaded with the value 100 (notice the # sign). What is the advantage of using EQU? Assume that there is a constant (a fixed value) used in many different places in the program, and the programmer wants to change its value throughout. By the use of EQU, one can change it once and the assembler will change all of its occurrences, rather than search the entire program trying to find every occurrence.
It is good practice to use EQU directive in professional programming.
END/.END
Another important pseudo code is the END/. END directive. This indicates to the assembler the end of the source (asm) file. The END directive is the last line of an 8051 program, meaning that in the source code anything after the END directive is ignored by the assembler.
NOTE: Programmer should refer assembler before using assembler directives.
BACK
|