CENTRO TECNOLÓGICO DE AVANZADA
AREA DE MECATRÓNICA
Código: M07 MICROCONTROLADORES II
Laboratorio: D-19
Duración: 2 Hs PUERTOS COMO GPIO
2.4. Encendido de LEDs con Switch
Objetivos
1. Realizar las configuraciones del ATMEGA128 para encender LED con switch.
2.4.1. Procedimiento
AVR Studio
1. Configure la F_CPU a 8MHz.
2. Configure el PUERTO E como salida.
3. Configure el PUERTO D como entrada.
4. Configure el PUERTO D a PULL-UP (entrada).
5. Realice el código en C, el LED debe encender cuando el switch se mantiene pulsado,
caso contrario debe permanecer apagado.
#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/sfr_defs.h>
int main(void)
{
DDRE = 0b11111111;//PUERTO E COMO SALIDA (LED)
DDRD = 0b00000000;//PUERTO D COMO ENTRADA (SWITCH)
PORTD = 0b11111111;//PUERTO D A PULL-UP
while (1)//LOOP INFINITO
{
if(bit_is_clear(PIND, PIND0))//SI EL SW0 SE PULSA
PORTE |= _BV(PINE0);//ENCIENDE EL LED0
else
PORTE &= ~_BV(PINE0);//APAGA EL LED0
}
}
Pedro Ramírez <pedroramirez22@gmail.com> 1
CENTRO TECNOLÓGICO DE AVANZADA
AREA DE MECATRÓNICA
Código: M07 MICROCONTROLADORES II
Laboratorio: D-19
Duración: 2 Hs PUERTOS COMO GPIO
Proteus
1. En el Edit Component del ATMEGA128, seleccione el CKSEL Fuses: (0100)
Int. RC 8MHz.
2. En el Edit Component del ATMEGA128, seleccione el Program File el archivo
.hex generado dentro de la carpeta Debug en la ruta del proyecto del AVR Studio
en cuestión.
3. Simule el esquemático y compruebe que el LED enciende cuando se pulsa el switch.
2.4.2. Esquemático
Realice el esquemático de la Figura 2.1 en el Proteus.
PE0/RXD0/PDI 2
PE1/TXD0/PDO 3
PE2/XCK0/AIN0 4
PE3/OC3A/AIN1 5
PE4/OC3B/INT4 6
PE5/OC3C/INT5 7
PE6/T3/INT6 8
PE7/ICP3/INT7 9
PB0/SS10
PB1/SCK11
PB2/MOSI12
PB3/MISO13
PB4/OC014
PB5/OC1A15
PB6/OC1B16
PB7/OC2/OC1C17
PG3/TOSC2 18
PG4/TOSC1 19
RESET20
XTAL223
XTAL124
PD0/SCL/INT0 25
PD1/SDA/INT1 26
PD2/RXD1/INT2 27
PD3/TXD1/INT3 28
PD4/ICP1 29
PD5/XCK1 30
PD6/T1 31
PD7/T2 32
PG0/WR 33
PG1/RD 34
PC0/A835
PC1/A936
PC2/A1037
PC3/A1138
PC4/A1239
PC5/A1340
PC6/A1441
PC7/A1542
PG2/ALE 43
PA7/AD744
PA6/AD645
PA5/AD546
PA4/AD447
PA3/AD348
PA2/AD249
PA1/AD150
PA0/AD051
PF7/ADC7/TDI 54
PF6/ADC6/TDO 55
PF5/ADC5/TMS 56
PF4/ADC4/TCK 57
PF3/ADC3 58
PF2/ADC2 59
PF1/ADC1 60
PF0/ADC0 61
AREF62
AVCC64 PEN 1
U1
ATMEGA128
R1
330
D1
LED-YELLOW
Figura 2.1: Encender LED por software
Pedro Ramírez <pedroramirez22@gmail.com> 2
CENTRO TECNOLÓGICO DE AVANZADA
AREA DE MECATRÓNICA
Código: M07 MICROCONTROLADORES II
Laboratorio: D-19
Duración: 2 Hs PUERTOS COMO GPIO
2.4.3. Ejercicios propuestos
1. Realice el mismo ejercicio pero ahora conecte el LED al PUERTO A y el switch
al PUERTO B.
2. Monte un circuito en Proteus con 8 switches y 8 LEDs. Cuando se pulsa un switch
se enciende el LED correspondiente, es decir SW1-LED1, SW2-LED2, etc.
3. Monte un circuito en Proteus con 2 switches (MAR, PAR) y un LED. El programa
debe trabajar como un circuito de enclavamiento con prioridad a la marcha.
4. Monte un circuito en Proteus con 2 switches (MAR, PAR) y un LED. El programa
debe trabajar como un circuito de enclavamiento con prioridad al paro.
5. Monte un circuito en Proteus con 2 switches (A, B) y un LED. El programa debe
funcionar (con los switches) con la lógica de:
a) AND
b) OR
c) NAND
d) NOR
e) XOR
f ) XNOR
Obs: realice la tabla de verdad para verificar los resultados.
6. Realice un circuito que cuente con tres switches (A, B, C) y un LED, al presionar
A el LED debe parpadear a 10Hz, al presionar B el LED debe parpadear a 5Hz y
al presionar C el LED debe parpadear a 1Hz.
2.4.4. Conclusión
Pedro Ramírez <pedroramirez22@gmail.com> 3

