Académique Documents
Professionnel Documents
Culture Documents
Most PIC18 devices will provide FLASH program memory in sizes from 8 to 128 Kbytes and data RAM from 256 to 4 Kbytes; operating from 2.0 to 5.5 volts, at speeds from DC to 48 MHz.
Optimized for high-level languages like ANSI C, the PIC18 family offers a highly flexible solution for complex embedded applications.
Because it clearly outlines the requirements of the system, an architecture can act as a solid basis for analyzing and testing the quality of a device and its performance under various circumstances.
The various structures of an architecture can then be leveraged for designing future products with similar characteristics, thus allowing design knowledge to be reused, and leading to a decrease of future design and development costs.
Defining and understanding the architecture of an embedded system is an essential component of good system design
Every embedded system has an architecture. An architecture by definition is a set of representations of those elements and their relationships. before starting development, take control of the design by defining the architecture first.
Embedded architecture is a useful tool in understanding all of the major elements, why each component is there, and why the elements behave the way they do.
Even if the architectural structures are rough and informal, it is still better than nothing. As long as the architecture conveys in some way the critical components of a design and their relationships to each other, it can provide project members with key information about whether the device can meet its requirements, and how such a system can be constructed successfully.
Program Counter
a) WREG register
In the CPU, registers are used to store information temporarily. That information could be a byte of data to be processed, or an address pointing to the data to be fetched. The vast majority of PIC registers are 8-bit registers.
In the PIC there is only one data type: 8-bit. The range goes from the MSB (most significant bit) D7 to the LSB leastsignificant bit) D0. With an 8-bit data type, any data larger than 8 bits must be broken into 8-bit chunks before it is processed.
The 8-bit WREG register is the most widely used register in the PIC micro controller. WREG stands for working register, as there is only one. The WREG register is the same as the accumulator in other microprocessors. The WREG register is used for all arithmetic and logic instructions.
To understand the use of the WREG register, we will show it in the context of two simple instructions: MOVE and ADD.
MOVLW Instruction
The MOVLW instruction moves 8-bit data into the WREG register. It has the following format: MOVLW K ;move literal value K into WREG
K is an 8-bit value that can range from 0-255 in decimal, or 00FF in hex. The L stands for literal, which means, literally, a number must be used. In other words, if we see the word literal in any instruction, we are dealing with an actual value that must be provided right there with the instruction.
Notice that in MOVLW, the letter L (literal) comes first and then the letter W (WREG), which means "move a literal value to WREG, " the destination. The following instruction loads the WREG register with a literal value of 25H (i.e., 25 in hex).
MOVLW 25H
ADDLW Instruction
The ADDLW instruction has the following format: ADDLW K ; ADD literal value K to WREG
The ADD instruction tells the CPU to add the literal value K to register WREG and put the result back in the WREG register. Notice that in ADDLW, first comes the letter L (literal) and then the letter W (WREG), which means "add a literal value to WREG," the destination.
To add two numbers such as 25H and 34H, one can do the following: MOVLW 25H ADDLW 34H ; load 25H into WREG ; add value 34 to W (W = W + 34H)
Executing the above lines results in WREG = 59H (25H + 34H = 59H)
When programming the WREG register of the PIC microcontroller with a literal value, the following points should be noted:
Values can be loaded directly into the WREG register. There is no need for a preceding pound sign or dollar sign to indicate that a value is an immediate value as is the case with some other microcontrollers. If values 0 to F are moved into an 8-bit register such as WREG, the rest of the bits are assumed to be all zeros. For example, in "MOVLW 5H" the result will be WREG = 05H; that is, WREG = 00000101 in binary.
Moving a value larger than 255 (FF in hex) into the WREG register will truncate the upper byte and cause a warning in the .err file.
The PIC SFRs are 8-bit registers. The number of locations in the file register set aside for SFR depends on the pin numbers and peripheral functions supported by that chip.
Note that there are two RAM columns in the chip information section of the Microchip web site. One refers to the generalpurpose registers' (GP RAM) size, and the other is the EEPROM size.
GP RAM (which constitutes most of the file register) must not be confused with the EEPROM data memory. The GPRs are used by the CPU for internal data storage, whereas the EEPROMs are considered as an add-on memory that one can also add externally to the chip.
The 256-byte access bank is divided into two equal sections of 128 bytes. These 128-byte sections are given to the generalpurpose registers and special function registers.
The 128 bytes from locations OOH to 7FH are set aside for general-purpose registers and are used for read/write storage, or what is normally called a scratch pad. These 128 locations of RAM are widely used for storing data and parameters by PIC 18 programmers and C compilers. Each location of this 128-byte RAM of general-purpose registers can be accessed directly by its address. The other 128 bytes of the access bank is used for SFRs. It has addresses of F80H to FFFH.
The PIC allows direct access to other locations in the file register for ALU and other operations. In this section we show the instructions using various locations of the file register. This is one of the most important sections in the book for mastering the topic of PIC Assembly language programming.
MOVWF instruction
the F stands for a location in the file register, while W means WREG The MOVWF instruction tells the CPU to move (in reality, copy) the source register of WREG to a destination in the file register (F).
After this instruction is executed, the location in the file register will have the same value as register WREG The location in the file register can be one of the SFRs or a location in the general purpose registers region.
;WREG ~ 55H ;copy WREG to Port B (Port B 55H) ;copy WREG to Port C (Port B 55H) ;copy WREG to Port D (Port B 55H)
c)Status Register
To indicate arithmetic conditions It is a 8-bit register
The OV and N flag bits are used for the signed number arithmetic operations
Hex numbers
There are four ways to show hex numbers: We can use h (or H) right after the number like this: MOVLW 99H Put Ox (or OX) in front of the number like this: MOVLW Ox99 Put nothing in front or back of the number like this: MOVLW 99
Put h in front of the number, but with single quotes around the number like this: MOVLW h' 99'
Binary numbers
MOVLW B'10011001' ;WREG = 10011001 or 99 in hex
Decimal numbers
MOVLW D'12' ;WREG = 00001100 or OC in hex MOVLW .12 ;WREG = 00001100 = OCH = 12
ASCII character
MOVLW A'2' ;WREG = 00110010 or 32 in hex MOVLW A9 ;WREG = 39H, which is hex number for ASCII '9' ADDLW A'l' ;WREG = 39H + 31H = 70H ; (31 hex is for ASCII '1')
Assembler directives
Directives (also called pseudo instructions) give directions to the assembler. For example, the MOVLW and ADDLW instructions are commands to the CPU, but EQU, ORG, and END are directives to the assembler.
EQU (equate)
This is used to define a constant value or a fixed address. The EQU directive does not set aside storage for a data item, but associates a constant number with a data or an address label so that when the label appears in the program, its constant will be substituted for the label. COUNT EQU Ox25; MOVLW COUNT ;WREG = 25H
SET
This directive is used to define a constant value or a fixed address. In this regard, the SET and EQU directives are identical. The only difference is the value assigned by the SET directive may be reassigned later.
ORG (origin)
The ORG directive is used to indicate the beginning of the address. It can be used for both code and data. The number that comes after ORG must be in hex.
END directive
Another important pseudocode is the END directive. This indicates to the assembler the end of he source (asm) file. The END directive is the last line of the IC program, meaning that anything after the END directive in the source code is ignored by the assembler.
LIST directive
Unlike ORG and END, which are used by all assemblers, the LIST directive is unique to the PIC assembler. It indicates to the assembler the specific PIC chip for which the program should be assembled. It is used as follows:
LIST P=18F458
The above tells the PIC assembler to assemble the program specifically for the PIC 18F458 microcontroller. We use LIST to state the target chip.
#include directive
The #include directive tells the PIC assembler to use the libraries associated with the specific chip for which we are compiling the program.
_config directive
The _ config directive tells the assembler the configuration bits for the targeted PIC chip.
radix directive
We can use the radix directive to indicate whether the numbering system is hexadecimal or decimal. The default is hex if we do not use the radix directive. If we use "radix dec", the default representation will change to decimal and any unformatted number will be interpreted as decimal rather than hex.