Post on 13-Jul-2016
description
Ingeniería Electromecánica
MICROCONTROLADORESEJERCICIOS: 1, 2 Y 3
Nombre del alumno: Alvarez Villegas Tomas Ernesto
Numero de control: 11090245
Docente: M.C: Alejandro Carlos Pérez Flores
Elaborado: 7/Septiembre/2015
INSTITUTO TECNOLÓGICO DE ZACATEPEC
EJERCICIO 1
/*
* File: newmain.c
* Author: Rafa
*
* Created on 30 de agosto de 2015, 12:43 AM
*/
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
// Configuration: Ext reset, Watchdog OFF, HS oscillator
#pragma config FOSC = XT, WDTE = OFF, PWRTE = OFF
#pragma config BOREN = OFF, LVP = OFF, CPD = OFF, WRT = OFF
// Define switch and LED connections
#define S1 PORTBbits.RB6
#define S2 PORTBbits.RB7
#define LD1 PORTBbits.RB4
#define LD2 PORTBbits.RB5
//Define useful symbols
#define INFINITE_LOOP 1
#define SW_ON 0
#define LED_ON 1
#define LED_OFF 0
#define DELAY_MS 10
#define DELAY_MULT 100
//
// Define clock frequency 4 Mhz
#define _XTAL_FREQ 4000000
/*
*
*/
int main() {
TRISBbits.TRISB4 = 0; // configure RB4 as output
TRISBbits.TRISB5 = 0; // configure RB5 as output
TRISBbits.TRISB6 = 1; // configure RB6 as input
TRISBbits.TRISB7 = 1; // configure RB7 as input
int cuenta = DELAY_MULT;
while(INFINITE_LOOP){
if (S1==SW_ON)
LD1 = LED_ON;
if (S2==SW_ON)
LD1 = LED_OFF;
__delay_ms(DELAY_MS);
if (cuenta-- == 0){
if (LD2 == LED_ON)
LD2 = LED_OFF;
else
LD2 = LED_ON;
cuenta = DELAY_MULT;
}
}
}
EJERCICIO 2
LED 1 LED 2 LED 3 LED 41 0 0 00 1 0 00 0 1 00 0 0 1
/*
* File: newmain 2.c
* Author: Rafa
*
* Created on 3 de septiembre de 2015, 08:58 PM
*/
#include <stdio.h>
#include <stdlib.h>
#include <xc.h> // libreria del compilador de c xc8
#define _XTAL_FREQ 8000000 //Frecuencia usada para las instrucciones de retardo (delay)
#define RETARDO 800
/*
*
*/
int main(int argc, char** argv) {
TRISB = 0x00; // Todos los bits del puerto B, serán salidas
PORTB = 0x00 ; // Colocamos 0s en los bits del puerto B
while (1) {
PORTBbits.RB0 = 1;
PORTBbits.RB3 = 0;
PORTBbits.RB1 = 0;
PORTBbits.RB2 = 0;
__delay_ms(RETARDO);
PORTBbits.RB1 = 1;
PORTBbits.RB0 = 0;
PORTBbits.RB2 = 0;
PORTBbits.RB3 = 0;
__delay_ms(RETARDO);
__delay_ms(50);
PORTBbits.RB2 = 1;
PORTBbits.RB0 = 0;
PORTBbits.RB1 = 0;
PORTBbits.RB3 = 0;
__delay_ms(RETARDO);
__delay_ms(50);
PORTBbits.RB3 = 1;
PORTBbits.RB0 = 0;
PORTBbits.RB1 = 0;
PORTBbits.RB2 = 0;
__delay_ms(RETARDO);
}
return (EXIT_SUCCESS);
}
EJERCICIO 3
LED1 LED2 LED3 LED40 1 0 10 1 1 01 0 1 01 0 0 1
/*
* File: newmain 3.c
* Author: Rafa
*
* Created on 3 de septiembre de 2015, 08:54 PM
*/
#include <stdio.h>
#include <stdlib.h>
#include <xc.h> // libreria del compilador de c xc8
#define _XTAL_FREQ 8000000 //Frecuencia usada para las instrucciones de retardo (delay)
#define RETARDO 800
/*
*
*/
int main(int argc, char** argv) {
TRISB = 0x00; // Todos los bits del puerto B, serán salidas
PORTB = 0x00 ; // Colocamos 0s en los bits del puerto B
while (1) {
PORTBbits.RB0 = 0;
PORTBbits.RB1 = 1;
PORTBbits.RB2 = 0;
PORTBbits.RB3 = 1;
__delay_ms(RETARDO);
PORTBbits.RB1 = 1;
PORTBbits.RB0 = 0;
PORTBbits.RB2 = 1;
PORTBbits.RB3 = 0;
__delay_ms(RETARDO);
PORTBbits.RB2 = 1;
PORTBbits.RB0 = 1;
PORTBbits.RB1 = 0;
PORTBbits.RB3 = 0;
__delay_ms(RETARDO);
PORTBbits.RB3 = 1;
PORTBbits.RB0 = 1;
PORTBbits.RB1 = 0;
PORTBbits.RB2 = 0;
__delay_ms(RETARDO);
__delay_ms(90);
}
return (EXIT_SUCCESS);
}