Más contenido relacionado

PDF
A report on 2 to 1 mux using tg
PPTX
Diodes and Its Application
PPT
Adc interfacing
PPT
Digital modulation
PPTX
Develop a shadow sensor alarm using IC 741
PPTX
Trintron tube Presentation
PPTX
Plc programming with fbd
PPTX
A report on 2 to 1 mux using tg
Diodes and Its Application
Adc interfacing
Digital modulation
Develop a shadow sensor alarm using IC 741
Trintron tube Presentation
Plc programming with fbd

La actualidad más candente (20)

PPTX
SPICE LEVEL I/LEVEL II/LEVEL III AND BSIM MODELS
PPTX
Beie unit 2
PPTX
PIC Microcontrollers
PPTX
Antennas - Array of point sources
PPTX
ADC and DAC Best Ever Pers
PPTX
Single Slope ADC.pptx
PPTX
Isolator & Circulator -FT.pptx
PPTX
Mosfet’s
PPTX
Vlsi gate level design
PPT
Mosfet
PPT
VLSI subsystem design processes
PPTX
DESIGN AND SIMULATION OF DIFFERENT 8-BIT MULTIPLIERS USING VERILOG CODE BY SA...
PDF
A PROJECT REPORT On LASER SECURITY ALARM SYSTEM
PDF
Arm cortex (lpc 2148) based motor speed
PPTX
LOGIC FAMILY.pptx
PPTX
Directional couplers ppt for microwave engineering
PDF
Pulse amplitude modulation & demodulation
PDF
Power power electronics (solution manual) by M.H.Rashid.pdf
PPTX
180nm process typical parameter values
PPTX
single stage amplifier Unit 5 AMVLSI
SPICE LEVEL I/LEVEL II/LEVEL III AND BSIM MODELS
Beie unit 2
PIC Microcontrollers
Antennas - Array of point sources
ADC and DAC Best Ever Pers
Single Slope ADC.pptx
Isolator & Circulator -FT.pptx
Mosfet’s
Vlsi gate level design
Mosfet
VLSI subsystem design processes
DESIGN AND SIMULATION OF DIFFERENT 8-BIT MULTIPLIERS USING VERILOG CODE BY SA...
A PROJECT REPORT On LASER SECURITY ALARM SYSTEM
Arm cortex (lpc 2148) based motor speed
LOGIC FAMILY.pptx
Directional couplers ppt for microwave engineering
Pulse amplitude modulation & demodulation
Power power electronics (solution manual) by M.H.Rashid.pdf
180nm process typical parameter values
single stage amplifier Unit 5 AMVLSI
Publicidad

Similar a 2.4 encender led con switch (20)

