This one may work for you.
Just work on this sample code.
Code:<font color="#000080"><i>'@ DEVICE PIC16F628A, INTRC_OSC_NOCLKOUT, WDT_OFF, PWRT_OFF, MCLR_OFF,PROTECT_ON,CPD_ON, BOD_OFF, LVP_OFF </i><b>DEFINE </b></font>OSC <font color="#FF0000">4 </font>CMCON = <font color="#FF0000">7 </font><font color="#000080"><b>PAUSE </b></font><font color="#FF0000">1 </font>VRCON = <font color="#FF0000">0 </font><font color="#000080"><b>PAUSE </b></font><font color="#FF0000">1 </font>TRISA = <font color="#FF0000">0 </font>TRISB = <font color="#FF0000">0 </font>PORTA = <font color="#FF0000">0 </font>PORTB = <font color="#FF0000">0 </font>OPTION_REG.<font color="#FF0000">5 </font>= <font color="#FF0000">0 </font><font color="#000080"><i>' Internal clk. </i></font>OPTION_REG.<font color="#FF0000">3 </font>= <font color="#FF0000">0 </font><font color="#000080"><i>' Prescaler assigned to TMR0. </i></font>OPTION_REG.<font color="#FF0000">2 </font>= <font color="#FF0000">0 </font><font color="#000080"><i>' </i></font>OPTION_REG.<font color="#FF0000">1 </font>= <font color="#FF0000">0 </font><font color="#000080"><i>' </i></font>OPTION_REG.<font color="#FF0000">0 </font>= <font color="#FF0000">0 </font><font color="#000080"><i>' 1:1 </i><b>PAUSE </b></font><font color="#FF0000">10 </font>Led1 <font color="#000080"><b>VAR </b></font>PORTA.<font color="#FF0000">0 </font><font color="#000080"><i>'Assign leds. </i></font>Led2 <font color="#000080"><b>VAR </b></font>PORTA.<font color="#FF0000">1 </font>Led3 <font color="#000080"><b>VAR </b></font>PORTA.<font color="#FF0000">2 </font>Led4 <font color="#000080"><b>VAR </b></font>PORTA.<font color="#FF0000">3 </font>Led5 <font color="#000080"><b>VAR </b></font>PORTA.<font color="#FF0000">4 </font>Led6 <font color="#000080"><b>VAR </b></font>PORTB.<font color="#FF0000">0 </font>Led7 <font color="#000080"><b>VAR </b></font>PORTB.<font color="#FF0000">1 </font>Led8 <font color="#000080"><b>VAR </b></font>PORTB.<font color="#FF0000">2 </font>Led9 <font color="#000080"><b>VAR </b></font>PORTB.<font color="#FF0000">3 </font>Led10 <font color="#000080"><b>VAR </b></font>PORTB.<font color="#FF0000">4 </font>Led11 <font color="#000080"><b>VAR </b></font>PORTB.<font color="#FF0000">5 </font>Led12 <font color="#000080"><b>VAR </b></font>PORTB.<font color="#FF0000">6 </font>Led13 <font color="#000080"><b>VAR </b></font>PORTB.<font color="#FF0000">7 </font>Led14 <font color="#000080"><b>VAR </b></font>PORTA.<font color="#FF0000">7 </font>Led15 <font color="#000080"><b>VAR </b></font>PORTA.<font color="#FF0000">6 </font>Index <font color="#000080"><b>VAR BYTE </b></font>LookForThree <font color="#000080"><b>VAR BYTE </b></font>Val <font color="#000080"><b>VAR WORD </b></font>Result <font color="#000080"><b>VAR BYTE PAUSE </b></font><font color="#FF0000">100 </font>Start: LookForThree = <font color="#FF0000">0 </font><font color="#000080"><b>WHILE </b></font>LookForThree <> <font color="#FF0000">3 </font><font color="#000080"><i>' Look for three "SET"s. </i><b>RANDOM </b></font>Val <font color="#000080"><i>' Get a random value. </i><b>PAUSEUS </b></font>TMR0 <font color="#000080"><i>' To get a good random number, have a changing value using TMR0 or TMR1. </i></font>LookForThree = <font color="#FF0000">0 </font><font color="#000080"><b>FOR </b></font>Index = <font color="#FF0000">0 </font><font color="#000080"><b>TO </b></font><font color="#FF0000">15 </font><font color="#000080"><i>' Scan through the bits. </i><b>IF </b></font>Val.<font color="#FF0000">0</font>[Index] = <font color="#FF0000">1 </font><font color="#000080"><b>THEN </b></font>LookForThree = LookForThree + <font color="#FF0000">1 </font><font color="#000080"><i>'Count "SET"s. </i><b>NEXT </b></font>Index <font color="#000080"><b>WEND GOSUB </b></font>SetPins <font color="#000080"><b>PAUSE </b></font><font color="#FF0000">5000 </font><font color="#000080"><b>GOTO </b></font>Start SetPins: Led1 = Val.<font color="#FF0000">0 </font>Led2 = Val.<font color="#FF0000">1 </font>Led3 = Val.<font color="#FF0000">2 </font>Led4 = Val.<font color="#FF0000">3 </font>Led5 = Val.<font color="#FF0000">4 </font>Led6 = Val.<font color="#FF0000">5 </font>Led7 = Val.<font color="#FF0000">6 </font>Led8 = Val.<font color="#FF0000">7 </font>Led9 = Val.<font color="#FF0000">8 </font>Led10 = Val.<font color="#FF0000">9 </font>Led11 = Val.<font color="#FF0000">10 </font>Led12 = Val.<font color="#FF0000">11 </font>Led13 = Val.<font color="#FF0000">12 </font>Led14 = Val.<font color="#FF0000">13 </font>Led15 = Val.<font color="#FF0000">14 </font><font color="#000080"><b>RETURN END </b></font>
i tried to compile the sample code and simulate it using proteus at first it will light 3 leds but next it will only light two of them so i tried compiling it for other pic but it has some error can you please say to me what this line is for:
VRCON = 0
i got error with that when i try to compile it for other pic's ???
Bookmarks