Hello, I am new to PIC programming and I could really use your assistance in my code. I would like to make a random output on Port D using only 5 bits. I attempted different ways to make the lookup table pick a different line in the lookup table but it would not work at all. Im using a PIC 18F4550 microcontroller that outputs to Port D to turn on a LED's. I'm only using bits 0 to 4, 5 bits from the lookup table below. I would like to randomly choose a line in the lookup table and output it to Port D.
Can someone help me in by modifying the code to randomly pick a line in the lookup table? I would greatly appreciate it. Thanks Mark Squared.
MAIN
GOTO Start
GOTO MAIN
Start clrf count ;set counter register to zero
Read movf count, w ;put counter value in W
call Table
movwf PORTD
call Delay
incf count, w
xorlw d'14' ;check for last (14th) entry
btfsc STATUS, Z
goto Start ;if start from beginning
incf count, f ;else do next
goto Read
Table ADDWF PCL, f ;data table for bit pattern
retlw b'10000000'
retlw b'01000001'
retlw b'00100010'
retlw b'00100100'
retlw b'00000000'
retlw b'00000100'
retlw b'00000010'
retlw b'00000001'
retlw b'00000010'
retlw b'00000100'
retlw b'00001000'
retlw b'00010000'
retlw b'00100000'
retlw b'00000100'
Delay
;return; added for testing
movlw d'250' ;delay 250 ms (4 MHz clock)
movwf count1
d1 movlw 0xC7
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0
decfsz count1 ,f
goto d1
retlw 0x00
end