0% found this document useful (0 votes)
9 views21 pages

PIC16F877A Microcontroller Programming Guide

This document presents the development of a program in assembly language for the PIC16F877A microcontroller. The objective of the program is to activate the input and output ports of the PIC to display the result of adding a binary input value through a dip switch and a 1 adder. The document describes the hardware and software used, including MPLAB for writing the code in assembly, and the results obtained when testing the program on the PIC.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views21 pages

PIC16F877A Microcontroller Programming Guide

This document presents the development of a program in assembly language for the PIC16F877A microcontroller. The objective of the program is to activate the input and output ports of the PIC to display the result of adding a binary input value through a dip switch and a 1 adder. The document describes the hardware and software used, including MPLAB for writing the code in assembly, and the results obtained when testing the program on the PIC.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

TIJUANA TECHNOLOGICAL INSTITUTE

COMMITTEE OF ELECTRONIC AND BIOMEDICAL ENGINEERING

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

Create a program in assembly language for the microcontroller


PIC16F877A, where the I/O ports of it are activated. Likewise, through
from a dip switch propose binary values and once registered, a sum of 1 is made and
it can show in the output the result of the input plus the sumr.

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

High-performance RISC CPU


● Only 35 instructions of a single word to learn
● All instructions are of a single cycle (1 µs) except for the branches.
of the program
● Operating speed: DC - 20 MHz clock input
● 8 kBytes flash program memory
● 368 bytes RAM data memory
● EEPROM data memory of 256 bytes
● Serial programming in circuit
● Interruption capacity (up to 10 sources)
Peripheral functions
● Two 8-bit timers/counters (TMR0, TMR2) with prescaler
8-bit programmable
● A 16-bit timer/counter (TMR1)
● High current source/sink for direct LED drive
● Watchdog Timer (WDT) with separate RC oscillator
● Two modules for capture, comparison and PWM

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

Figure 2.2Pin design.

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

Pin number Description

1 MCLR/VPP - Master clear input


2 RA0/AN0 - Port A
3 RA1/AN1 - Puerto A
4 RA2/AN2/VREF-/CVREF - Port A
5 RA3/AN3/VREF+ - Port A
6 RA4/T0CKI/C1OUT - Port A
7 RA5/AN4/SS/C2OUT - Port A
8 RE0/RD/AN5 - Puerto E
9 RE1/WR/AN6 - Puerto E
10 RE2/CS/AN7 - Port E
11 Vdd - Positive power supply
12 Vss - Earth
13 OSC1/CLKI - Oscillator input
14 OSC2/CLKO - Oscillator output
15 RC0/T1OSO/T1CKI - Puerto C
16 RC1/T1OSI/CCP2 - Port C
17 RC2/CCP1 - Puerto C
18 RC3/SCK/SCL - Port C
19 RD0/PSP0 - Port D
20 RD1/PSP1 - Puerto D
21 RD2/PSP2 - Port D
22 RD3/PSP3 - Port D
23 RC4/SDI/SDA - Puerto C
24 RC5/SDO - Port C
25 RC6/TX/CK - Port C
26 RC7/RX/DT - Port C
27 RD4/PSP4 - Port D
28 RD5/PSP5 - Puerto D
29 RD6/PSP6 - Puerto D
30 RD7/PSP7 - Puerto D

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.

2.1 Programming in the PIC16F877A

The programming of a PIC can be divided into four steps:


1. Edit
Editing is writing the program, it is making a list of instructions in a language
that allows us to indicate to the PIC what we want it to do. There are several
languages such as: Assemblyr, BASIC, C, etc. All of them aim to approach
our way of thinking and speakingr. Showever, the PIC only know about
ones and zeros. That is why the next step is necessary.