PDF
2.3 encender 1 led
PDF
2.5 contador con led
PDF
3.3 display 7 segmentos con decoder
PDF
3.2 display 7 segmentos v4
PDF
⭐⭐⭐⭐⭐ (Práctica 4) DESARROLLO DE APLICACIONES CON #PIC16F886
PDF
Micro2 tema 4
PDF
1.1 introduccion al atmega 128
PDF
3.4 matriz de le ds
PDF
3.1 display 7 segmentos
PPTX
⭐⭐⭐⭐⭐ (Práctica 1) DESARROLLO DE APLICACIONES CON #PIC16F886
PDF
⭐⭐⭐⭐⭐ (Práctica 3) DESARROLLO DE APLICACIONES CON #PIC16F886
PDF
⭐⭐⭐⭐⭐ (Práctica 2) DESARROLLO DE APLICACIONES CON #PIC16F886
DOCX
Lab 01 micro
PDF
RE-10-LAB-248 MICROPROCESADORES II v6.pdf
PPTX
Practica Cableada. ESP32 es denominación
PDF
Curso de microcontroladores capitulo 03
PDF
ARDUINO - METODOLOGÍA PARA TRADUCIR AL LENGUAJE PROCESSING UN CIRCUITO E...
PDF
Construccion sonometro nov dic 16 21 pgs-joaquin
PDF
⭐⭐⭐⭐⭐ (Práctica 5) DESARROLLO DE APLICACIONES CON #PIC16F886
PDF
2.3 encender 1 led
2.5 contador con led
3.3 display 7 segmentos con decoder
3.2 display 7 segmentos v4
⭐⭐⭐⭐⭐ (Práctica 4) DESARROLLO DE APLICACIONES CON #PIC16F886
Micro2 tema 4
1.1 introduccion al atmega 128
3.4 matriz de le ds
3.1 display 7 segmentos
⭐⭐⭐⭐⭐ (Práctica 1) DESARROLLO DE APLICACIONES CON #PIC16F886
⭐⭐⭐⭐⭐ (Práctica 3) DESARROLLO DE APLICACIONES CON #PIC16F886
⭐⭐⭐⭐⭐ (Práctica 2) DESARROLLO DE APLICACIONES CON #PIC16F886
Lab 01 micro
RE-10-LAB-248 MICROPROCESADORES II v6.pdf
Practica Cableada. ESP32 es denominación
Curso de microcontroladores capitulo 03
ARDUINO - METODOLOGÍA PARA TRADUCIR AL LENGUAJE PROCESSING UN CIRCUITO E...
Construccion sonometro nov dic 16 21 pgs-joaquin
⭐⭐⭐⭐⭐ (Práctica 5) DESARROLLO DE APLICACIONES CON #PIC16F886
Publicidad

Más de SNPP (20)

PDF
proyecto electrico 1 plano de una instalacion.pdf
PDF
proyecto electrico 2 plano de una instalacion.pdf
PDF
RR00X_RESUMEN.pdf
PDF
RR_TAYI.pdf
PDF
1. panel de le ds
PDF
7. incubadora de huevos
PDF
6. visualizacion remota de consumo de agua en tiempo real
PDF
5. alimentador de animales domesticos smart feeder
PDF
3. radar medidor de velocidad
PDF
2. soft starter monofasico
PDF
Operadores y expresiones
PDF
6.2 cadenas de caracteres
PDF
6.1 vectores
PDF
5.5 instruccion for
PDF
5.4 instruccion do-while
PDF
5.3 instruccion while
PDF
5.2 instruccion switch
PDF
5.1 instruccion if-else
PDF
4. entrada y salida de datos
PDF
3.6 funciones de biblioteca
proyecto electrico 1 plano de una instalacion.pdf
proyecto electrico 2 plano de una instalacion.pdf
RR00X_RESUMEN.pdf
RR_TAYI.pdf
1. panel de le ds
7. incubadora de huevos
6. visualizacion remota de consumo de agua en tiempo real
5. alimentador de animales domesticos smart feeder
3. radar medidor de velocidad
2. soft starter monofasico
Operadores y expresiones
6.2 cadenas de caracteres
6.1 vectores
5.5 instruccion for
5.4 instruccion do-while
5.3 instruccion while
5.2 instruccion switch
5.1 instruccion if-else
4. entrada y salida de datos
3.6 funciones de biblioteca

Último (20)

