You are on page 1of 8

PROYECTO FINAL MICROS

/*
* proyecto.c
*
* Created: 14/3/2019 14:55:21
* Author : Monica Jacome
*/

EJERCICIO 1:
/*
* timers.c
*
* Created: 28/2/2019 14:55:21
* Author : David Mena
*/

#define F_CPU 8000000UL

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

void config_puertos();

int main(void)
{
config_puertos();

while (1)
{
}
}

void config_puertos()
{
DDRA=0;
PORTA=0b11111100;
DDRB=255;
PORTB=0;
DDRC=255;
PORTC=0;
DDRD=0b00110000;
PORTD=0b11001111;

EICRA|=(1<<ISC11)|(1<<ISC01);
EIMSK|=(1<<INT0)|(1<<INT1);
sei();

TCCR0A|=(1<<COM0A1)|(1<<COM0B1)|(1<<WGM01)|(1<<WGM00);
TCCR0B|=(1<<CS00);
TCNT0=0;
OCR0B=64;
OCR0A=126;
}
EJERCICIO 2:
/*
* timers.c
*
* Created: 28/2/2019 14:55:21
* Author : David Mena
*/

#define F_CPU 8000000UL

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

void config_puertos();

int main(void)
{
config_puertos();
adc_config();

while (1)
{
OCR0B=0.24*adc_value(0);
}
}

void config_puertos()
{
DDRA=0;
PORTA=0b11111100;
DDRB=255;
PORTB=0;
DDRC=255;
PORTC=0;
DDRD=0b00110000;
PORTD=0b11001111;

EICRA|=(1<<ISC11)|(1<<ISC01);
EIMSK|=(1<<INT0)|(1<<INT1);
sei();

TCCR0A|=(1<<COM0B1)|(1<<WGM02)|(1<<WGM01)|(1<<WGM00);
TCCR0B|=(1<<WGM02)|(1<<CS01)|(1<<CS00);
TCNT0=0;
OCR0A=249;
OCR0B=0;
}

void adc_config()
{
ADMUX|=(1<<REFS0);
ADCSRA|=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1);
DIDR0|=(1<<0);
}

int adc_value (int canal)


{
ADMUX&=0b11100000;
ADMUX|=(canal<<MUX0);
ADCSRA|=(1<<ADSC);
while(!((ADCSRA&(1<<ADSC))==0));
return ADCW;
}

EJERCICIO 4:
/*
* timers.c
*
* Created: 28/2/2019 14:55:21
* Author : David Mena
*/

#define F_CPU 8000000UL

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

void config_puertos();

int main(void)
{
config_puertos();
adc_config();

while (1)
{
OCR1B=0.97*adc_value(0)+1000;
}
}

void config_puertos()
{
DDRA=0;
PORTA=0b11111100;
DDRB=255;
PORTB=0;
DDRC=255;
PORTC=0;
DDRD=0b00110000;
PORTD=0b11001111;

EICRA|=(1<<ISC11)|(1<<ISC01);
EIMSK|=(1<<INT0)|(1<<INT1);
sei();

TCCR1A|=(1<<COM1B1)|(1<<WGM11)|(1<<WGM10);
TCCR1B|=(1<<WGM12)|(1<<WGM13)|(1<<CS11);
TCNT1=0;
OCR1A=19999; // TOP
OCR1B=1000; //VALOR INICIAL
}

void adc_config()
{
ADMUX|=(1<<REFS0);
ADCSRA|=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1);
DIDR0|=(1<<0);
}

int adc_value (int canal)


{
ADMUX&=0b11100000;
ADMUX|=(canal<<MUX0);
ADCSRA|=(1<<ADSC);
while(!((ADCSRA&(1<<ADSC))==0));
return ADCW;
}
CLASE MIERCOLES

PARIDAD PARA VERIFICAR ERRORES

PARIDAD PAR.-NUMERO PAR DE UNOS

PARIDAD IMPAR.- NUMERO IMPAR DE UNOS

 0 UN BIT DE PARO
 1 DOS BITS DE PARO

CHEQUEO DE ERRORES

Comunicación serial

Modos

-full dúplex

-half dúplex

-simplex

Trama:

Bit de parada

Bit de inicio

BIT DE DATOS

Bauds (bit/s): FRECUENCIA DE COMUNICACION

USART 164P: Trabaja a nivel de voltaje entre +3 y +5 V

Db9

GENERACIÓN DE RELOJ

SINCRONO

ASINCRONO.- NO NECESITA TRANSMITIR UNA SEÑAL DE RELOJ

UBRRn: UBRR1, UBRR0


Registro UCSR0B

BIT 7

BIT 6

BIT 5

UDR0 SE ESCRIBE EL DATO A RENVIAR O RECIBIR

Ejemplo:
/*
* CRISTIAN.c
*
* Created: 06/03/2019 15:13:47
* Author : SalaB-4
*/
#define F_CPU 8000000UL
#include <avr/io.h>
#include <avr/interrupt.h>

void conf_port()
{
DDRB=0b11110000;
PORTB=0b00001111;

}
void conf_usart()
{
UBRR0=51; //9600 baudios
UCSR0A=0;
UCSR0B= (1<<RXCIE0)|(1<<RXEN0)|(1<<TXEN0); //HABILITAR INTERRUPTORES
UCSR0C=(1<<USBS0)|(3<<UCSZ00);
}
ISR(USART0_RX_vect)
{
PORTB=0B00001111|(UDR0<<4);
}
void enviar(unsigned char dato)
{
/*wait for empty transmit buffer*/
while (!(UCSR0A &(1<<UDRE0)));
/*put data into buffer, send the data*/
UDR0= dato;
}
int main(void)
{
/* Replace with your application code */

{
conf_port();
conf_usart();
sei();
while(1)
{
enviar(PINB&0b00001111);

}
}
}

LCD

EJRCICIO
/*
* deberbrayan.c
*
* Created: 07/03/2019 14:47:00
* Author : SalaB-4
*/
#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

#include "lcdS.h"

uint8_t valor,aux, aux2;


float numero;

int main(void)
{
DDRB= 0b11111111;
lcd_init(LCD_DISP_ON);
lcd_clrscr();
numero=2.15;

while (1)
{
numero=numero+0,1;
valor=(uint8_t)numero;
aux2=numero*100;
aux=aux2-valor*100;
lcd_gotoxy(0,0);
lcd_puts("A:");
lcd_gotoxy(6,1);
lcd_write_value(valor,1);
lcd_gotoxy(7,1);
lcd_puts(".");
lcd_gotoxy(8,1);
lcd_write_value(aux,2);
_delay_us(100);

}
}

You might also like