Академический Документы
Профессиональный Документы
Культура Документы
Directriz
Descripcin
BYTE
CSEG
Segmento de Cdigo
CSEGSIZE
DB
DEF
DSEG
Segmento de datos
DW
ENDM, ENDMAKRO
Endmacro
EQU
ESEG
Segmento EEPROM
SALIDA
Salir de archivo
CONTENER
LISTA
LISTMAC
MACRO
Comience Macro
NOLIST
ORG
SET
ELSE, ELIF
Ensamblaje condicional
TERMINARA SI
Ensamblaje condicional
ERROR
Ensamblaje condicional
MENSAJE
DD
DQ
UNDEF
ADVERTENCIA
OVERLAP / NOOVERLAP
Nota
Tenga en cuenta que todas las directivas deben ir precedidos por un punto.
Los recursos de las reservas directiva BYTE memoria en la SRAM o EEPROM. Con el fin de ser capaz de
hacer referencia a la ubicacin reservada, la directiva BYTE debe ir precedida de una etiqueta. La
directiva toma un parmetro, que es el nmero de bytes para reservar. La directiva no se puede
utilizar dentro de un segmento de cdigo (ver directivas ESEG, CSEG, DSEG) .Nota que se debe dar
un parmetro. No se inicializan Los bytes asignados.
Sintaxis:
ETIQUETA: expresin .BYTE
Ejemplo:
.DSEG
var1: .BYTE 1; reservar 1 byte a var1
tabla: tab_size .BYTE; bytes tab_size reserva
.CSEG
r30 LDI, baja (Q1); Cargar Z registro bajo
r31 LDI, alta (Q1); Cargar Z registro de alta
r1 ld, Z; Cargar VAR1 en el registro 1
.CSEG
consts: .DB 0, 255, 0b01010101, -128, 0xAA
.ESEG
const2: .DB 1,2,3
.UNDEF Var1
.def Var2 = R16; R16 ahora puede ser reutilizado sin previo aviso.
.CSEG
varlist: .DW 0, 0xffff, 0b1001110001010101, -32.768, 65.535
.ESEG
eevarlst: .DW 0,0xffff, 10
.CSEG
varlist: .Dd 0, 0xfadebabe, -2147483648, 1 << 30
.ESEG
eevarlst: 0,0xfadebabedeadbeef .DQ, 1 << 62
.IFDEF DEBUG
.message "Depuracin .."
.ELSE
.message "Release .."
.TERMINARA SI
.IFNDEF DEBUG
.message "Release .."
.ELSE
.message "Depuracin .."
.TERMINARA SI
.IFDEF TOBEDONE
.ERROR "Still cosas que hacer .."
.TERMINARA SI
Ejemplo:
.IFDEF EXPERIMENTAL_FEATURE
.WARNING "Esto no est bien probado, utilice por cuenta y riesgo."
.TERMINARA SI
; iodefs.asm:
.equ SREG = 0x3F; Registro de estado
.equ Sphigh = 0x3e; Pila puntero alta
.equ Splow = 0x3D; Pila puntero baja
; incdemo.asm
.MACRO SET_BAT
.IF @ 0> 0x3F
.message "Direccin mayor que 0x3F"
lds @ 2, @ 0
sbr @ 2, (1 << @ 1)
pts @ 0, @ 2
.ELSE
.message "Direccin menor o igual 0x3F"
.TERMINARA SI
.ENDMACRO
.LISTMAC
Ejemplo:
.IFDEF DEBUG
.message "Modo de depuracin"
.TERMINARA SI
.NOLIST
Ejemplo:
.SET FOO = 0x114; establecer FOO para que apunte a una ubicacin SRAM
lds r0, FOO; ubicacin de carga en r0
.SET FOO FOO = + 1; incremento (redefinir) FOO. Esto sera ilegal si se utiliza .equ
lds r1, FOO; cargar prxima ubicacin en r1
generan. Esto es totalmente independiente de lo que se establece mediante los #pragma directivas. El
atributo de superposicin-permitido permanecer en efecto a travs de directivas .org, pero no va a
seguir a travs de .cseg / .eseg / .dseg directivas (cada segmento marcado por separado).
Sintaxis:
.OVERLAP
.NOOVERLAP
Ejemplo:
.overlap
.org 0; seccin 1
rjmp por defecto
.nooverlap
.org 0; seccin 2
rjmp REINICIAR; No hay error dado aqu
.org 0; la seccin # 3
rjmp REINICIAR; Error aqu porque se solapan con # 2
Macros Asamblea
http://www.avrtutorials.com/projects/avrmicrocontroller-based-projects
Qu es un Macros?
En la programacin de ensamblaje de una macro es bsicamente un conjunto de
instrucciones representado por una sola sentencia. Una macro puede ser visto como una
nueva instruccin creado por el programador para el microcontrolador.
Tenga en cuenta sin embargo que esta nueva instruccin (la macro) se crea mediante el
uso de las instrucciones existentes que se proporcionan con el microcontrolador AVR.
Digamos que usted quiere inicializar el puntero de pila AVR. Se necesitaran cuatro (4)
instrucciones para realizar esta tarea, como se muestra en el cdigo ensamblador AVR
SPH, R16
Ahora, en lugar de escribir los cuatro (4) de instrucciones para inicializar el puntero de pila
AVR puede definir una macro, decir LSP, con estas instrucciones y utilizar esta macro
para reemplazar el conjunto de la instruccin como se muestra en el cdigo
ensamblador AVR continuacin.
; Inicializar la pila
LSP R16, RAMEND
LSP
LDI @ 0, baja (@ 1)
OUT
SPL, @ 0
LDI @ 0, alta (@ 1) OUT
SPH, @ 0. ENDMAKRO
Una vez que haya definido su macro se puede utilizar como cualquier otra de las
instrucciones de microcontroladores AVR. A continuacin se muestra como se puede
utilizar la macro simplemente definir arriba.Ntese aqu que @ 0 y @ 1 ser sustituido
por R16 y RAMEND, respectivamente, en la definicin de la macro.
LSP R16, RAMEND
AVR Tutoriales espera este tutorial montaje sobre escribiendo macros montaje AVR fue
beneficioso para usted y espera con inters sus continuas visitas para todas sus
necesidades de tutora microcontrolador.
Nota Importante: Para que nuestro reloj digital para que funcione correctamente el
oscilador interno del microcontrolador ATmega16 AVR debe estar habilitado y se puso a 4
MHz.
A continuacin se muestra la ejecucin AVR C de todo el cdigo para el reloj digital LCD
basada ATmega16. El cdigo fue implementado y construido con AVR
Studio 5. Recurdese que el reloj interno del microcontrolador ATmega16 debe estar
habilitado y programado para funcionar a 4 MHz para el cdigo AVR C para funcionar
correctamente. Un video del reloj digital LCD en la operacin se presenta al final de esta
pgina.
/ *
* LCD-Digital-Clock.c
*
* Escrito en AVR Studio 5
* Compilador: AVR GNU C Compiler (GCC)
*
* Creado: 12/22/2011 6:34:36 PM
* Autor: AVR Tutoriales
* Sitio web: www.AVR-Tutorials.com
* /
#define F_CPU 4000000UL
#include <avr / delay.h>
#include <avr / io.h>
#include <string.h>
#include <avr / interrupt.h>
/ * Variables globales Declaraciones * /
unsigned Char horas = 0;
sin firmar Char minutos = 0;
sin firmar Char segundo = 0;
Char tiempo [] = "00:00:00";
/ * Declaraciones de funciones LCD */
void LCD_send_command ( unsigned char cmnd ) ;
void LCD_send_data ( unsigned char data ) ;
void LCD_init ( ) ;
void LCD_goto ( unsigned char y , unsigned char x ) ;
void LCD_print ( char * string ) ;
void LCD_update_time ( void ) ;
/ * Contador Temporizador 1 Comparar rutina de ajuste de un Servicio de
Interrupcin / Interrumpir Manejador * /
ISR (TIMER1_COMPA_vect);
#define LCD_DATA_PORT PORTB
#define LCD_DATA_DDR DDRB
#define LCD_DATA_PIN PINB
#define LCD_CNTRL_PORT PORTC
#define LCD_CNTRL_DDR DDRC
#define LCD_CNTRL_PIN PINC
#define
#define
#define
#define
#define
LCD_RS_PIN 5
LCD_RW_PIN 6
LCD_ENABLE_PIN 7
SET_HOUR 3
SET_MINUTE 4
(1 << SET_HOUR |
1 << SET_MINUTE);
( 1 << LCD_ENABLE_PIN ) ;
_delay_us ( 2 ) ;
LCD_CNTRL_PORT &= ~ ( 1 << LCD_ENABLE_PIN ) ;
_delay_us ( 100 ) ;
}
void LCD_init ()
{LCD_CNTRL_DDR = 0xFF;
LCD_CNTRL_PORT = 0x00;
LCD_DATA_DDR = 0xFF;
LCD_DATA_PORT = 0x00;
_delay_ms ( 10 )
LCD_send_command
LCD_send_command
LCD_send_command
_delay_ms ( 10 )
LCD_send_command
;
(
(
(
;
(
0x38 ) ;
0x0C ) ;
0x01 ) ;
0x06 ) ;
}
/ * Esta funcin mueve el cursor a la recta y la columna x en el mdulo
LCD * /
void LCD_goto (sin firmar
carbn y, sin firmar carbn x) {unsigned
carbn firstAddress [] = {0x80, 0xC0, 0x94, 0xD4};
LCD_send_command (firstAddress [y - 1]
_delay_ms (10);}
void LCD_print (Char
+ x - 1);
LCD_print (temp);
LCD_print (":");
itoa (segundos / 10, temp, 10);
LCD_print (temp);
itoa (segundos% 10, temp, 10);
LCD_print (temp);} / * Contador Temporizador 1 Compara Partido Un
servicio de interrupcin Rutina / Interrumpir Manejador * /
ISR (TIMER1_COMPA_vect)
{segundo ++;
si (segundo ==
60)
{segundos = 0;
minutos ++;}
si (minutos ==
60)
{minutos =
horas ++;}
0;
si (hora> 23)
horas = 0;
LCD_update_time ();}
Nota Importante: Para que la unidad Termmetro Digital LM35 LCD para que funcione
correctamente el oscilador interno del microcontrolador ATmega16 AVR debe estar
habilitado y se puso a 4 MHz.
Software
para
el
Termmetro
Digital
LCD
ATmega16
LCD_RS_PIN 5
LCD_RW_PIN 6
LCD_ENABLE_PIN 7
SET_HOUR 3
SET_MINUTE 4
LCD_init ();
LCD_goto (1, 2);
LCD_print ("La temperatura es");
LCD_CNTRL_PORT =
(1 << SET_HOUR |
1 << SET_MINUTE);
//
sei ();
interrupciones
ADCSRA | =
//
Activar
el
ADC
su
void LCD_init ()
{LCD_CNTRL_DDR = 0xFF;
LCD_CNTRL_PORT = 0x00;
LCD_DATA_DDR = 0xFF;
LCD_DATA_PORT = 0x00;
Global
_delay_ms ( 10 )
LCD_send_command
LCD_send_command
LCD_send_command
_delay_ms ( 10 )
LCD_send_command
;
(
(
(
;
(
0x38 ) ;
0x0C ) ;
0x01 ) ;
0x06 ) ;
}
/ * Esta funcin mueve el cursor a la recta y la columna x en el mdulo
LCD * /
void LCD_goto (sin firmar
carbn y, sin firmar carbn x) {unsigned
carbn firstAddress [] = {0x80, 0xC0, 0x94, 0xD4};
LCD_send_command (firstAddress [y - 1]
_delay_ms (10);}
void LCD_print (Char
+ x - 1);
, 10 ) ;
, 10 ) ;
, 10 ) ;
, 10 ) ;
ADCSRA |=
Conversin}
1 << ADSC ;
// Comience
Nota Importante: Para que nuestro reloj digital para que funcione correctamente el
oscilador interno del microcontrolador ATmega16 AVR debe estar habilitado y se puso a 4
MHz.
/ * Funcin
Dgitos (0-9) a siete valores del segmento Encoder * /
unsigned
carbn DigitTo7SegEncoder (sin firmar
carbn dgitos, sin
firmar carbn comn);
/ * Contador Temporizador 1 Comparar rutina de ajuste de un Servicio de
Interrupcin / Interrumpir Manejador * /
ISR (TIMER1_COMPA_vect);
/ * Inicio Program*/
/
*************************************************************************
****/
int main ( void )
{
SegDataDDR = 0xFF ;
SegCntrlDDR = 0x3F ;
SegCntrlPort = 0xFF ;
TCCR1B = (1 << CS12 | 1 << WGM12);
OCR1A = 15 625 - 1;
TIMSK = 1 << OCIE1A;
sei ();
mientras que (1)
{/ * Minutos establecidos al pulsar SegCntrl Pin 6 Interruptor * /
si ((SegCntrlPin y
0x40)
==
0)
{_delay_ms (200);
si (minuto <59)
minutos ++;
else
minutos = 0;
}
/ * Horas establecidos al pulsar SegCntrl Pin 7 Interruptor * /
si ((SegCntrlPin y 0x80) == 0)
{_delay_ms (200);
si (horas <23)
horas ++;
else
horas = 0;}
SegDataPort = DigitTo7SegEncoder
SegCntrlPort = ~ 0x01 ;
SegDataPort = DigitTo7SegEncoder
SegCntrlPort = ~ 0x02 ;
SegDataPort = DigitTo7SegEncoder
SegCntrlPort = ~ 0x04 ;
SegDataPort = DigitTo7SegEncoder
( seconds % 10 , 1 ) ;
( seconds / 10 , 1 ) ;
( minutes % 10 , 1 ) ;
( minutes / 10 , 1 ) ;
SegCntrlPort = ~ 0x08 ;
SegDataPort = DigitTo7SegEncoder ( hours % 10 , 1 ) ;
SegCntrlPort = ~ 0x10 ;
SegDataPort = DigitTo7SegEncoder ( hours / 10 , 1 ) ;
SegCntrlPort = ~ 0x20 ;
}
Volver
0;}
/ *
* Funcin descriptiva:
* Codificar un dgito decimal 0-9 a su equivalente de siete segmentos.
*
* Argumentos de funcin:
* Dgito - dgito decimal a codificar
* Comn - nodo comn (0), Ctodo Comn (1)
* SegVal - Codificado Valor siete segmentos
*
* Conexiones:
* Encoded SegVal es el retorno en la otra GFEDCBA es A es el menos
* Poco significativo (bit 0) y G bit 6.
* /
Unsigned
carbn DigitTo7SegEncoder (sin firmar
carbn dgitos, sin
firmar carbn comn) {unsigned carbn SegVal;
switch ( digit )
{
case 0 :
case
1 :
case
2 :
1 )
break ;
if ( common ==
case
3 :
break ;
if ( common ==
1 )
case
4 :
break ;
if ( common ==
1 )
case
5 :
break ;
if ( common ==
SegVal =
SegVal
1 )
else
0b01100110 ;
SegVal =
SegVal
else
0b01001111 ;
SegVal =
SegVal
else
0b01011011 ;
break ;
if ( common ==
SegVal =
SegVal
else
0b00000110 ;
1 )
else
0b00111111 ;
if ( common ==
SegVal =
SegVal
1 )
SegVal =
0b00111111
=
0b00000110
=
0b01011011
=
0b01001111
=
0b01100110
=
0b01101101
else
0b01101101 ;
case
break ;
if ( common ==
6 :
SegVal
1 )
else
0b01111101 ;
case
break ;
if ( common ==
7 :
SegVal
1 )
else
0b00000111 ;
case
break ;
if ( common ==
8 :
case
break ;
if ( common ==
9 :
else
SegVal =
SegVal
1 )
else
0b01111111 ;
SegVal =
SegVal =
SegVal
1 )
SegVal =
SegVal
0b01111101
=
0b00000111
=
0b01111111
=
0b01101111
=
0b01101111 ;
}
return SegVal ;
}
/ * Contador Temporizador 1 Comparar Partido Un servicio de interrupcin
de rutina / Interrumpir Manejador * /
ISR (TIMER1_COMPA_vect)
{segundo ++;
si (segundo ==
60)
{segundos = 0;
minutos ++;}
si (minutos ==
60)
{minutos =
horas ++;}
si (hora> 23)
horas = 0;}
0;