Can someone help me make a code for this:


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Delete VRCON = 0, try again.


    Also,
    VAL is a WORD variable thus it has 16-bits.
    But, in the sample code, we have 15 bits (15 LEDS) getting set.
    Depending on the pic you are using, add one more led to an appropriate pic pin, and assign it to the last bit of VAL (Val.15) in SetPins subroutine.

    -------------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  2. #2
    Join Date
    Apr 2009
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    i think the problem is on the configure bits ???

    i changed the pause 5000 to 100 and run it on simulation and i noticed that led's connected on RA6 and RA7 is never energized, what could be the problem?
    Last edited by joseph; - 18th May 2009 at 21:35.

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    It all depending of our device in use, some have ADC, some have analog comparator, some have open-drain, and the list is almost endless. But there's less chance that any issues would be caused by a timer.

    I suggest you to have a look at this link.
    http://www.picbasic.co.uk/forum/showthread.php?t=11116

    Remember, datasheet MUST be your friend
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Apr 2009
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    I changed the start of the code

    Code:
    @ DEVICE PIC16F628A, INTRC_OSC_NOCLKOUT, WDT_OFF, PWRT_OFF, MCLR_OFF,PROTECT_ON,CPD_ON, BOD_OFF, LVP_OFF
    it was a part of the comments before

    and changed

    Code:
    FOR Index = 0 TO 15   ' Scan through the bits.
    to

    Code:
    FOR Index = 0 TO 14   ' Scan through the bits.
    and the final code:

    Code:
    @ DEVICE PIC16F628A, INTRC_OSC_NOCLKOUT, WDT_OFF, PWRT_OFF, MCLR_OFF,PROTECT_ON,CPD_ON, BOD_OFF, LVP_OFF
    
    DEFINE OSC 4
    
    CMCON = 7
    PAUSE 1
    VRCON = 0
    PAUSE 1
    
    TRISA = 0
    TRISB = 0
    PORTA = 0
    PORTB = 0
    T1CON.1 = 0
    OPTION_REG.5 = 0 ' Internal clk.
    OPTION_REG.3 = 0 ' Prescaler assigned to TMR0.
    OPTION_REG.2 = 0 ' 
    OPTION_REG.1 = 0 ' 
    OPTION_REG.0 = 0 ' 1:1
    
    PAUSE 10
    
    Led1 VAR PORTA.0    'Assign leds. 
    Led2 VAR PORTA.1
    Led3 VAR PORTA.2
    Led4 VAR PORTA.3
    Led5 VAR PORTA.4
    
    Led6 VAR PORTB.0
    Led7 VAR PORTB.1
    Led8 VAR PORTB.2
    Led9 VAR PORTB.3
    Led10 VAR PORTB.4
    Led11 VAR PORTB.5
    Led12 VAR PORTB.6
    Led13 VAR PORTB.7
    Led14 VAR PORTA.6
    Led15 VAR PORTA.7
    
    Index VAR BYTE
    LookForThree VAR BYTE
    Val    VAR WORD
    Result VAR BYTE
    PAUSE 100
    
    
    Start:
    
    
        LookForThree = 0
        WHILE LookForThree <> 3   ' Look for three "SET"s.
            RANDOM Val            ' Get a random value.
            PAUSEUS TMR0          ' To get a good random number, have a changing value using TMR0 or TMR1.
        
            LookForThree = 0
            FOR Index = 0 TO 14   ' Scan through the bits.
                IF Val.0[Index] = 1 THEN LookForThree = LookForThree + 1 'Count "SET"s.
               
                NEXT Index
        
        WEND
    
        GOSUB SetPins
        PAUSE 1000
    
        GOTO Start
    
    SetPins:
    
        Led1  = Val.0
        Led2  = Val.1
        Led3  = Val.2
        Led4  = Val.3
        Led5  = Val.4
        Led6  = Val.5
        Led7  = Val.6
        Led8  = Val.7
        Led9  = Val.8
        Led10 = Val.9
        Led11 = Val.10
        Led12 = Val.11
        Led13 = Val.12
        Led14 = Val.13
        Led15 = Val.14 
        RETURN
    
    
    END
    it's now working good hooray! thanks for your help pips more power!

  5. #5
    Join Date
    Apr 2009
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    and oh i forgot i just switched to PIC16F628A



Similar Threads

  1. Code doesn't work on 16F648A
    By Mr_Joe in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 1st September 2018, 23:09
  2. I2C Master/Slave 16F88/16F767 working code
    By DanPBP in forum Code Examples
    Replies: 2
    Last Post: - 23rd October 2012, 23:31
  3. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 22:07
  4. Minimizing code space
    By Tobias in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th May 2009, 08:25
  5. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 09:26

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts