lundi 26 septembre 2016

Generating random Number ATMega168, AVR STUDIO 4

how can I generate a random number(command) in Avr Studio 4. I have an ATMEGA168. I want to generate the random number, so the "warten"(waiting) has an non defined waiting time and is changing all time. So if it has decreased from 255 to 0 etc. I want it to generate a random number which defines if its going another time through the waiting or if it's going to ret. Here's my code:

.include "m168def.inc" ;ATMega 168

rjmp main                

main:
ldi r16, 0b00000100

out ddrB, r16           

loop:
ldi r16, 0b00000100
out portB, r16

rcall warten            

ldi r16, 0b00000000     
out portB, r16          
rcall warten

rjmp loop

warten: ldi r17,2
w3:
ldi r18,255
w2:
ldi r19,255
w1:
dec r19
brne w1

dec r18                 
brne w2                 



dec r17                 
brne w3                 

ret




Aucun commentaire:

Enregistrer un commentaire