Published:2011/8/1 21:38:00 Author:Phyllis From:SeekIC
By Jim Spence
Assembly code
At some point in time more control or faster speed may be required than a high level language can give. There is no alternative but to resort to use assembler, which is the direct equivalent to programming the processor itself.
To do this effectively you will need an assembler. This is a program that translates 2 to 4 letter mnemonics into numbers that the processor can understand. There are many available free for this processor. In the examples shown "ASM51" has been used. It can be downloaded from various sources.
RAM would be required to run assembly code using the LOADH feature but none is available in this project. However, we have free code space in EEPROM starting at 1700h which is accessible through the in-circuit programming feature.
Getting Started
Always the hardest part? You can’t really program in assembler without knowing something about the processor and for this you will need at least a data sheet for the processor and some knowledge of the 8051 / 8052 instruction set but the following example will get you on your way.
Example program
We will keep on familiar ground by flashing the on board LED again. As you know, to do this we need to set PI .0 to zero and back to 1 again.
Example of flashing an LED
Use Asm51
Pl.O has the LED connected to it
$MOD8252
cseg
org 1700h
flash: ; pulse Pl.O up and down
setb pl.O
call delay
clr pl.O
call delay
jmp flash
delay: ; delay
mov r0,§0f0h
del2: mov rl,#0
dell: nop
djnz rl,dell
djnz
ret r0,del2
end
The operation of the program is conveniently explained by means of a table.
Assembling
Use Notepad or any text editor to create the above program, save it with an ’asm’ extension, for example FlashLed.asm. Now that the program is written it needs converting to a format that the processor can understand. To do this you will need to use the command prompt if you are using the Windows operating system. If you are using DOS then you are already there.
Choose a directory to put the files in, you should have FlashLed.asm, Asm51 and MOD8252 in the same directory (unless you know how to set paths up). At the prompt type "asm51 FlashLed". On pressing enter you should see something similar to that of Figure A. Note that Asm51or indeed any other 8051 assembler has to be obtained separately, it is not included with the software for this project.
This process produces two files using the same file name but with different extensions thus: FlosLed.hex and FlosLed.lst. The LST file is where you will find any errors if there are any and the HEX file is a special format developed by Intel to enable code to be loaded into processors. As a matter of interest the format consists of lines of text preceded by a colon.
: 10170000D29012170CC29012170C80F478F0790066
The first two numbers ’10’ is the length of the code in hex, the next 4 numbers is the memory address, in our case 1700 this is followed by a record type which is almost always 00. The rest of the line consisted of the actual code to be loaded at the given memory address except for the last two numbers, ’66’ which is a checksum to verify that the line has been received correctly.
Load Up
The next job is to load this program into code space. This is where the special features come in. Click on the "101" icon and the background will turn black. We are now in flash programming mode. Press ’p’ and the text will turn yellow, this indicates that we will be using Program or Code space (the flash memory area). Typing "v" "88 <enter>" and then "99<enter>" will enable you to view the contents of the code memory from memory address 0088 to 0099. This is v/here the sign-on message of TCB is located. All numbers are in hexadecimal format, see Figure B.
To program this area with our assemble program type "h" This will pop a dialog ox that will allow you to select the FlashLed.hex file. This will be loaded into the memory and you should get something like Figure C. Programming will now commence automatically (and it does take some time to complete).
Running the program
First of all get back into terminal mode by pressing ’x’ or the ’101’ icon. To run this program TCB has provided CALL. The syntax is CALL n where n is the address you want to jump to. The address we chose to put the program at was 1700h, TCB works by default in decimal, to change this type HEX. Another word of caution, everything is in hex from now on until you reset or type DECIMAL. This applies to normal basic program, hex line numbers look very strange.
Type the following to run the program:
HEX
CALL 1700
If you don’t want to use HEX then CALL 5888 works just as well, 5888 is the decimal equivalent of 1700h.
The LED should now flash indicating that you are running the assembler program. Note because this is such a simple program, the only way to stop it is to press reset. Do this at the terminal using the icon next to "101" or using the push button on the main board. Once in flash memory, the program will remain after power is removed. Because of the slow serial programming nature it is not really suitable for large files. Although this can be done, expect TCB to take about 25 minutes for the basic.hex file. Some things simply can’t be done using TCB alone, this feature makes the project completely versatile.
You can quite happily use a mixture of TCB and assembler. You can for example assemble the code at address 1700 and use a simple 2 line basic program:
10 HEX
20 CALL 1700
This will start flashing the LED whenever there is power applied to the board. Okay so a flashing LED has its limitations but we’re sure you get the idea.
Reprinted Url Of This Article: http://www.seekic.com/blog/project_solutions/2011/08/01/Swiss_Army__(6).html
Print this Page | Comments | Reading(371)
Author:Ecco Reading(32821)
Author:Ecco Reading(3526)
Author:Ecco Reading(3246)
Author:Ecco Reading(3801)
Author:Ecco Reading(5331)
Author:Ecco Reading(3315)
Author:Ecco Reading(3462)
Author:Ecco Reading(3604)
Author:Ecco Reading(4009)
Author:Ecco Reading(3807)
Author:Ecco Reading(3748)
Author:Ecco Reading(3780)
Author:Ecco Reading(6094)
Author:Ecco Reading(3764)
Author:Ecco Reading(4579)