[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.

[Link] the PIC


In this step, the program is recorded in the PIC. Using an electronic card and
a little software transfers the compiled program from the PC to the PIC. They are

Just a few clicks and you're done. It is necessary to clarify this.


moment. We often refer to the PIC programmer as the card
electronics that transfers the compiled program from the PC to the PIC. It's fine

6
as long as we understand that this device is not going to think for us and that it is

unable to program instructions by itself.

[Link] the program


Well, in this step it is about verifying the operation of the program. It is about
to check that the PIC behaves as we programmed it. If everything went well,
it is no longer necessary to edit the PIC again, we can use a Protoboard,
wire the LEDs or buttons, install the power supply, set the clock, etc. etc. But how
it's not about learning to build circuits in Proteus but about learning to
programming Pics is better to use a "Project" card that already has everything
this and is ready to be used.

Figure 2.1.1Diagram for programming a PIC.

7
III. DEVELOPMENT

The main objective of this practice is to use tools to assemble and


run the first program in assembly language for the microcontroller
PIC16F877A for using the I/O.

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

The first part is to compile the following code:

Figure 3.1Configuration for the program.

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.

In the circuit of figure 3.3 we have the simulation in which we check if


our program really worked, we loaded the code to the PIC of the simulation and
we saw that the increment was working correctly, since when setting 0 in the
Dip-Switch the result of the LEDs is 1. Finally, to check that everything was okay,
we burned the PIC to start assembling the circuit on the protoboard and move on to
the final result in this one.

10
IV. RESULTADOS

Using figure 3.3 as reference, this circuit was assembled on a breadboard.


As shown in figure 4.1. It is composed of the PIC16F877A., 2
capacitors, 17 resistors, 8 LEDs, 1 quartz crystal and a sensor (switch). The design
as a guide to making the circuit, was implemented by us.
The least significant values of the dip switch input start from the side
left (where the value of 1 is) and at the output of the LEDs the least significant
They start at the first blue LED on the right side.

Figure 4.1Complete circuit on the breadboard.

Once the circuit is ready, it is connected to the voltage source.


supplied voltage of 5V and 0.01A), with the power supply provided, the circuit starts to
function correctly and without connection errors (does not show a short circuit in the
cables), this is shown in figure 4.2.

11
Figure 4.2Circuit connected to the voltage source.

Next, photos were taken of the circuit operation when it is


connected to the power source and how the output of the LEDs is configured
the input of the dip switch. Being an 8-bit input, it tends to have 256 combinations,
therefore the most significant ones will be shown.
In figure 4.3, you can see how the first blue LED lights up.
even when the input shows a value of 0; this happens because in the register bank it
it has a value of 1 (the number that will be added to the added values) and in this case
0 is entered, therefore 0+1=1, that is why the LED at position 1 is displayed.

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.

Figure 4.4LED in the 2nd position on, with an input value of 1.

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.5LED of the 4th ignition position, with an input value of 7.

Another case showing the operation is in figure 4.6, entered in


the input of the dip switch the value of 252, therefore the addition action is performedr,
252+1=253, therefore all the LEDs light up except for the 2nd.

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.

Figure 4.7LEDs in positions 2 and 3 lit up, with an input value of 5.

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.

Figure 4.8LEDs of positions 2 and 3 on, with an input value of 5.

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.

Figure 4.9Correct operation of the circuit.

16
V
CCONCLUSIONS
.

★ Alberto Lizeth Guerrero


Through this practice it was possible to knowr, eunderstand and study
about assembly language to make its realization possible.

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.

★ Hidalgo Escobar Sabina Monserrat


For the preparation of this practice, it was necessary to use the language
assembler (MPLAB) for the creation of the circuit which allows generating a
registration of primary terms (values) so that when necessary it
generate the increase by 1, for that it was also necessary to learn the different ones
ports of the PIC to be used (PIC16F877A), since these with the help of the code and
a simulation (Proteus), the assembly was able to be performed correctly in
physical.

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.

★ Sotero Sanchez German


The objective of this practice is to learn how to handle input and output ports.
output in the PIC16F877A,specifically in this practice we handle with a dip
switch the input and output ports with several LEDs.

Here I was able to learn how to connect a dip switch since


Before this practice, I didn't know what the connection of this was.

In the programming section, I learned about the use of variables such as


values or records since at the time of programming, the
variable used as a record when it was supposed to be used as a valuer.

Although the program worked, it was not recommended to use it.


variable as a record since a particular address was used and could lead to
cause problems in the program.

★ Verduzco Acosta Kimberly Janeth


The objective of thisis learning to operate in PIC16F877A, its ports of
E/S and knowing which programs, code editors, and programmers to use for
apply its operation in circuits on a breadboard.

In order to carry out the practice, the first thing that was done was to write the code in

the MPLAB program that is able to record binary values and by


each valuer, s1. Once the program is executed and confirming that it has no errors,
this is sent to another program that is capable of transforming it into a type of

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.

2, demonstrating that the output is equal to 2.

19
REFERENCES

[1]Valdez.L.J. (2014).How to program a PICMexico. UNIDAP Retrieved from


[Link]
[Link]
[2]PIC16F877A microcontroller. (n.d.). MV Electrónica. Retrieved October 5
2022, of[Link]
[3] Geek Factory. (2022, September 21).PIC16F877A Microcontroller PIC 8 bits
Microchip. Recovered 5 of October of 2022 of
[Link]
7a-microcontroller-pic-8-bits-microchip/
[4]PIC16F877A DatasheetRetrieved October 5, 2022,
[Link] bclid=IwAR1uLXuqk0
TE2zkErDvHWG4fc1UytRaqM8l0nErFPLENrQpEIjdXi6_--xc

20

You might also like