; generates a 16 bit pseudo-random number which is returned in Acc (lsb) & B (msb)
; two bytes of memory must be available for rand16reg
ORG 0H
rand16reg EQU 40H ;two bytes
rand16: MOV A, rand16reg
JNZ rand16b
MOV A, rand16reg+1
JNZ rand16b
CPL A
MOV rand16reg, A
MOV rand16reg+1, A
rand16b: ANL A, #11010000b
MOV C, P
MOV A, rand16reg
JNB ACC.3, rand16c
CPL C
rand16c: RLC A
MOV rand16reg, A
MOV B, A
MOV A, rand16reg+1
RLC A
MOV rand16reg+1, A
XCH A, B
RET
END
Related topics:
8051 Program - 8bit random number generator | 8051 Program - bit shifting | 8051 Program - count external interrupt | 8051 Program - frequency measurement | 8051 Program - led rotation pattern | 8051 Program - memory subroutines | 8051 Program - math subroutines | 8051 Program - conversion subroutines
List of topics: 8051
No comments:
Post a Comment