Professional Documents
Culture Documents
Act3 - Timers and Delays
Act3 - Timers and Delays
DELAYS
MICROCONTROLLERS
FJ22
PREPARED BY
Introduction
The following report will detail the process elaborated to comply with activity 3 of
Timers and delays. It was to be reused in PIC16F877A. This microcontroller has a lot of
configuration and ports that allow it to develop the activity.
This microcontroller works with a RISC architecture at an operating frequency that can reach
up to 20 MHz. For the PIC16F877A there are 35 instructions to be able to program your
algorithms inside the memory of this microcontroller and carry out your project.
The PIC16F877A is used to develop projects in which you have to use several external
elements for its operation, this can be done thanks to the large number of pins it has.
Figure 1. PIC16F887A
The PIC16F877A microcontrollers within its 40 pins have 5 ports available, port A, B, C, D
and E. In port A you can find the pins that can be used as analog inputs which are RA0,
RA1 and RA2. Port A of the PIC16F877A microcontroller occupies 6 of the 40 pins that this
microcontroller provides, that is, it goes from A0 to A5.
Port B on the other hand makes use of 8 pins, this port goes from B0 to B7 being B0 the port
for the use of programmed interrupts. Like port B, port C has 8 pins, it goes from C0 to C7.
Port C is the most used since it is where the pins for the PWM and for the UART
communication with its RX and TX pins are located.
D, like C and B, has 8 pins that we can use. And finally, port E, which is where the rest of the
pins that accept analog inputs are located, has only 3 pins. The remaining pins are used for
the connection of the external crystal and the power supply of the PIC16F877A. Figure 2
In this activity you will have two inputs that will be activated by a push button. One of them
will be a tigger and the other a reset. They will be connected as shown Figure 3
● LP" type oscillator (Low Power) for frequencies between 32 and 200 Khz.
● HS" type oscillator (High Speed) for frequencies between 4 and 20 MHz
This configuration should be used when using crystals larger than 4 MHz. The
connection is the same as for a normal crystal.
● TTL oscillator
This type of oscillator is based on a crystal that contains all the circuitry to generate a
square wave.These crystal types are specially designed for TTL technologies.
For this activity it is necessary to obtain a truth table that will allow the programming of the
LEDs to be turned on at the desired time, which in this case will be the numbers from 0 to 9.
Figure 7. Configuration led by number.
A vital component for the development of this activity is the PickIt3, which is
Microchip's simplest and lowest cost debugging and programming tool. It is fully supported
by the MPLAB IDE and has a simple USB Full Speed connection to the computer that not
only allows programming and debugging but also updates the internal firmware of the
PICKIT3. [2]
Figure 8. Pickit3
To determine the settings of the 7-segment display in the program I used the following table
Finally, connections were made to the PIC16F877A at 5 V voltage from an Arduino Uno.
Figure 19. Circuit
implementation.
Results
The results obtained are the simulation of the circuit in proteus, which can be appreciated in
the following link:
https://drive.google.com/file/d/1Xk4iZtmqHH4KmeT3VZjw1-_eob2PfH1T/view?usp=sharin
g
https://youtu.be/fbqgFlzPRKA
Conclusions
This activity allowed me to remember the structure of counters, for and while cycles. At the
beginning I had a hard time programming but thanks to it I have mastered a little more
programming. On the other hand, I had a hard time with the implementation because of the
configuration of the bits of the 7-segment display. Because I had never physically connected
one, I finally managed to display on the screen what I wanted. The most important thing of
the practice was the oscillator, finally I could understand why it is used and what role it plays
in the circuit. It tells the microcontroller at what speed it should work.
References
[4]MPLAB-IDE-SOFTWARE-DE-DESARROLLO-DE-MICROCHIP-PARA-PIC-18F2550-PUN
TO-FLOTANTE-S.A. (2022). Retrieved 7 April 2022, from
https://www.puntoflotante.net/mplab.htm
/*
* File: Act_3.c Rocket Countdown
* Author: Laritza Márquez A01702253
* Created on 29 de marzo de 2022, 01:15 PM
*/
// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial
Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data
EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write
protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code
protection off)
#include <xc.h>
#define _XTAL_FREQ 20000000 //Crystal oscillator at 20 MHz
// 9 8 7 6 5 4 3 2 1 0
int display[10] =
{0b10010000,0b10000000,0b11111000,0b10000010,0b10010010,0b10011001,0b1011000
0,0b10100100,0b11111001,0b11000000}; //array of the numbers from 9 to 0 for 7-segment
display common anode
int i; //counter
//int display[10] =
{0b10010000,0b10000000,0b11111000,0b10000010,0b10010010,0b10011001,0b1011000
0,0b10100100,0b11111001,0b11000000}; //array of the numbers from 9 to 0 for 7-segment
display common anode
//int display[10] =
{0b10010000,0b10010000,0b10010000,0b10010000,0b10010000,0b10010000,0b100100
00,0b10010000,0b10010000,0b10010000};
void displayseg(){ //function for 7-segment display which shows all numbers from 9 to 0
PORTB= display[i];
__delay_ms(1000);
Red_LED = 1;
Green_LED = 0;
__delay_ms(Delay_leds);
Red_LED = 0;
Green_LED = 1;
__delay_ms(Delay_leds);
}
}
Reset();
}
}
Appendix B
Proteus simulation
https://drive.google.com/drive/folders/1N-WindTYsGC3NYTRPxIV02V5IWd_OeiI?usp=sha
ring