Commit bd73c49a authored by Leandro Lanzieri's avatar Leandro Lanzieri

agrego proyecto de prueba uart

parent 3b53c76d
......@@ -6,5 +6,5 @@ RemoteSystemsTempFiles/
# Reglas para ignorar compilaciones
Debug/
Release/
.project/
.cproject/
.project
.cproject
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Remoto-con-8</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
<nature>de.innot.avreclipse.core.avrnature</nature>
</natures>
</projectDescription>
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Modulo_Luces</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
<nature>de.innot.avreclipse.core.avrnature</nature>
</natures>
</projectDescription>
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Modulo_On_Off</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
<nature>de.innot.avreclipse.core.avrnature</nature>
</natures>
</projectDescription>
/*
* configuracion.h
*
* Created on: 1 de dic. de 2015
* Author: Leandro
*/
#ifndef CONFIGURACION_H_
#define CONFIGURACION_H_
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <stdio.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#define FOSC 8000000 // Frecuencia de oscilacion
#define BAUD 9600 // Baud Rate
#define UBRRREG FOSC/16/BAUD-1 // El reultado debe ser el numero del registro UBRR para tener BAUD
#endif /* CONFIGURACION_H_ */
/*
* hardware.h
*
* Created on: 1 de dic. de 2015
* Author: Leandro
*/
#ifndef HARDWARE_H_
#define HARDWARE_H_
/**************************************Definiciones para Manejo de a bit**********************************/
typedef struct
{
unsigned char B0:1;
unsigned char B1:1;
unsigned char B2:1;
unsigned char B3:1;
unsigned char B4:1;
unsigned char B5:1;
unsigned char B6:1;
unsigned char B7:1;
}BIT;
#define REGBIT(reg,bt) ((volatile BIT*)&reg)->B##bt //MACRO PARA MANEJAR REGISTROS DE A BIT.
/*********************************************************************************************************/
#define LED_PORT PORTD
#define LED_PIN 7
#define LED_DDR DDRD
#define LED REGBIT(PORTD, 7)
#endif /* HARDWARE_H_ */
/*
* main.c
*
* Created on: 1 de dic. de 2015
* Author: Leandro
* @brief: El programa pretende hacer un uso basico de la USART del Atmega8. Dar un ejemplo
* de su inicializacion y utilizacion.
*/
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <stdio.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include "hardware.h"
#include "configuracion.h"
#include "mcu.h"
int main (void) {
inicializarTodo();
while(1){
// Si se recibe el caracter A por UART, se hace toggle al led
if(recibirUART() == 'A')
LED ^= 1;
}
return 0;
}
/*
* mcu.c
*
* Created on: 1 de dic. de 2015
* Author: Leandro
*/
#include "mcu.h"
#include "hardware.h"
#include "configuracion.h"
void inicializarTodo() {
inicializarUART();
inicializarGPIO();
sei(); // Habilita interrupciones
}
void inicializarGPIO(void) {
LED_DDR |= (1 << LED_PIN); // Led como salida
}
void inicializarUART() {
/* Configura el Baud Rate - ver configuracion.h */
UBRRH = (unsigned char) (UBRRREG >> 8);
UBRRL = (unsigned char) UBRRREG;
/* Habilita recepcion y transmision */
UCSRB = (1 << RXEN) | (1 << TXEN);
/* Comunicacion de 8 bits, 2 bits stop */
UCSRC = (1 << URSEL) | (1 << USBS) | (3 << UCSZ0);
}
/* Funciones UART */
void transmitirUART(unsigned char dato) {
/* Espero a que este libre el buffer */
while(! (UCSRA & (1<<UDRE)));
/* Coloco el dato en el buffer */
UDR = dato;
}
unsigned char recibirUART(void) {
/* Espero a que este recibido el dato */
while(! (UCSRA & (1<<RXC)));
/* Devuelvo el dato */
return UDR;
}
unsigned char disponibleUART(void) {
return (! (UCSRA & (1<<RXC)));
}
/*
* mcu.h
*
* Created on: 1 de dic. de 2015
* Author: Leandro
*/
#ifndef MCU_H_
#define MCU_H_
/* Funciones de Inicializacion */
void inicializarTodo(void);
void inicializarUART(void);
void inicializarGPIO(void);
/* Funciones de UART */
void transmitirUART(unsigned char);
unsigned char recibirUART(void);
unsigned char disponibleUART(void);
#endif /* MCU_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment