Ejemplos'puertos
Ejemplos'puertos
LDI
OUT
ON, LD3 = OFF,
RCALL
R20, 0xA0
PORTE, R20
;PORTE = 1010 0000 B (LD1 = OFF, LD2 =
LD4 = ON)
DELAY
;wait 1 second
LDI
OUT
OFF, LD3 = ON,
RCALL
RJMP
R20, 0x50
PORTE, R20
;PORTE = 0101 0000 B (LD1 = ON, LD2 =
LD4 = OFF)
DELAY
;wait 1 second
L1
;jump to L1
;
======================================================================
=
;The Delay subroutine creates a delay which is 1 second for XTAL =
8MHz.
;
======================================================================
=
DELAY:
LDI
R21, 32
;R21 = 32
DL1:LDI R22, 200
;R22 = 200
DL2:LDI R23, 250
DL3:NOP
NOP
DEC
R23
BRNE
DL3
DL3
DL2
DL1
;R23 = 250
;R23 = R23 - 1
;if R23 is not equal to zero then go to
DEC R22
BRNE
DL2
;R22 = R22 - 1
;if R22 is not equal to zero then go to
DEC R21
BRNE
DL1
;R21 = R21 - 1
;if R21 is not equal to zero then go to
RET
http://www.microdigitaled.com/AVR/Hardware/Digilent_asm/1_toggleUserLED
s.asm
L1:
LDI
OUT
OUT
OUT
R20, 0xFF
DDRA, R20
DDRC, R20
DDRE, R20
LDI
OUT
OUT
OUT
RCALL
R20, 0xAA
;R20 = 1010 1010 B
PORTA, R20
PORTC, R20
PORTE, R20
DELAY
;wait 1 second
LDI
OUT
OUT
OUT
RCALL
RJMP
R20, 0x55
;R20 = 0101 0101 B
PORTA, R20
PORTC, R20
PORTE, R20
DELAY
;wait 1 second
L1
;JA as output
;JB as output
;user LED as output
;
======================================================================
=
;The Delay subroutine creates a delay which is 1 second for XTAL =
8MHz.
;
======================================================================
=
DELAY:
LDI
R21, 32
;R21 = 32
DL1:LDI R22, 200
;R22 = 200
DL2:LDI R23, 250
DL3:NOP
NOP
DEC
R23
BRNE
DL3
DL3
;R23 = 250
;R23 = R23 - 1
;if R23 is not equal to zero then go to
DEC R22
BRNE
DL2
;R22 = R22 - 1
;if R22 is not equal to zero then go to
DEC R21
BRNE
DL1
;R21 = R21 - 1
;if R21 is not equal to zero then go to
DL2
DL1
RET
http://www.microdigitaled.com/AVR/Hardware/Digilent_asm/2_togglePorts.as
m
.INCLUDE "M64DEF.INC"
L1:
LDI
OUT
LDI
OUT
R20, 0x00
DDRA, R20
R20, 0xF0
DDRE, R20
OUT
PORTA, R20
;JA as input
;User LEDs as output
;make pull-up resistors active
IN
R20, PINA
;R20 = JA
ANDI R20, 0xF0 ;R20 = R20 & 0xF0 (just the high nibble)
OUT
PORTE, R20
;User LEDs = R20
RJMP
L1
;go to L1
http://www.microdigitaled.com/AVR/Hardware/Digilent_asm/3_sendJAtoUserL
EDs.asm
;The Cerebot board has 8 ports named as JA, JB, JC, ..., and JH.
;The program gets Data from JA and sends it to JB.
;connect DIP switches to JA and LEDs to JB
;It is in AVR Assembly Language for AVR Studio IDE. Make the hex file
using AVR Studio.
;See www.microdigitaled.com and www.digilentinc.com for more
information
.INCLUDE "M64DEF.INC"
LDI
OUT
LDI
OUT
R20, 0x00
DDRA, R20
R20, 0xFF
DDRC, R20
OUT
PORTA, R20
;JA as input
;JB as output
;make the pull-up resistors of port A
active
;-------Get data from DIP switches connected to JA and send it to LEDs
of JB
L1:
IN
R20, PINA
;R20 = JA
OUT
PORTC, R20
;JB = R20
RJMP
L1
;go to L1
http://www.microdigitaled.com/AVR/Hardware/Digilent_asm/4_sendJAtoJB.as
m