Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Ingeniera
Electromecnica
MICROCONTROLADORES
EJERCICIOS DE LA UNIDAD 2
EJERCICIO 2.1
#include "p16F873A.inc"
; __config 0xFF79NFIG
; __config 0xFF79
GOTO START
MAIN_PROG CODE
START
BSF STATUS,RP0
MOVLW B'11111100'
MOVWF TRISB
BCF STATUS,RP0
BCF PORTB,COMPRESOR
BCF PORTB,ALARMA
LOOP
MOVF TA_ADDR,W
SUBWF TD_ADDR,W
BTFSS STATUS,C
GOTO COMPRESOR_ON
BCF PORTB,COMPRESOR
GOTO LOOP
COMPRESOR_ON
BSF PORTB,COMPRESOR
ADDLW LIMITE_ALARMA
BTFSC STATUS,C
GOTO LOOP
BSF PORTB,ALARMA
GOTO LOOP
END
EJERCICIO 2.2
/*
* File: newmain.c
* Author: Rafa
*
* Created on 1 de octubre de 2015, 11:25 AM
*/
#include <xc.h>
int main () {
TRISBbits.TRISB0 = 0;
TRISBbits.TRISB1 = 0;
COMPRESOR = OFF;
ALARMA = OFF;
while(1) {
if (tempactual > tempdeseada)
COMPRESOR = ON;
else
COMPRESOR = OFF;
Ejercicio 2.4
Registros de funciones especiales (SFR)
Todos los microcontroladores cuentan con registros internos que permiten
controlar y supervisar las funciones y recursos disponibles del dispositivo.
Los registros de los microcontroladores PIC se encuentran en un espacio especial
de la memoria de datos, el SFR (Special Function Registers). En los dispositivos
PIC16F estos registros son de 8 bits, la mayora de lectura y escritura. Se puede
acceder a dichos bits de manera individual, o bien a todo el registro a la vez.
Determinados pares de registros tienen funciones especiales para las cuales se
pueden considerar unidos en un nico registro de 16 bits, aunque fsicamente
siguen estando separados.
Ejercicio 2.5
Propsito de los registros de propsito general
(GPRs)
Los registros de propsito general (en ingls GPRs o General Purpose Registers)
pueden guardar tanto datos como direcciones. Son fundamentales en
la arquitectura de von Neumann. La mayor parte de las computadoras modernas
usa GPR.
Ejercicio 2.6a
#include "p16F873A.inc"
; CONFIG
; __config 0xFF79
__CONFIG _FOSC_XT & _WDTE_OFF & _PWRTE_OFF & _BOREN_ON & _LVP_OFF & _CPD_OFF & _WRT_OFF &
_CP_OFF
Org 00
bsf STATUS,RP0
movlw 0x07
movwf TRISB
bcf STATUS,RP0
start
btfsc PORTB,RB0
goto no_sw1
goto si_sw1
si_sw1
bsf PORTB,RB3
bcf PORTB,RB4
bcf PORTB,RB5
no_sw1
btfsc PORTB,RB1
goto no_sw2
goto si_sw2
si_sw2
bcf PORTB,RB3
bsf PORTB,RB4
bcf PORTB,RB5
no_sw2
btfsc PORTB,RB5
goto no_sw3
goto si_sw3
si_sw3
bcf PORTB,RB4
bsf PORTB,RB5
bcf PORTB,RB3
no_sw3
goto start
END
Ejercicio 2.6b
EJERCICIO 2.8B
#include "p16F873A.inc"
; CONFIG
; __config 0xFF79
__CONFIG _FOSC_XT & _WDTE_OFF & _PWRTE_OFF & _BOREN_ON & _LVP_OFF & _CPD_OFF & _WRT_OFF &
_CP_OF
bsf STATUS,RP0
movlw B11110000
movwf TRISB
movlw B11111111
movwf TRISA
movlw B00000111
movwf ADCON 1
GOTO NO_RA0
GOTO SI_RA0
LOOP
GOTO NO_RA0
GOTO SI_RA0
ETIQUETA_1
GOTO NO_RA1
GOTO SI_RA1
ETIQUETA_2
GOTO NO_RA2
GOTO SI_RA2
ETIQUETA_3
GOTO NO_RA3
GOTO SI_RA3
NO_RA0
BCF PORTB,RB0
GOTO ETIQUETA_1
NO_RA1
BCF PORTB,RB1
GOTO ETIQUETA_2
NO_RA2
BCF PORTB,RB2
GOTO ETIQUETA_3
NO_RA3
BCF PORTB,RB3
GOTO LOOP
SI_RA0
BSF PORTB,RB0
GOTO ETIQUETA_1
SI_RA1
GOTO ETIQUETA_2
SI_RA2
BSF PORTB,RB2
GOTO ETIQUETA_3
SI_RA3
BSF PORTB,RB3
GOTO LOOP
END
EJERCICIO 2.9
#include "p16F873A.inc"
; CONFIG
; __config 0xFF79
__CONFIG _FOSC_XT & _WDTE_OFF & _PWRTE_OFF & _BOREN_ON & _LVP_OFF & _CPD_OFF & _WRT_OFF &
_CP_OFF
delay (clock=4000000)
BSF STATUS, RP0
CLRT TRISB
BCF STATUS, RP0
MOVLW .4
MOVWF 0X21
MOVLW .82
MOVWF 0X22
MOVLW 0XCC
MOVWF 0X20
LOOP
CALL DELAY
DECFSZ 0X20
GOTO NO_ZERO
GOTO SI_ZERO
NO_ZERO
MOVF 0X20,W
MOVWF PORTB
SI_ZERO
MOVF 0X20,W
MOVWF PORTB
MOVLW 0XCC
MOVWF 0X20
GOTO LOOP
DELAY MOVF 0X21,W
MOVWF 0X23
CTA1 MOVF 0X22,W
MOVWF 0X24
CTA2 DECFSZ 0X24
GOTO CTA2
DECFSZ 0X23
GOTO CTA2
RETURN
END