Вы находитесь на странице: 1из 10

UNIVERSIDAD NACIONAL DE

CHIMBORAZO
FACULTAD DE INGENIERA
ESCUELA DE ELECTRNICA Y TELECOMUNICACIONES
CATEDRA MICROPROCESADORES Y LAB.
PROYECTO FINAL DE MICROPROCESADORES
Hctor Cajilema
javi88@hotmail.es
Javier LoLpez
hector55@hotmail.es

Tema: Motor Led RGB, Sensor de


Temperatura mediante Atmel Studio 6.2 y
Arduino con el Atmega 328.
ResumenEn este informe muestra el
diseo e implementacin del motor led con
RGB de la palabra PARADA que ser
programado
mediante
el
software
AVRStudio 6.2, tambin se realizara un
sensor de temperatura mediante Arduino y
AVR Studio los tres sern programados con
el Atmega 328.

A. OBJETIVO GENERAL

Realizar Un Motor Led, Sensor De


Temperatura Mediante Atmel Studio
6.2 Y Arduino Con El Atmega 328.

I. MARCO TEORICO
PIC ATmega328P
Microcontrolador de 8 bits basados en los
procesadores AVR., 23 pines I/O
disponibles, memoria de programa flash 32
kB, SRAM 2 kB, EEPROM de datos 1 kB,
ADC de 10 bits y 6 canales, 3
timers/comparadores/contadores, 6 canales
PWM, programador de modo USART, SPI
puerto serial, TWI (I2C compatible),
comparador anlogo, "watchdog timer"
programable con oscilador interno, y cinco
modos de ahorro de energa seleccionables
por software.

Figure 1_Pic Atmega328

B. OBJETIVOS ESPECIFICOS.

Realizar la respectiva programacin


mediante el hardware AVR Studio
6.2.
Probar la programacin en el
simulador Proteus.
Quemar y comprobar en el pic
Atmega328
el
correcto
funcionamiento de la programacin
y simulacin.
Proceder a sacar las respectivas
conclusiones.

El dispositivo opera entre 1.8 y 5.5 voltios.


Por medio de la ejecucin de poderosas

instrucciones en un solo ciclo de reloj, el


dispositivo alcanza una respuesta de 1
MIPS, balanceando consumo de energa y
velocidad de proceso.
Figure 2_Puertos

Registros del CPU


Cada registro 4ene asignada una direccin
en memoria.
Se utilizan las primeras 32 localidades del
espacio de memoria para datos.
Los registros X, Y y Z se utilizan tambin
como apuntadores de 16 bits.
Caractersticas elctricas

Arquitectura RISC
Operacin entre 1.8 y 5.5 voltios
131 instrucciones
32 registros de propsito general
1 Kbyte de EEPROM
Proteccin de cdigo programable
Cumple directivas RoHS
Encapsulado PDIP de 28 pines

Figure 4_lcd

Las siglas LCD significan Liquid Cristal


Display pantalla de cristal lquido. Es una
pantalla plana basada en el uso de una
sustancia liquida atrapada entre dos placas
de vidrio, haciendo pasar por este una
corriente elctrica a una zona especfica,
para que as esta se vuelva opaca, y adems
cuenta (generalmente) con iluminacin
trasera.

Figure 3_Mikroc

LCD

Figure 5_carateristicas_LCD

II. PROCEDIMIENTO
a) PROGRAMACION
AVR STUDIO 6.2
Programacin En Ensamblador Del
Motor Led Con La Palabra PARADA.
.include <m328def.inc>
.def Temp1 = r17
.def Temp2 = r18
.def Temp3 = r19
.def data = r20
.def byte = r21
.equ INPUT = 0x00 ;
.equ OUTPUT = 0xFF ;
.org 0x0000
rjmp RESET ; Reset Handler
reti
loop_for_ever:
rjmp loop_for_ever
RESET1:
ldi r16, high(RAMEND); Main program start
out SPH,r16 ; Set Stack Pointer to top of RAM
ldi r16, low(RAMEND)
out SPL,r16
sei ; Enable interrupts

;-------------------------------------------------------------delay500ms:
;-*****CALCULADO 8MHZ*****************
; delay loop generator
; 80000 cycles:
; ----------------------------; delaying 7998 cycles:
ldi temp1, $1F
WGLOOP0: ldi temp2, $55
WGLOOP1: dec temp2
brne WGLOOP1
dec temp1
brne WGLOOP0
; ----------------------------; delaying 2 cycles:
nop
nop
; =============================

