Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

The above is called a register file map for the PIC16F877A.

First thing you will notice is that it is split into


four banks - Bank 0, Bank 1, Bank 2, and Bank 3. Bank 1 is used to control the actual operation of the
PIC, for example to tell the PIC which bits of Port A are input and which are output. Bank 0 is used to
manipulate the data. An example is as follows: Let us say we want to make one bit on Port A output.
First we need to go to Bank 1 to set the particular bit, or pin, on Port A as an output. We then come back
to Bank 0 and send a input 1 to that pin. In the case of this circuit we are at first setting all the pins of
Port A as input ports; then we set all the pins of Port B as output ports.

The registers we used in Bank 1 are STATUS, TRISA and TRISB. The first allows us to come back to Bank 0,
TRISA allows us to select which pins on Port A are output and which are input, TRISB allows us to select
which pins on Port B are output and which are input.

The registers we used in Bank 0 are PORTA and PORTB for the actual code of the program that executes
a function, in this case an add function.

Additionally used is the Work Registry, this is where data can temporarily be stored to be called upon
and also the information can be replaced.
The first step in the coding process is to first include the command list that is specific to the
microcontroller you are using to be loaded into the microcontroller. Then you need to add the
configuration bits: are a collection of special bits that can only be modified at program time.
Configuration bits are "read" during reset and enable or disable hardware features in the
microcontroller. The features controlled by the configuration bits include, but not limited to, the clock
source, WatchDog timer, brownout detect and Memory Read protection. Configuration bits are not
executable code they are essentially fuses located in the program memory space. For this circuit all the
other configurations are turned off and only the oscillator was set to HS (high speed) due to the 20MHz
used in the circuit built.

Additionally defined is the number system that will be used in the code, in this case hexadecimal was
used. The same code can also be done in binary and this line removed.

ORG command places the assembler in Bank 0 and places all the values as their default.

The BSF Means Bit Set F. The letter F means that we are going to use a memory location, or register. We
are using a registry address and a number after this instruction –STATUS register address, and the
number 5 which corresponds to the bit number. So, what we are saying is “Set bit 5 in address STAUTS
to 1”. Similarly BCF means Bit Clear F, however, this time it is referencing bit 6. The purpose of this
command is to clear the bit which will change it to a value of 0.
From the data set we can see that the bits we are referring to are located on RP1 and RP0, therefore
changing it from its previous value to 01 which indicates that you are not moving from Bank 0 to bank 1.

Now that we are located in Bank 1 we will move the value “0x06” to the work registry to be stored. In
binary this is 0000 0110.

Then we will move the work registry stored value to the function ADCON1. This will configure PORTA to
digital as we can see from the datasheet the values 0000 0110 turn the bits 1 and 2 to 1 and this
configures all of them as digital. For this program only the bits from 0 to 3 are affected.
This command moves a value “0xff” which is hexadecimal, or 1111 1111 binary, to the Work Registry to
be stored for recall later.

Now the previously stored value in the Work Registry is then moved to TRISA which configures the
PORTA to have a value of 1 which signifies Input.

PORTB is then configured similarly but as output ports.

The assembler is the returned to Bank 0 by clearing the value located in bit 5. Additionally the values of
PORTA and PORTB are cleared in preparation to run the actual addition program.

Inicio begins the program that you will want to execute. MOVF then moves the value that is read from
the inputs of PORTA to the Work Register.
This line of code adds the value specified “2” to the value currently stored in the Work Registry which is
affected the 4 switches being input at PORTA on the physical circuit.
The value then located in the Work Registry is moved to PORTB which are the output ports that either
turn on or off the LED lights on the physical circuit.

After the addition the goto function restarts the process and the END is required as a part of the
program code that indicates that the program is finished.

You might also like