Can someone help me make a code for this:


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    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!

  2. #2
    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, 22:09
  2. I2C Master/Slave 16F88/16F767 working code
    By DanPBP in forum Code Examples
    Replies: 2
    Last Post: - 23rd October 2012, 22:31
  3. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  4. Minimizing code space
    By Tobias in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th May 2009, 07:25
  5. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08: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