PIC16F877A Microcontroller Programming Guide
PIC16F877A Microcontroller Programming Guide
RESEARCH
PRACTICE 3
SUBJECT:
Microcontrollers
TEAM:
Guerrero Alberto Lizeth #20210789
Hidalgo Escobar Sabina Monserrat #20210793
Sotero Sanchez German #19212437
-Verduzco Acosta Kimberly Janeth #20210838
TEACHER:
M.C Angel Humberto Corral Dominguez
14-10-2022
INDEX
I. OBJECTIVE 2
II. THEORETICAL FRAMEWORK 3
2.1 Programming in the PIC16F877A 6
Edit 6
Compile 6
Burn the PIC 6
Test the program 7
III. DEVELOPMENT 8
3. 1 Code in MPLAB 8
IV. RESULTADOS 11
V
CCONCLUSIONS
. 17
Guerrero Alberto Lizeth 17
Hidalgo Escobar Sabina Monserrat 17
Sotero Sanchez German 18
Verduzco Acosta Kimberly Janeth 18
REFERENCES 20
1
I. OBJECTIVE
2
II. THEORETICAL FRAMEWORK
The PIC16F877A is one of the most popular PIC microcontrollers from the company.
Microchip. It has a little more memory and input/output pins than the
basic range microcontrollers (such as the PIC16F84A). It has a RISC type CPU.
(Reduced Instruction Set) that only has 35 instructions.
different, which makes it very easy to program both in assembly language and in
And it is therefore ideal for teaching.
Figure 2.1PIC16F877A
3
● Synchronous Serial Port with SPI and I²C
● Eight-channel, 10-bit analog-to-digital converter
● Universal Synchronous Asynchronous Receiver Transmitter (USART)
Special features of the microcontroller
● Ignition reset
● Power-on timer (PWRT) and startup timer of
oscillator (OST)
● 1000 erase/write cycles Enhanced flash memory
● 1,000,000 typical erase/write cycles EEPROM data memory
● Selectable oscillator options
CMOS technology
● Low power high speed CMOS FLASH technology
● Completely static design
4
● Low energy consumption
I/O and packets
● 33 I/O pins with individual direction control
● 40-pin DIP
5
31 Vss - Earth
32 Vdd - Positive power supply
33 RB0/INT - Port B
34 RB1 - Puerto B
35 RB2 - Puerto B
36 RB3/PGM - Puerto B
37 RB4 - Puerto B
38 RB5 - Puerto B
39 RB6/PGC - Puerto B
40 RB7/PGD - Puerto B
Table 2.1Description of pins.
[Link]
Compiling is translating the program into machine [Link] the
PIC. To carry out this translation, we use software that transforms the
Source Program”, awhatever we edit in step 1 into another that we can.
inform the PIC.
6
as long as we understand that this device is not going to think for us and that it is
7
III. DEVELOPMENT
In order to create this practice in person, the following materials were needed and
programs:
★ 2 protoboards.
★ 2 capacitors of 33 pF.
★ 2 resistors of 330 Ω.
★ 16 resistors of 220Ω.
★ 1 quartz crystal 4MHz.
★ 1 PIC16F877A.
★ 1 push button.
★ 8 LEDs.
★ 22 AWG wire.
★ Programs: MPLAB and Master Prog.
3. 1 Code in MPLAB
Here the options available for the PIC are configured as shown in the
first line of code from figure 3.1, for this program we only use one variable
with the name "V" at address 0X00.
8
Figure 3.2Main section of the program.
In figure 3.2 we can observe that the program is divided into 2 labels, the
etiqueta “Inicio” e “Incremento”, eIn the Home section, you can access and modify the
different banks of the PIC, the input and output ports are configured, in this case
Our entry ports are port C, while the exit is port B.
In the Increment section, we see that what comes in through port C is loaded into the
register W to later load into our variable V and increment it by 1
value to later load this result back to W and finally to our outputs
the port B, finally we have the SLEEP and GOTO instructions that are responsible for only
show the result when the button is pressed and make the program into a loop
respectively.
After having all the code, we check that it compiles correctly for
to proceed with the program test.
9
Figure 3.3Simulated circuit.
10
IV. RESULTADOS
11
Figure 4.2Circuit connected to the voltage source.
12
Figure 4.3LED at position 1 on, with an input value of 0.
In figure 4.4 it can be seen how the 2nd LED lights up when the input indicates
value of 1, in this case, 1 is entered in the dip switch and the addition action is performedr,
1+1=2, therefore the LED in the 2nd position lights up.
13
Therefore, in figure 4.5, it is observed how the 4th red LED is
it lights up when the input shows a value of 7, therefore the addition action is performedr,
7+1=8, therefore the LED in position 4 turns on.
Figure 4.6LEDs lit except for position 2, with an input value of 252.
14
Another example can be observed in figure 4.7, it is entered at the dip input.
switch the value of 5, therefore the action of addition is performedr, 5+1=6, therefore the
LEDs in positions 2 and 3 are lit.
Finally, in figure 4.8, the value of 4 is entered at the dip switch input,
thus the action of the addition is doner, 4+1=5, therefore the LEDs in position 1 and 3
they turn on.
15
These are some examples of how the circuit works, since it arrives
An 8-bit input tends to create many combinations, a maximum of 256 (the
the last combination contains a carry, so if the entire dip switch is marked with
pure 1, this does not turn on any LEDs). To verify that the practice is with
the correct functioning, 15 tests were conducted where the teacher was
supervising the operation of each number that could be enteredr.
To finalizer, sIt can be concluded that the operation of the code (figure 4.9) in the
PIC is correct since when assembling the circuit and connecting it to a power source, it is
it works correctly. By entering any number (1, 2, 5, into the dip switch
10, etc) this allows you to add 1 to any valuer, por therefore it meets the objective of
the practice, to make a consecutive adder and handle the I/O correctly so that
function correctly.
16
V
CCONCLUSIONS
.
What I could understand the most in this practice was the use of records; where
define the register as a space in the data memory of the microcontroller
where we can store information (general purpose) and where there are
also some registers in which we can configure the microcontroller or
to know the status of this, as well as some of its specific peripherals.
Through an observation provided by the teacher, we understood a little.
more about them and why it is important to know and differentiate the
function of RFS (special function registers) and RGP (registers of)
general purpose), where poor implementation of them can affect
to the PIC.
It also learned to manage the input and output ports of the PIC to
carry out the summation to 1 each time a switch on our dip is activated
8-bit switch, showing the result of the input plus the
addedr. Lthe exits and entries can be scheduled according to the way in
that we indicate, as long as the RFS and RG are respectedP.
Where the function of this code is based on performing the reading ofa value
8-bit binary through one of the I/O ports of the PIC, this part is determined by
17
the team, while it should be provided by dip switch in this case of
8 entries since it is the value of bits to enter. The entered value is
it will increase by 1, the resulting data will be output through another port where it will be displayed
in 8 LEDs connected to 8 resistors each and in the same way it connects to the
dip switch.
In order to carry out the practice, the first thing that was done was to write the code in
18
file that can be transferred to the programmer and then to the PIC. This part
it can become a bit complex, as the code has to be sent continuously
between programs and finally save it. Once the code is saved in the PIC,
the circuit assembly begins on the protoboard (the circuit is composed of
for the PIC16F877A, quartz crystal, capacitors, resistors, switch, and LEDs)
remembering that the purpose of the circuit is to create a summer according to the
Entered values can confirm that depending on the value of the dip switch
the output value will be reflected in the LEDs; in this case, if the input is
The value of 1 on the dip switch is observed at the output that turns on the LED in the position.
19
REFERENCES
20