Академический Документы
Профессиональный Документы
Культура Документы
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
A. OBJETIVO GENERAL
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.
B. OBJETIVOS ESPECIFICOS.
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
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
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
// lcd
// lcd
lcd_write_4(lcd_FunctionSet4
bit);
// set 4-bit mode
_delay_us(80);
// 40uS delay (min)
// lcd
#define lcd_E_port
Enable pin
#define lcd_E_bit
#define lcd_E_ddr
PORTD
// lcd
PORTD1
DDRD
// 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)
{
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.
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;
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
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
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;
}
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;
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
Figure 11
Figure 8
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
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.
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