PPTX
CNE-Tx-ZyD_Comite_2020-12-02-Consolidado-Version-Final.pptx
PDF
MODULO 1 Base Legal Nacional y sus aplicaciones.pdf
PPTX
TECNOLOGIA EN CONSTRUCCION PUBLICO Y PRIVADA
PDF
Diseño y Utiliación del HVAC Aire Acondicionado
PDF
UD3 -Producción, distribución del aire MA.pdf
PPTX
376060032-Diapositivas-de-Ingenieria-ESTRUCTURAL.pptx
PPTX
Riesgo eléctrico 5 REGLAS DE ORO PARA TRABAJOS CON TENSION
PDF
Presentación Ejecutiva Minimalista Azul.pdf
PPTX
Investigacioncientificaytecnologica.pptx
PDF
SESION 9 seguridad IZAJE DE CARGAS.pdf ingenieria
PDF
experto-gestion-calidad-seguridad-procesos-quimicos-industriales-gu.pdf
PPTX
TOPOGRAFÍA - INGENIERÍA CIVIL - PRESENTACIÓN
PDF
Módulo V. Tema 2. Disruptive & Transformation 2024 v.0.4.pdf
PPTX
PROCESOS DE REGULACION DE CRECIMIENTO.pptx
PPTX
ARQUITECTURA INTEGRAL EN OBRA, PRINCIPIOS BASICOS Y TERMINOS
PPTX
Cómo Elaborar e Implementar el IPERC_ 2023.pptx
PPTX
TRABAJOS DE ALTO RIESGO IZAJE Y CALIENTE.pptx
PDF
SESION 10 SEGURIDAD EN TRABAJOS CON ELECTRICIDAD.pdf
PPTX
PPT PE 7 ASOCIACIONES HUAMANGA_TALLER DE SENSIBILIZACIÓN_20.04.025.pptx
PPTX
Identificacion de Peligros mediante GTC 45
CNE-Tx-ZyD_Comite_2020-12-02-Consolidado-Version-Final.pptx
MODULO 1 Base Legal Nacional y sus aplicaciones.pdf
TECNOLOGIA EN CONSTRUCCION PUBLICO Y PRIVADA
Diseño y Utiliación del HVAC Aire Acondicionado
UD3 -Producción, distribución del aire MA.pdf
376060032-Diapositivas-de-Ingenieria-ESTRUCTURAL.pptx
Riesgo eléctrico 5 REGLAS DE ORO PARA TRABAJOS CON TENSION
Presentación Ejecutiva Minimalista Azul.pdf
Investigacioncientificaytecnologica.pptx
SESION 9 seguridad IZAJE DE CARGAS.pdf ingenieria
experto-gestion-calidad-seguridad-procesos-quimicos-industriales-gu.pdf
TOPOGRAFÍA - INGENIERÍA CIVIL - PRESENTACIÓN
Módulo V. Tema 2. Disruptive & Transformation 2024 v.0.4.pdf
PROCESOS DE REGULACION DE CRECIMIENTO.pptx
ARQUITECTURA INTEGRAL EN OBRA, PRINCIPIOS BASICOS Y TERMINOS
Cómo Elaborar e Implementar el IPERC_ 2023.pptx
TRABAJOS DE ALTO RIESGO IZAJE Y CALIENTE.pptx
SESION 10 SEGURIDAD EN TRABAJOS CON ELECTRICIDAD.pdf
PPT PE 7 ASOCIACIONES HUAMANGA_TALLER DE SENSIBILIZACIÓN_20.04.025.pptx
Identificacion de Peligros mediante GTC 45

