Documentos de Académico
Documentos de Profesional
Documentos de Cultura
OBJETIVOS
Se usará el micro Atmega 164P, ya que posee todos los pines que necesito (17 pines), e inclusive
sobran pines, ya que posee 40 pines:
Entradas:
Salidas:
Usart:
Diagrama de flujo
Comunicación Serial
Código
/*
* Prepa2_Jauregui_C_U.c
*
* Created: 2015-10-27 14:35:02
* Author : DiegoSteve
*/
#define F_CPU 8000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
int main(void)
{
//Configuracion de Puertos de Entrada
DDRA=255;
DDRC=(1<<DDC0)|(1<<DDC1)|(1<<DDC2);//Para la activacion de los displays
DDRB=(0<<DDB0);//Pin B0 como entrada
PORTB=(1<<PB0);
serial();
//interrupcion();
sei();//Activo Interrupciones Globales
while(1)
{
envio=PINB;
transmitir_dato(envio);
contador();
barrido();
}
}
void serial()
{
// f= 8mhz, ux2n=1, error 0.2%
UBRR0=51;
UCSR0A = 0;
UCSR0B=0b10011000;
UCSR0C=0b00000110;
}
void contador()
{
if (tempo<255)
{
if (recepcion==1)
{
tempo++;
_delay_ms(500);
}
else
{
tempo--;
_delay_ms(500);
}
}
else
{
tempo=0;
}
}
void barrido()
{
centenas=tempo/100;
aux=tempo%100; //"%" residuo de division
decenas=aux/10;
unidades=aux%10;
PORTA=tabla[unidades];
PORTC=(1<<PC0)|(0<<PC1)|(0<<PC2);
_delay_ms(100);
PORTA=tabla[decenas];
PORTC=(0<<PC0)|(1<<PC1)|(0<<PC2);
_delay_ms(100);
PORTA=tabla[centenas];
PORTC=(0<<PC0)|(0<<PC1)|(1<<PC2);
_delay_ms(100);
}
ISR(USART0_RX_vect)
{
while(!(UCSR0A & (1<<RXC0)));
recepcion=UDR
Simulación en Proteus:
U1
40 37
PB0/XCK0/T0/PCINT8 PA0/ADC0/PCINT0
41 36
PB1/T1/CLKO/PCINT9 PA1/ADC1/PCINT1
42 35
PB2/AIN0/INT2/PCINT10 PA2/ADC2/PCINT2
43 34
PB3/AIN1/OC0A/PCINT11 PA3/ADC3/PCINT3
44 33
PB4/SS/OC0B/PCINT12 PA4/ADC4/PCINT4
1 32
PB5/MOSI/PCINT13 PA5/ADC5/PCINT5
2 31
PB6/MISO/PCINT14 PA6/ADC6/PCINT6
3 30
PB7/SCK/PCINT15 PA7/ADC7/PCINT7
9 19
PD0/RXD0/PCINT24 PC0/SCL/PCINT16
10 20
PD1/TXD0/PCINT25 PC1/SDA/PCINT17
11 21
PD2/INT0/RXD1/PCINT26 PC2/TCK/PCINT18
12 22
P1 PD3/INT1/TXD1/PCINT27 PC3/TMS/PCINT19
13 23
PD4/OC1B/XCK1/PCINT28 PC4/TDO/PCINT20
14 24
PD5/OC1A/PCINT29 PC5/TDI/PCINT21
1 15 25
DCD PD6/ICP/OC2B/PCINT30 PC6/TOSC1/PCINT22
6 16 26
DSR PD7/OC2A/PCINT31 PC7/TOSC2/PCINT23
2
RXD
7 29 8
RTS AREF XTAL1
3 27 7
TXD AVCC XTAL2
8 4
CTS RESET
4
DTR
9 ATMEGA164P
RI
ERROR
COMPIM
Simulación en LabVIew:
Bibliografía:
[2] National Instruments, «National Instruments: Comunicacion serial con Labview,» [En
línea]. Available: http://www.ni.com/white-paper/7907/es/. [Último acceso: 06 10 2015].