8051 Microcontroller - Random Generator

Discussion in 'Homework Help' started by kay19, Mar 2, 2014.

  1. kay19

    Thread Starter New Member

    Mar 2, 2014
    1
    0
    Hello, I am doing a project that requires 3 parts, and I have finished 2 parts. They were (1) getting two led's moving back and forth across the display & (2) Two led's that start at the center and each move to the end, one to the left and one to the right.

    There's one more part that i'm just stuck, because the book does not say anything about generating random numbers/led, as well as instructor told us to look for it online. More specific, (3) Three led's moving randomly around the 8-bit display, but not necessarily connected.

    I am using assembly language Atmel 89C51RD2 to do this. Here is my code if anyone wants to take a look and tinker it around. Any help on how to generate random 3 LED sequences.

    Code ( (Unknown Language)):
    1. ORG 000H
    2.    
    3.     MOV P0, #0E7H
    4.     LJMP MAIN
    5.  
    6.     ORG 0100H
    7.    
    8.    
    9.  
    10. MAIN:
    11.     MOV A, P0
    12.     ;MOV R7, P0
    13.     ANL A, #11100000b
    14.  
    15.     CJNE A, #20H, J0
    16.     LJMP PATERN1
    17.  
    18.     J0: CJNE A, #40H, J1
    19.     LJMP PATERN2
    20.    
    21.     J1: CJNE A, #60H, J2
    22.     LJMP PATERN3
    23.    
    24.     J2: CJNE A, #80H, J3
    25.     LJMP PATERN4
    26.    
    27.     J3: CJNE A, #0A0H, J4
    28.     LJMP PATERN5
    29.    
    30.     J4: CJNE A, #0C0H, J5
    31.     LJMP PATERN6
    32.    
    33.     J5: CJNE A, #0E0H, J6
    34.     LJMP PATERN7
    35.    
    36.     J6: CJNE A, #00H, J7
    37.     LJMP PATERN8
    38.  
    39.     J7: LJMP MAIN
    40.    
    41. PATERN1:
    42.     MOV P1, #0C0H
    43.     ACALL DELAY
    44.     MOV P1, #60H
    45.     ACALL DELAY
    46.     MOV P1, #30H
    47.     ACALL DELAY
    48.     MOV P1, #18H
    49.     ACALL DELAY
    50.     MOV P1, #0CH
    51.     ACALL DELAY
    52.     MOV P1, #06H
    53.     ACALL DELAY
    54.     MOV P1, #03H
    55.     ACALL DELAY
    56.     MOV P1, #06H
    57.     ACALL DELAY
    58.     MOV P1, #0CH
    59.     ACALL DELAY
    60.     MOV P1, #18H
    61.     ACALL DELAY
    62.     MOV P1, #30H
    63.     ACALL DELAY
    64.     MOV P1, #60H
    65.     ACALL DELAY
    66.     MOV P1, #0C0H
    67.     ACALL DELAY
    68.    
    69.     LJMP MAIN
    70.    
    71.    
    72. PATERN2:
    73.     MOV P1, #01H
    74.     ACALL DELAY
    75.     MOV P1, #00H
    76.     ACALL DELAY
    77.     MOV P1, #01H
    78.     ACALL DELAY
    79.     MOV P1, #00H
    80.     ACALL DELAY
    81.     MOV P1, #01H
    82.     ACALL DELAY
    83.     MOV P1, #00H
    84.     ACALL DELAY
    85.    
    86.     LJMP MAIN
    87.  
    88.    
    89. PATERN3:
    90.     MOV P1, #18H
    91.     ACALL DELAY
    92.     MOV P1, #24H
    93.     ACALL DELAY
    94.     MOV P1, #42H
    95.     ACALL DELAY
    96.     MOV P1, #81H
    97.     ACALL DELAY
    98.     MOV P1, #42H
    99.     ACALL DELAY
    100.     MOV P1, #24H
    101.     ACALL DELAY
    102.    
    103.     LJMP MAIN
    104.    
    105. PATERN4:
    106.    
    107.     MOV P1, #00H
    108.     ACALL DELAY
    109.     MOV P1, #88H
    110.     ACALL DELAY
    111.     MOV P1, #44H
    112.     ACALL DELAY
    113.     MOV P1, #22H
    114.     ACALL DELAY
    115.     MOV P1, #11H
    116.     ACALL DELAY
    117.     MOV P1, #22H
    118.     ACALL DELAY
    119.     MOV P1, #44H
    120.     ACALL DELAY
    121.     MOV P1, #88H
    122.  
    123.     ACALL DELAY
    124.    
    125. PATERN5:
    126.     MOV P1, #03H
    127.     ACALL DELAY
    128.     MOV P1, #00H
    129.     ACALL DELAY
    130.     MOV P1, #03H
    131.     ACALL DELAY
    132.     MOV P1, #00H
    133.     ACALL DELAY
    134.     MOV P1, #03H
    135.     ACALL DELAY
    136.     MOV P1, #00H
    137.     ACALL DELAY
    138.    
    139.     LJMP MAIN
    140.    
    141. PATERN6:
    142.     MOV P1, #07H
    143.     ACALL DELAY
    144.     MOV P1, #00H
    145.     ACALL DELAY
    146.     MOV P1, #07H
    147.     ACALL DELAY
    148.     MOV P1, #00H
    149.     ACALL DELAY
    150.     MOV P1, #07H
    151.     ACALL DELAY
    152.     MOV P1, #00H
    153.     ACALL DELAY
    154.    
    155.     LJMP MAIN
    156.    
    157. PATERN7:
    158.     MOV P1, #0BH
    159.     ACALL DELAY
    160.     MOV P1, #00H
    161.     ACALL DELAY
    162.     MOV P1, #0BH
    163.     ACALL DELAY
    164.     MOV P1, #00H
    165.     ACALL DELAY
    166.     MOV P1, #0BH
    167.     ACALL DELAY
    168.     MOV P1, #00H
    169.     ACALL DELAY
    170.    
    171.     LJMP MAIN
    172.    
    173. PATERN8:
    174.     MOV P1, #00H
    175.     ACALL DELAY
    176.     MOV P1, #0FFH
    177.     ACALL DELAY
    178.     MOV P1, #00H
    179.     ACALL DELAY
    180.     MOV P1, #0FFH
    181.     ACALL DELAY
    182.     MOV P1, #00H
    183.     ACALL DELAY
    184.     MOV P1, #0FFH
    185.     ACALL DELAY
    186.    
    187.     LJMP MAIN
    188.    
    189.    
    190.        
    191. DELAY       :
    192.     MOV A, P0
    193.     ANL A, #00000111b
    194.  
    195.     S0: CJNE A, #00H, S1
    196.     LJMP SELECT0
    197.  
    198.     S1: CJNE A, #01H, S2
    199.     LJMP SELECT1
    200.    
    201.     S2: CJNE A, #02H, S3
    202.     LJMP SELECT2
    203.    
    204.     S3: CJNE A, #03H, S4
    205.     LJMP SELECT3
    206.  
    207.     S4: CJNE A, #04H, S5
    208.     LJMP SELECT4
    209.    
    210.     S5: CJNE A, #05H, S6
    211.     LJMP SELECT5
    212.    
    213.     S6: CJNE A, #06H, S7
    214.     LJMP SELECT6
    215.  
    216.     S7: ;CJNE A, #07H, S8
    217.     LJMP SELECT7
    218.    
    219.    
    220. SELECT0     : MOV R1, #2
    221.               MOV R2, #1
    222.               SJMP SL2
    223. SELECT1     : MOV R1, #3
    224.               MOV R2, #1
    225.               SJMP SL2
    226. SELECT2     : MOV R1, #6
    227.               MOV R2, #1
    228.               SJMP SL2
    229. SELECT3     : MOV R1, #10
    230.               MOV R2, #1
    231.               SJMP SL2
    232. SELECT4     : MOV R1, #20
    233.               MOV R2, #1
    234.               SJMP SL2
    235. SELECT5     : MOV R1, #200
    236.               MOV R2, #1
    237.               SJMP SL2
    238.              
    239. SELECT6     : MOV R2, #10
    240.               MOV R1, #200
    241.               SJMP SL3
    242. SELECT7     : MOV R2, #100
    243.               MOV R1, #200
    244.               SJMP SL3
    245.  
    246. SL3         : MOV R1, #200
    247.              
    248. SL2         : MOV R0, #23
    249.  
    250. SL1         : DJNZ R0, SL1
    251.               DJNZ R1, SL2
    252.               DJNZ R2, SL3
    253.              
    254.               RET
    255.               END
    256.  
     
  2. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,383
    495
Loading...