ret
;--------------------------------------------------------------

RESET:
ldi Temp1, low(RAMEND)
out SPL, Temp1
ldi Temp1, high(RAMEND)
out SPH, Temp1
ldi temp1,0xFF
out DDRB,temp1
out DDRC,temp1
out DDRD,temp1
sei
;
******************************************
**
; Bucle Principal
;
******************************************
**
final:
;P
call delay500ms
ldi temp1,0b1111110
out portb,temp1

call delay500ms
ldi temp1,0b0001001
out portb,temp1
call delay500ms
ldi temp1,0b0001001
out portb,temp1
call delay500ms
ldi temp1,0b1111110
out portb,temp1
call delay500ms
;R
call delay500ms
ldi temp1,0b1111110
out portb,temp1
call delay500ms
ldi temp1,0b0010001
out portb,temp1
call delay500ms
ldi temp1,0b0010001
out portb,temp1
call delay500ms
ldi temp1,0b0101001
out portb,temp1
call delay500ms
ldi temp1,0b1000110
out portb,temp1
call delay500ms
ldi temp1,$00
out portb,temp1
call delay500ms
call delay500ms
;A
call delay500ms
ldi temp1,0b1111110
out portb,temp1
call delay500ms
ldi temp1,0b0001001
out portb,temp1
call delay500ms
ldi temp1,0b0001001
out portb,temp1
call delay500ms
ldi temp1,0b0001001
out portb,temp1
call delay500ms
ldi temp1,0b1111110
out portb,temp1
call delay500ms
ldi temp1,$00
out portb,temp1
call delay500ms
call delay500ms
;D
call delay500ms
ldi temp1,0b1111111
out portb,temp1
call delay500ms
ldi temp1,0b1000001
out portb,temp1
call delay500ms
ldi temp1,0b1000001
out portb,temp1
call delay500ms
ldi temp1,0b0100010
out portb,temp1
call delay500ms
ldi temp1,0b0011100
out portb,temp1

call delay500ms
ldi temp1,0b0010001
out portb,temp1
call delay500ms
ldi temp1,0b0010001
out portb,temp1
call delay500ms
ldi temp1,0b0010001
out portb,temp1
call delay500ms
ldi temp1,0b0001110
out portb,temp1
call delay500ms
ldi temp1,$00
out portb,temp1
call delay500ms
call delay500ms

call delay500ms
ldi temp1,$00
out portb,temp1
call delay500ms
call delay500ms
;A
call delay500ms
ldi temp1,0b1111110
out portb,temp1
call delay500ms
ldi temp1,0b0001001
out portb,temp1
call delay500ms
ldi temp1,0b0001001
out portb,temp1
call delay500ms
ldi temp1,0b0001001
out portb,temp1
call delay500ms
ldi temp1,0b1111110
out portb,temp1
call delay500ms
ldi temp1,$00
out portb,temp1
call delay500ms
call delay500ms

;A
call delay500ms
ldi temp1,0b1111110
out portb,temp1
call delay500ms
ldi temp1,0b0001001
out portb,temp1
ldi temp1,$00
out portb,temp1
call delay500ms
call delay500ms

Programacin En AVR Studio6.2 Mikroc


Del Sensor De Temperatura.
/*
* LCD_4.c
*
* Created: 31/07/2015 19:46:18
* Author: User
*/
#define F_CPU 16000000UL

// Reset the LCD controller

lcd_write_4(lcd_FunctionRes
et);
// first part of
reset sequence

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
// LCD interface (should agree with the diagram
above)
// make sure that the LCD RW pin is
connected to GND
#define lcd_D7_port PORTD
// lcd
D7 connection
#define lcd_D7_bit
PORTD7
#define lcd_D7_ddr DDRD

lcd_write_4(lcd_FunctionRes
et);
// second part of
reset sequence
_delay_us(200);
// 100uS delay (min)

lcd_write_4(lcd_FunctionRes
et);
// third part of
reset sequence
_delay_us(200);
// this delay is omitted in the
data sheet

#define lcd_D6_port PORTD


D6 connection
#define lcd_D6_bit
PORTD6
#define lcd_D6_ddr DDRD

// lcd

#define lcd_D5_port PORTD


D5 connection
#define lcd_D5_bit
PORTD5
#define lcd_D5_ddr DDRD

// lcd

lcd_write_4(lcd_FunctionSet4
bit);
// set 4-bit mode
_delay_us(80);
// 40uS delay (min)

