Está en la página 1de 14

MT-136-A 2019-1 | Laboratorio del 28 de Mayo

UNIVERSIDAD NACIONAL DE INGENIERÍA


FACULTAD DE INGENIERÍA MECÁNICA

Curso: Sistemas Embebidos (MT 136)

Tema: Laboratorio n°02

Profesor: Ing. José Oliden

Sección: A

Alumnos: Código

Williams F. Noel Vasquez 20165027G

Gelmer Keyti, Geronimo Riveros 20161062B

Fecha de presentación: 28/05/2019

2019-1

_____________________________________________________________________
Rímac-Lima, FIM-UNI
MT-136-A 2019-1 | Laboratorio del 28 de Mayo

LABORATORIO N2:

Laboratorio n°2

____________________________________________________________________________

1. Laboratorio n°2

De acuerdo al cuadro realizar lo siguiente:

- Diagrama de flujo
- Programar en Software MPLAB lenguaje Assembler
- Implementación en Protoboard.

2. Objetivo
Desarrollar el problema propuesto, aplicando conocimientos del lenguaje
Assembler en el Software MPLAB, aplicando conceptos de manejo de puertos,
uso de subrutinas, delays, timer 0 e interrupciones (Timer0, RB0, RB4RB7)
Manejo y configuración del microcontrolador PIC16F877A y realizar el
funcionamiento con el Software Proteous y su implementación física.

_____________________________________________________________________
Rímac-Lima, FIM-UNI
MT-136-A 2019-1 | Laboratorio del 28 de Mayo

3. Diagrama de Flujo
Se desarrolla el diagrama de flujo:

3.1 Diagrama de Flujo del Programa Principal

INICIO

Configuración

PORTD OUT

OPTION_REG

b’ 11000111’

Activar
interrupciones

GIE, TOIE, INTE,


RBIE
PORTD,0=0

DELAY 100ms

PORTD,0 =1

DELAY 100ms

_____________________________________________________________________
Rímac-Lima, FIM-UNI
MT-136-A 2019-1 | Laboratorio del 28 de Mayo

3.2 Diagrama de Flujo de las Interrupciones

INTERRUPCION

Guardo W, STATUS,
PCLATH

TOIF= INTF= RBIF=


1 1 1

INT_TMR0 INT_RB RB4RB7

Recupero W, STATUS, PCLATH

RETFIE

_____________________________________________________________________
Rímac-Lima, FIM-UNI
MT-136-A 2019-1 | Laboratorio del 28 de Mayo

3.3 Diagrama de Flujo de Timer0 y RB0

INT_TMR0

TMR0=.60

D1=0
?

D1=0 D1=1

T0IF=0

Salida_int_tmr0

INT_RB

D2=0
?

D2=0 D2=0

INTF=0

Salida_rb

3.4 Diagrama de Flujo de la interrupción RB4-RB7

_____________________________________________________________________
Rímac-Lima, FIM-UNI
MT-136-A 2019-1 | Laboratorio del 28 de Mayo

Figura 1, Diagrama de Flujo

_____________________________________________________________________
Rímac-Lima, FIM-UNI
MT-136-A 2019-1 | Laboratorio del 28 de Mayo

4. Programación en Software MPLAB lenguaje Assembler

list p=16f877A ; list directive to define processor


#include <p16f877A.inc> ; processor specific variable
definitions

__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON


& _HS_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF

; '__CONFIG' directive is used to embed configuration data within .asm file.


; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.

;*** VARIABLE DEFINITIONS


cont1 EQU 0x20
cont2 EQU 0x21
CONTA3 EQU 0X23
w_temp EQU 0x7D ; variable used for context saving
status_temp EQU 0x7E ; variable used for context saving
pclath_temp EQU 0x7F ; variable used for context saving

;************************
ORG 0x000 ; processor reset vector

nop ; nop required for icd


goto main ; go to beginning of program

ORG 0x004 ; interrupt vector location

movwf w_temp ; save off current W register contents


movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register

_____________________________________________________________________
Rímac-Lima, FIM-UNI
MT-136-A 2019-1 | Laboratorio del 28 de Mayo

movf PCLATH,w ; move pclath register into w register


movwf pclath_temp ; save off contents of PCLATH register
goto int1

; isr code can go here or be located as a call subroutine elsewhere


s_int:
movf pclath_temp,w ; retrieve copy of PCLATH register
movwf PCLATH ; restore pre-isr PCLATH register contents
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt

main

; configuracion
bsf STATUS, RP0
bcf STATUS, RP1 ; banco 1
clrf TRISD
movlw b'11000111'
movwf OPTION_REG
bcf STATUS, RP0 ;banco 0
bcf STATUS, RP1
bsf INTCON,GIE
movlw .60
movwf TMR0
bsf INTCON,T0IE
bsf INTCON,INTE
bsf INTCON,RBIE
clrf PORTB

