South Manchester Radio Club 010101 PIC Tutorial 1010101 |
...... |
SYMBOLIC CONSTANTSIn this lesson we will amend our first program to make it more readable and understandable Lets have a look at what we have:- org
0 ; Start at location 0 As you can imagine trying to keep a track of all those numbers for the File Registers gets a bit tedious. The comments help, but when you are coding a new program, it would be hard to remember if 03h (thats 03 Hex) is the STATUS register or the PORTD register. Fortunately the Assembler gives us a way to replace these with the names of the registers. These are often called "Symbolic Constants" or "Symbols" for short. How does this work? Well first we use the "EQU" (EQUate) directive to define the symbol. e.g. STATUS EQU 03h ; Symbol for the STATUS Register Then whenever we want to refer to the STATUS register we can just use the word "STATUS" in the program. We can do the same for TRISD and PORTD. So our program now looks like this:- ; ; define some constants ; STATUS EQU 03H ; Define a symbol for the status register TRISD EQU 08H ; Define a symbol for the status register PORTD EQU 08H ; Define a symbol for the status register ; ; Now the code starts here ; org
0 ; Start at location 0 The code generated by the assembler is exactly the same, but the program is now more readable. Include FilesTo make things even easier, MicroChip provide a file of EQU's for each chip type. We use the "#include" directive to load a file of "EQU" statements into our program. So for the 44-pin board with the 16F877 chip we can do:- ; ; define some constants ; #include "p16f677.inc" ; ; Now the code starts here ; org
0 ; Start at location 0 Notes:-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Daves Sample Program ; Written 01-April-2009 ; ; Author:- Dave Wade G4UGM ; ; Version History: ; 1.0 Initial version for course ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Quick Quiz1. Which of these statements is FALSE? 2. Which of these statements is true 3. Which of these statements is true |
South Manchester Radio & Computer Club PIC Tutorial If you need support and help visit the SMRCC PIC Support Group on Yahoo For more information about SMRCC visit the main web site or e-mail "chairman <at> smrcc.org.uk"
|