#define lcd_D4_port PORTD


D4 connection
#define lcd_D4_bit
PORTD4
#define lcd_D4_ddr DDRD

// lcd

// Function Set instruction

#define lcd_E_port
Enable pin
#define lcd_E_bit
#define lcd_E_ddr

PORTD

// lcd

PORTD1
DDRD

#define lcd_RS_port PORTD


Register Select pin
#define lcd_RS_bit
PORTD0
#define lcd_RS_ddr DDRD
// LCD module information
#define lcd_LineOne 0x00
of line 1
#define lcd_LineTwo 0x40
of line 2

// lcd

// start
// start

lcd_write_instruction_4d(lcd_
FunctionSet4bit); // set
mode, lines, and font
_delay_us(80);
// 40uS delay (min)
//
lcd_write_instruction_4d(lcd_
DisplayOff);
// turn
display OFF
_delay_us(80);
// 40uS delay (min)
// Clear Display instruction

lcd_write_instruction_4d(lcd_
Clear);
// clear display

// LCD instructions
#define lcd_Clear
0b00000001
//
replace all characters with ASCII 'space'
#define lcd_Home
0b00000010
//
return cursor to first position on first line
#define lcd_EntryMode
0b00000110
//
shift cursor from left to right on read/write
#define lcd_DisplayOff
0b00001000
//
turn display off
#define lcd_DisplayOn
0b00001100
//
display on, cursor off, don't blink character
#define lcd_FunctionReset 0b00110000
//
reset the LCD
#define lcd_FunctionSet4bit 0b00101000
//
4-bit data, 2-line display, 5 x 7 font
#define lcd_SetCursor
0b10000000
//
set cursor position
//****************************************
************************
#include <avr/io.h>
#define PORT_ON(port,pin) port |= (1<<pin)
#define PORT_OFF(port,pin) port &=
~(1<<pin)

// Program ID
uint8_t visual1[] = "SEN TEMPERATURA";
//***********************
uint8_t visual2[] = " REF:25 GRADOS";
uint8_t ch ;
// Function Prototypes
void lcd_write_4(uint8_t);
void lcd_write_instruction_4d(uint8_t);
void lcd_write_character_4d(uint8_t);
void lcd_write_string_4d(uint8_t *);
void lcd_init_4d(void);

