so I have this question, I have been given a task to do a bombard game with AVR Studio. To be true, I have no clue on how to use AVR and my programming is not so good as well. I got my ships done somehow, but now I need a random number generator. Have been looking throughout Internet for about 2 days now, only found source codes in C, in Java, in absolutely every other language but not the one I need. Could anyone suggest me in what to write for the RAND? for now, my source code looks like this:
;ports
.equ PORTC = $15 ;port C address
.equ DDRC = $14
.equ PORTA = $15 ;port A address
.equ DDRA = $14
;registers
.def leds = r16 ;storing data for leds
.def temp = r18 ;Temporary storage register
.def save = r19 ;Temporary storage register for status registers
.def YL = r20 ;Defining low bite of Y
.def YH = r21 ;Defining high bite of Y
;
.equ SREG = $3F ;Status Register Address
.equ SPH = $3E ;High bite Stack Pointer address
.equ SPL = $3D ;Low bite Stack Pointer address
.equ RAMEND = $25F ;Stack Address
;Random number generator
ldi r16, $80
ldi r17, $C0
;Set stack pointer to registers
ldi temp,high(RAMEND)
out SPH,temp
ldi temp,low(RAMEND)
out SPL,temp
;Initialise output ports
ldi temp, $ff
out DDRC, temp
clear: clc
; clr leds
out PORTC, leds
rjmp SHIP2_prep
SHIP1_prep: ldi leds, $80
rjmp SHIPS
SHIP2_prep: ldi leds, $80
out PORTC, leds
ldi leds, $C0
rjmp SHIPS
SHIP3_prep: ldi leds, $80
out PORTC, leds
ldi leds, $C0
out PORTC, leds
ldi leds, $E0
rjmp SHIPS
;Rotate ships right
SHIPS: out PORTC, leds
; rcall delay
ror leds
brcs clear
rjmp SHIPS
;delay: in save,SREG
; ldi YH,high($FF9C)
; ldi YL,low($FF9C)
loop: sbiw Y,1
brne loop
out SREG, save
ret
Aucun commentaire:
Enregistrer un commentaire