micro controladores
DESCRIPTION
trata de unos ejercicios para microcontroladores mas que nada son secuencias con leds. y hacionamiento de motores ! es un buen trabajoTRANSCRIPT
Ingeniería Electromecánica
MICROCONTROLADORES
EJERCICIOS DE LA UNIDAD 2
Nombre del alumno: Alvarez Villegas Tomas Ernesto
Numero de control: 11090245
Docente: M.C: Alejandro Carlos Pérez Flores
INSTITUTO TECNOLÓGICO DE ZACATEPEC
EJERCICIO 2.1
#include "p16F873A.inc"
; __config 0xFF79NFIG
; __config 0xFF79
__CONFIG _FOSC_XT & _WDTE_OFF & _PWRTE_OFF & _CP_OFF
TA_ADDR equ 0x21
TD_ADDR equ 0x22
COMPRESOR equ RB0
ALRMA equ RB1
LIMITE_ALARMA equ 0x0A
RES_VECT CODE 0X0000
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>
#pragma config FOSC = XT, WDTE = OFF, PWRTE = OFF, CP = OFF
#define COMPRESOR PORTBbits.RB0
#define ALARMA PORBbits.RB1
#define ON 1
#define OFF 0
unsigned char tempactual __at(0x21);
unsigned char tempdeseada __at(0x22);
int main () {
TRISBbits.TRISB0 = 0;
TRISBbits.TRISB1 = 0;
COMPRESOR = OFF;
ALARMA = OFF;
while(1) {
if (tempactual > tempdeseada)
COMPRESOR = ON;
else
COMPRESOR = OFF;
if ((tempactual - tempdeseada) > 10)
ALARMA = ON;
}
}
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 mayoría 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 físicamente
siguen estando separados.
Ejercicio 2.5
Propósito de los registros de propósito general (GPRs)
Los registros de propósito general (en inglés 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 B’11110000’
movwf TRISB
bcf STATUS, RP0
bsf STATUS RP0
movlw B’11111111’
movwf TRISA
movlw B’00000111’
movwf ADCON 1
bcf STATUS RP0
btfss portA, RA0
GOTO NO_RA0
GOTO SI_RA0
LOOP
BTFSS PORTA, RA0
GOTO NO_RA0
GOTO SI_RA0
ETIQUETA_1
BTFSS PORTA, RA1
GOTO NO_RA1
GOTO SI_RA1
ETIQUETA_2
BTFSS PORTA, RA2
GOTO NO_RA2
GOTO SI_RA2
ETIQUETA_3
BTFSS PORTA, RA3
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
BSF PORTB, RB1
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