/******************************* Main
Program Code *************************/
int main(void)
{

// configure the microprocessor pins for the data


lines
lcd_D7_ddr |= (1<<lcd_D7_bit);
// 4
data lines - output
lcd_D6_ddr |= (1<<lcd_D6_bit);
lcd_D5_ddr |= (1<<lcd_D5_bit);
lcd_D4_ddr |= (1<<lcd_D4_bit);
// configure the microprocessor pins for the
control lines
lcd_E_ddr |= (1<<lcd_E_bit);
// E
line - output
lcd_RS_ddr |= (1<<lcd_RS_bit);
//
RS line - output
// initialize the LCD controller as determined by
the defines (LCD instructions)
lcd_init_4d();
// initialize
the LCD display for a 4-bit interface
// display the first line of information
lcd_write_string_4d(visual1);
//******************11111111111111
// set cursor to start of second line
lcd_write_instruction_4d(lcd_SetCursor |
lcd_LineTwo);
_delay_us(80);
// 40 uS delay
(min)
// display the second line of information
lcd_write_string_4d(visual2);

lcd_write_instruction_4d(lcd_SetCursor |
lcd_LineTwo);
_delay_us(80);
lcd_write_character_4d(ch);

RAM
_delay_ms(4);
// 1.64 mS delay (min)
// ; Entry Mode Set
instruction

lcd_write_instruction_4d(lcd_
EntryMode);
// set
desired shift characteristics
_delay_us(80);
// 40uS delay (min)
// This is the end of the LCD
controller initialization as
specified in the data sheet,
but the display
// has been left in the OFF
condition. This is a good time
to turn the display back ON.

// Display On/Off Control


instruction

lcd_write_instruction_4d(lcd_
void lcd_init_4d(void)
{
// Power-up delay
_delay_ms(100);
// initial 40 mSec delay
// Set up the RS and E lines
for the 'lcd_write_4'
subroutine.
lcd_RS_port &=
~(1<<lcd_RS_bit);
//
select the Instruction Register
(RS low)
lcd_E_port &=
~(1<<lcd_E_bit);
//
make sure E is initially low

// endless loop
///*********************ADC**************
*****************
//**********************ADC*************
*******************
unsigned int adc_value; // Variable to hold
ADC result

long tlong;

DDRB=0xff; // Set Port D as Output


PORTB = 0x00;

ADCSRA = (1<<ADEN) | (1<<ADPS2) |


(1<<ADPS0);
// ADEN: Set to turn on ADC , by default it is
turned off
//ADPS2: ADPS2 and ADPS0 set to make
division factor 32
ADMUX=0x05; // ADC input channel set to
PC5

while (1)
{
ADCSRA |= (1<<ADSC); // Start
conversion
while (ADCSRA &
(1<<ADSC)); // wait for conversion to complete
adc_value = ADCW; //Store ADC
value

_delay_ms(10);
// 4.1 mS delay (min)
DisplayOn);
// turn the
display ON
_delay_us(80);
// 40uS delay (min)
}

void
lcd_write_string_4d(uint8_t
theString[])
{
volatile int i = 0;
// character counter*/
while (theString[i] != 0)
{

lcd_write_character_4d(theSt
ring[i]);
i++;
_delay_us(80);
// 40 uS delay (min)
}
}

void
lcd_write_character_4d(uint8
_t theData)
{
lcd_RS_port |=
(1<<lcd_RS_bit);
//
select the Data Register (RS
high)
lcd_E_port &=
~(1<<lcd_E_bit);
//
make sure E is initially low
lcd_write_4(theData);
// write the upper 4-bits of the
data
lcd_write_4(theData << 4);
// write the lower 4-bits of the
data

void
lcd_write_instruction_4d(uint
8_t theInstruction)
{
lcd_RS_port &=
~(1<<lcd_RS_bit);
//
select the Instruction Register
(RS low)
lcd_E_port &=
~(1<<lcd_E_bit);
//
make sure E is initially low

tlong = (long)adc_value * 1000;


tlong = tlong / 1023;

if ( tlong <= 50)


{
PORT_ON
(PORTB,6); //**ENCIENDE FOCO****

PORT_OFF(PORTB,7); // ***APAGA
VENTILADOR***

}
else
{

PORT_ON(PORTB,7); // ***ENCIENDE
VENTILADOR***
PORT_OFF
(PORTB,6); //**APAGA FOCO****
}
}
while(1);
return 0;
}

/******************************* End of
Main Program Code ******************/
/*============================== 4-bit
LCD Functions ======================*/
/*
Name: lcd_init_4d
Purpose: initialize the LCD module for a 4-bit
data interface
Entry: equates (LCD instructions) set up for
the desired operation
Exit: no parameters

lcd_write_4(theInstruction);
// write the upper 4-bits of the
data
lcd_write_4(theInstruction
<< 4);
// write the
lower 4-bits of the data
}

void lcd_write_4(uint8_t
theByte)
{
lcd_D7_port &=
~(1<<lcd_D7_bit);
// assume that data is '0'
if (theByte & 1<<7)
lcd_D7_port |=
(1<<lcd_D7_bit); // make
data = '1' if necessary
lcd_D6_port &=
~(1<<lcd_D6_bit);
// repeat for each data bit
if (theByte & 1<<6)
lcd_D6_port |=
(1<<lcd_D6_bit);
lcd_D5_port &=
~(1<<lcd_D5_bit);
if (theByte & 1<<5)
lcd_D5_port |=
(1<<lcd_D5_bit);
lcd_D4_port &=
~(1<<lcd_D4_bit);
if (theByte & 1<<4)
lcd_D4_port |=
(1<<lcd_D4_bit);
// write the data

// 'Address set-up time' (40


nS)
lcd_E_port |=
(1<<lcd_E_bit);
//
Enable pin high
_delay_us(1);
// implement 'Data set-up
time' (80 nS) and 'Enable
pulse width' (230 nS)
lcd_E_port &=
~(1<<lcd_E_bit);
//
Enable pin low
_delay_us(1);
// implement 'Data hold time'
(10 nS) and 'Enable cycle
time' (500 nS)
}

Notes: uses time delays rather than checking


the busy flag
*/

comp=Serial.read();
switch (comp){
case'A':
digitalWrite(foco,LOW);
digitalWrite(motor,LOW);
break;
case'M':
//digitalWrite(led,LOW);
digitalWrite(motor,HIGH);
if (pot<tem)
{
digitalWrite(foco,HIGH);
//digitalWrite(motor,LOW);
}
else
{
digitalWrite(foco,LOW);
//digitalWrite(motor,HIGH);
}
break;
case 'F':
digitalWrite(foco,HIGH);
//digitalWrite(motor,LOW);
if (pot<tem)
{
//digitalWrite(led,HIGH);
digitalWrite(motor,LOW);
}
else
{
//digitalWrite(led,LOW);
digitalWrite(motor,HIGH);
}
break;
}

Programacin En Arduino Del Sensor De


Temperatura.
//***SENSOR TEMPERATURA*******************

lcd.setCursor(0,0);
lcd.print("VOL_REF ");
lcd.print("VOL_TEMP ");
lcd.setCursor(1,1);
lcd.print((float)var1);
lcd.setCursor(9,9);
lcd.print(var2);

#include <LiquidCrystal.h>
int foco=13;
int motor=12;

int var_pot = A2;


int var_temp = A1;
char comp;
float pot = 0;
float tem = 0;
float var1 = 1;
float var2=0;

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

void setup()
{
pinMode(foco, OUTPUT);
pinMode(motor, OUTPUT);
lcd.begin(16, 2);
Serial.begin(9600);
///LEER DATOS....TRANS*****************
}

void loop ()
{
pot = analogRead(var_pot);
tem = analogRead(var_temp);

var1=(5*tem)/1024;
var2=(5*pot)/1024;

SIMULACION PROTEUS
Como Se Puede Apreciar En La Fig.6 Tenemos
El Diagrama De Nuestro Circuito En Proteus
Del Motor Led.

Figure 9

Figure 6

Figure 10

Figure 7

En La Fig.8 Tenemos El Sensor De


Temperatura Programado En AVR
Studio Mikroc.

Figure 11

Figure 8

Tenemos Nuestra SIMULACION En


Arduino De Nuestro Sensor De
Temperatura.

Figure 15

Figure 12

Figure 16

Figure 13

Figure 17

Figure 14

CIRCUITO ARMADO

Figure 18

Figure 19
Figure 22

II.

Figure 20

Figure 21

III.

CONCLUSIONES

La programacin de nuestro motor led


en ensamblador funciono correctamente
conforme
a
lo
requerido.

Para una mejor apreciacin de nuestra


palabra PARADA, tuvimos que calibrar
bien el tiempo a 500ms.

Tuvimos que instalar unas libreras del


LCD para poderlo utilizar, ya uqe sin
ellas no funciona.

En la programacin en Mikroc del


sensor
de
temperatura
tuvimos
complicaciones ya que algunas libreras
no nos funcionaban.

En la comunicacin serial programado


en Arduino hay que habilitar los puertos
del RX y TX para poderlos utilizar.

RECOMMENDACIONES
Instalar los drivers del quemador del
Atmega 328 en una PC de 32bits ya que
en la de 64bits no funciona.
Se recomienda utilizar cuidadosamente
el LCD debido a que si se hace un corto
se quemara.

Recomendamos simular antes de armar


el circuito del filtro.

Ubicar correctamente el Pic Atmega 328


al momento de quemar para evitar la
prdida del mismo.
No sobrepasar el voltaje del Pic ya que
si se lo hace se echara a perder.

VI.

yori.mxl.uabc.mx/wpcontent/plugins/download.../do
wnload.php?id=32
http://www.mikroe.com/chapter
s/view/82/capitulo-4ejemplos/#c4v12

ANEXOS

DATASHEEF

IV.

BIOGRAFIA
HECTOR CAJILEMA
Estudiante de la
Escuela
de
Ingeniera
en
Electrnica
y
Telecomunicaciones de la Universidad
Nacional de Chimborazo (Riobamba),
desde el ao 2010-2011 graduado como
Bachiller Tcnico en Electrnica de
Consumo en el Instituto Tecnolgico
Superior Carlos Cisneros.
JAVIER LPEZ
Estudiante de la Escuela de Ingeniera
en Electrnica y Telecomunicaciones de
la Universidad Nacional de Chimborazo
(Riobamba), desde el ao 2011-2012
graduado como Bachiller Tcnico en
Electrnica en el Instituto Tecnolgico
Superior Carlos Cisneros.

V.

REFERENCIAS

www.youtube.com/watch?
v=d_RL5g-bzGI
proyectoaulapic16f628a.blogspot.com/
proyectoselectronicoos.blogspot
.com/2013/01/matriz-de-leds7x5.html
https://es.wikipedia.org/wiki/At
mega328
www.atmel.com/images/doc816
1.pdf

PLACAS DEL MOTOR LED RGB

Вам также может понравиться