2.4 encender led con switch

  • 1. CENTRO TECNOLÓGICO DE AVANZADA AREA DE MECATRÓNICA Código: M07 MICROCONTROLADORES II Laboratorio: D-19 Duración: 2 Hs PUERTOS COMO GPIO 2.4. Encendido de LEDs con Switch Objetivos 1. Realizar las configuraciones del ATMEGA128 para encender LED con switch. 2.4.1. Procedimiento AVR Studio 1. Configure la F_CPU a 8MHz. 2. Configure el PUERTO E como salida. 3. Configure el PUERTO D como entrada. 4. Configure el PUERTO D a PULL-UP (entrada). 5. Realice el código en C, el LED debe encender cuando el switch se mantiene pulsado, caso contrario debe permanecer apagado. #define F_CPU 8000000UL #include <avr/io.h> #include <util/delay.h> #include <avr/sfr_defs.h> int main(void) { DDRE = 0b11111111;//PUERTO E COMO SALIDA (LED) DDRD = 0b00000000;//PUERTO D COMO ENTRADA (SWITCH) PORTD = 0b11111111;//PUERTO D A PULL-UP while (1)//LOOP INFINITO { if(bit_is_clear(PIND, PIND0))//SI EL SW0 SE PULSA PORTE |= _BV(PINE0);//ENCIENDE EL LED0 else PORTE &= ~_BV(PINE0);//APAGA EL LED0 } } Pedro Ramírez <pedroramirez22@gmail.com> 1
  • 2. CENTRO TECNOLÓGICO DE AVANZADA AREA DE MECATRÓNICA Código: M07 MICROCONTROLADORES II Laboratorio: D-19 Duración: 2 Hs PUERTOS COMO GPIO Proteus 1. En el Edit Component del ATMEGA128, seleccione el CKSEL Fuses: (0100) Int. RC 8MHz. 2. En el Edit Component del ATMEGA128, seleccione el Program File el archivo .hex generado dentro de la carpeta Debug en la ruta del proyecto del AVR Studio en cuestión. 3. Simule el esquemático y compruebe que el LED enciende cuando se pulsa el switch. 2.4.2. Esquemático Realice el esquemático de la Figura 2.1 en el Proteus. PE0/RXD0/PDI 2 PE1/TXD0/PDO 3 PE2/XCK0/AIN0 4 PE3/OC3A/AIN1 5 PE4/OC3B/INT4 6 PE5/OC3C/INT5 7 PE6/T3/INT6 8 PE7/ICP3/INT7 9 PB0/SS10 PB1/SCK11 PB2/MOSI12 PB3/MISO13 PB4/OC014 PB5/OC1A15 PB6/OC1B16 PB7/OC2/OC1C17 PG3/TOSC2 18 PG4/TOSC1 19 RESET20 XTAL223 XTAL124 PD0/SCL/INT0 25 PD1/SDA/INT1 26 PD2/RXD1/INT2 27 PD3/TXD1/INT3 28 PD4/ICP1 29 PD5/XCK1 30 PD6/T1 31 PD7/T2 32 PG0/WR 33 PG1/RD 34 PC0/A835 PC1/A936 PC2/A1037 PC3/A1138 PC4/A1239 PC5/A1340 PC6/A1441 PC7/A1542 PG2/ALE 43 PA7/AD744 PA6/AD645 PA5/AD546 PA4/AD447 PA3/AD348 PA2/AD249 PA1/AD150 PA0/AD051 PF7/ADC7/TDI 54 PF6/ADC6/TDO 55 PF5/ADC5/TMS 56 PF4/ADC4/TCK 57 PF3/ADC3 58 PF2/ADC2 59 PF1/ADC1 60 PF0/ADC0 61 AREF62 AVCC64 PEN 1 U1 ATMEGA128 R1 330 D1 LED-YELLOW Figura 2.1: Encender LED por software Pedro Ramírez <pedroramirez22@gmail.com> 2
  • 3. CENTRO TECNOLÓGICO DE AVANZADA AREA DE MECATRÓNICA Código: M07 MICROCONTROLADORES II Laboratorio: D-19 Duración: 2 Hs PUERTOS COMO GPIO 2.4.3. Ejercicios propuestos 1. Realice el mismo ejercicio pero ahora conecte el LED al PUERTO A y el switch al PUERTO B. 2. Monte un circuito en Proteus con 8 switches y 8 LEDs. Cuando se pulsa un switch se enciende el LED correspondiente, es decir SW1-LED1, SW2-LED2, etc. 3. Monte un circuito en Proteus con 2 switches (MAR, PAR) y un LED. El programa debe trabajar como un circuito de enclavamiento con prioridad a la marcha. 4. Monte un circuito en Proteus con 2 switches (MAR, PAR) y un LED. El programa debe trabajar como un circuito de enclavamiento con prioridad al paro. 5. Monte un circuito en Proteus con 2 switches (A, B) y un LED. El programa debe funcionar (con los switches) con la lógica de: a) AND b) OR c) NAND d) NOR e) XOR f ) XNOR Obs: realice la tabla de verdad para verificar los resultados. 6. Realice un circuito que cuente con tres switches (A, B, C) y un LED, al presionar A el LED debe parpadear a 10Hz, al presionar B el LED debe parpadear a 5Hz y al presionar C el LED debe parpadear a 1Hz. 2.4.4. Conclusión Pedro Ramírez <pedroramirez22@gmail.com> 3