pp:
bcf PORTD,0
call delay_100ms
bsf PORTD,0
call delay_100ms

_____________________________________________________________________
Rímac-Lima, FIM-UNI
MT-136-A 2019-1 | Laboratorio del 28 de Mayo

goto pp

int1:
btfsc INTCON,T0IF
goto Int_TMR0
btfsc INTCON, INTF
goto int_ex
btfsc INTCON, RBIF
goto int_74
goto s_int

Int_TMR0
movlw .60
movwf TMR0
btfss PORTD,1
goto d1_0
goto d1_1
d1_0:
bsf PORTD,1
goto s_tmr0
d1_1:
bcf PORTD,1
goto s_tmr0
s_tmr0:
bcf INTCON,T0IF
goto s_int
; Interrupcion RB0
int_ex:
btfss PORTD,2
goto d2_0
goto d2_1
d2_0:
bsf PORTD,2
goto s_ex
d2_1:
bcf PORTD,2
goto s_ex

_____________________________________________________________________
Rímac-Lima, FIM-UNI
MT-136-A 2019-1 | Laboratorio del 28 de Mayo

s_ex:
bcf INTCON,INTF
goto s_int

;Interrupcion RB4-RB7
int_74:
movf PORTB,W
xorwf CONTA3,CONTA3
btfsc CONTA3,7
goto b7
btfsc CONTA3,6
goto b6
btfsc CONTA3,5
goto b5
btfsc CONTA3,4
goto b4
goto s_74
b7:
btfsc PORTB,7
goto d4
goto s_74
d7:
btfss PORTD,7
goto d7_0
goto d7_1
d7_0:
bsf PORTD,7
goto s_74
d7_1:
bcf PORTD,7
goto s_74
b6:
btfss PORTB,6
goto d5
goto s_74
d6:
btfss PORTD,6

_____________________________________________________________________
Rímac-Lima, FIM-UNI
MT-136-A 2019-1 | Laboratorio del 28 de Mayo

goto d6_0
goto d6_1
d6_0:
bsf PORTD,6
goto s_74
d6_1:
bcf PORTD,6
goto s_74
b5:
btfss PORTB,5
goto d6
goto s_74
d5:
btfss PORTD,5
goto d5_0
goto d5_1
d5_0:
bsf PORTD,5
goto s_74
d5_1:
bcf PORTD,5
goto s_74
b4:
btfsc PORTB,4
goto d7
goto s_74
d4:
btfss PORTD,4
goto d4_0
goto d4_1
d4_0:
bsf PORTD,4
goto s_74
d4_1:
bcf PORTD,4
goto s_74
s_74:

_____________________________________________________________________
Rímac-Lima, FIM-UNI
MT-136-A 2019-1 | Laboratorio del 28 de Mayo

movf PORTB,W
movwf CONTA3
movf PORTB,1
bcf INTCON,RBIF
goto s_int

delay_25
movlw 0xA7
movwf cont1
bucle1
movlw 0xFA
movf cont2
bucle2
decfsz cont2,F
goto bucle2
decfsz cont1,F
goto bucle1
return
delay_50
call delay_25
call delay_25
return
delay_100ms
call delay_50
call delay_50
return

END ; directive 'end of program'

_____________________________________________________________________
Rímac-Lima, FIM-UNI
MT-136-A 2019-1 | Laboratorio del 28 de Mayo

5. Implementación en Protoboard

5.1 Materiales Usados

- 01 Microcontrolador PIC16F877A
- 01 Cristal de 20Mhz
- 13 leds
- 13 resistencias de 330omhios
- Jumper (40)
- Fuente de 5v
- 01 resistencia de 5Komhios
- 06 pulsador
- 02 condensadores de 27 pico faradios
- 03 condensadores de 0.1 micro faradios

5.2 Armado del Circuito


5.2.1 Armado en Software Proteus

a) RB7, modifica el estado del RD4

Figura 1, Simulación en Proteous


De la misma manera se procede con las siguientes interrupciones

_____________________________________________________________________
Rímac-Lima, FIM-UNI
MT-136-A 2019-1 | Laboratorio del 28 de Mayo

5.2.2 Armado en Físico


Se procede con el armado del circuito

Figura 2, Implementación del Circuito

6. Recomendaciones y Conclusiones

- Se demuestra que los conceptos teóricos del microcontrolador funcionan en la


práctica.
- Se desarrolla los 03 tipos de interrupciones del PIC16F877A.
- Se tuvo problemas para la implementación en HARDWARD para desarrollar el
problema propuesto.
- Para resolver el problema de interferencias en los pines del RB4 al RB7 se
desarrolló e implemento el concepto de Pullp Down y Pull Up.

_____________________________________________________________________
Rímac-Lima, FIM-UNI

También podría gustarte