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

;This program displays 07 on the seven segments.

;Connect the 7-segment module to the upper pins of JA and JB.


;The code is in AVR assembly. 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
;JA (PORTA) and JB(PORTC) as outputs
LDI
R20, 0xFF
OUT
DDRA, R20
OUT
DDRC, R20
L1:

LDI
R20, 0x07
;R20 = 0x07 (to display '7' on 7-segment
we should put 0x07 on the port)
;===========================
;Right 7-segment
;===========================
;put the high nibble of R20 on JB (PORTC)
MOV
R16, R20
;R16 = R20
ANDI R16, 0x70
SWAP R16
OUT
PORTC, R16
;put the low nibble of R20 on JA (PORTA)
MOV
R16, R20
;R16 = R20
ANDI R16, 0x0F ;R16 = R16 & 0x0F
OUT
PORTA, R16
;PORTA = R16
CALL

DELAY

;wait for a while

;R20 = 0x3F (to display '0' on 7-segment we should put 0x07 on


the port)
LDI
R20, 0x3F

segment

;===========================
;Left 7-segment
;===========================
;put the high nibble of R20 on JB (PORTC)
MOV
R16, R20
;R16 = R20
ANDI R16, 0x70
ORI
R16, 0x80
;enable the catode for the Left 7SWAP R16
OUT
PORTC, R16
;put the low nibble of R20 on JA (PORTA)
MOV
R16, R20
ANDI R16, 0x0F
OUT
PORTA, R16
CALL
RJMP

DELAY
L1

;wait for a while


;goto L1

;========================================
;The delay subroutine makes a small delay
;========================================
DELAY:
DL1:

LDI

R16, 0 ;R16 = 0

NOP
DEC R16
BRNE
DL1
RET

;R16 = R16 - 1
;if R16 is not zero go to DL1

http://www.microdigitaled.com/AVR/Hardware/Digilent_asm/5_sevenSeg.asm

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