0% found this document useful (0 votes)
45 views3 pages

Ejemplos'puertos

This document contains 4 assembly language programs for the Cerebot2 microcontroller board. The programs toggle LEDs, ports, read an input port and write to LEDs, and read from one port and write to another port. It provides instructions for using the AVR Studio IDE to compile and run the programs on the Cerebot2 board.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views3 pages

Ejemplos'puertos

This document contains 4 assembly language programs for the Cerebot2 microcontroller board. The programs toggle LEDs, ports, read an input port and write to LEDs, and read from one port and write to another port. It provides instructions for using the AVR Studio IDE to compile and run the programs on the Cerebot2 board.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

;In Cerebot2, 4 LEDs (LD1, LD2, LD3, and LD4) are connected to PORTE

which are named "user LEDs".


;This program Toggles user LEDs (PORTE) in AVR Assembly Language.
;Use AVR Studio IDE to make the hex file.
;For more information see www.microdigitaled.com and
www.digilentinc.com
.INCLUDE "M64DEF.INC"

;ATmega64 is used by Cerebot2 board

;initialize SP (Stack Pointer)


LDI
R20, HIGH(RAMEND)
OUT
SPH, R20
LDI
R20, LOW(RAMEND)
OUT
SPL, R20
;PE4 to PE7 as outputs (PE4 to PE7 are connected to LD1 to LD4
respectively)
LDI
R20, 0xF0
OUT
DDRE, R20
L1:

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

;Cerebot2 has 8 ports named as JA, JB, JC,...,and JH respectively.


Cerebot2 also has four LEDs named as LD1, LD2, LD3, and LD4.
;This program toggles JA (portA), JB (port C), and the four LEDs.
;This code is for AVR Studio IDE. Use AVR Studio to make the hex file.
;For more information see www.microdigitaled.com and
www.digilentinc.com
.INCLUDE "M64DEF.INC" ;ATmega64 is used by Cerebot2 board
;initialize SP (Stack Pointer)
LDI
R20, HIGH(RAMEND)
OUT
SPH, R20
LDI
R20, LOW(RAMEND)
OUT
SPL, R20

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

;The Cerebot board has 8 ports named as JA, JB, JC,


also has 4 LEDs named as LD1, LD2, LD3, and LD4.
;This program reads JA.4 to JA.7 and writes to User
;Connect DIP switches to JA.
;It is in AVR Assembly Language for AVR Studio IDE.
using AVR Studio.
;See www.microdigitaled.com and www.digilentinc.com
information

..., and JH. It


LEDs (LD1 to LD4)
Make the hex file
for more

.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"

;ATmega64 is used by Cerebot2 board

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

You might also like