Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC Random Lookup Table

Status
Not open for further replies.

mark squared

Newbie level 1
Joined
Oct 21, 2010
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,298
:?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. I’m 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
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
 

PIC18F4550 isn't banked !

You should look at the instructions specifically written to access data tables though. Check the data sheet for the "TBLRD" instruction details.
Your code seems to be sequentially reading through the table though, this is not random !

Brian.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top