1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Electronics Pic16f88 code help

Discussion in 'Modding' started by hcker2000, 20 Feb 2006.

  1. hcker2000

    hcker2000 What's a Dremel?

    Joined:
    21 Oct 2004
    Posts:
    109
    Likes Received:
    0
    Alright I'v got this bit of code here that compiles alright but some thing isnt working because when I hook up my pic16f88 it dose nothing but sit there. Im programing with IC-Prog 1.05D and wish to use the internal timing crystal.

    Code:
    program LED_Patterns
    
    sub procedure pNightRider            'Night Rider LED Pattern
      dim x as byte
       dim vNightRider as byte
       vNightRider = $00000001
    
       for x = 0 to 5 step 1
          vNightRider = vNightRider << vNightRider
          PORTA = vNightRider
       next x
    
       for x = 5 to 0 step -1
          vNightRider = vNightRider >> vNightRider
          PORTA = vNightRider
       next x
    
       return
    end sub
    
    Main:
    dim Pattern as byte                  'Variable to store current pattern
    
    TRISA = 0                        'Configure pins of PORTA as output
    TRISB = %00000001                  'Configure first pin of PORTB as input and the rest as output
    INTCON = %10010000                  'Enable Interrupts
    Pattern = 0                     'Set it to 0 when the pic starts
    
       while true                     'Main Loop
          if Pattern = 0 then
             pNightRider
          else if Pattern = 1 then
                                  'add code here
             end if
        end if
       wend
    end. 
    
     
  2. Hazer

    Hazer In time,you too will be relixalated

    Joined:
    14 Apr 2003
    Posts:
    957
    Likes Received:
    2
    Im gonna have to let someone else handle this. I only know MPASM. From the look of this, it seems like there is no timing for the pattern, and the loop would be going so fast that all the LEDs would appear to be on all the time.

    Also, do you have MCLR held high with a pull-up resistor when operating?
     
  3. SteveyG

    SteveyG Electromodder

    Joined:
    23 Nov 2002
    Posts:
    3,049
    Likes Received:
    8
    I'm not too familiar with the 16F88, but usually PORTA is assigned to AD conversion and the comparator. Be sure to turn off all AD inputs on PORTA as they are not disabled at power up. See ADCON1 and CMCON.
     
  4. hcker2000

    hcker2000 What's a Dremel?

    Joined:
    21 Oct 2004
    Posts:
    109
    Likes Received:
    0
    Oh crap that could be it. I will check the AD register and disable them. I'v disabled the MCLR fuse just so I don't have to pull it high.

    I have put a Delay_ms(500) under the PORTA = vNightRider (both of them). I thought this was the issue as well but now I'm thinking its the AD or comparator.
     
    Last edited: 21 Feb 2006
  5. bigal

    bigal Fetch n Execute

    Joined:
    8 Oct 2004
    Posts:
    609
    Likes Received:
    0
    i didnt realise you could program PICs with basic? its not a PICAXE is it?
     
  6. hcker2000

    hcker2000 What's a Dremel?

    Joined:
    21 Oct 2004
    Posts:
    109
    Likes Received:
    0
  7. bigal

    bigal Fetch n Execute

    Joined:
    8 Oct 2004
    Posts:
    609
    Likes Received:
    0
    cool i will look into that!
     
  8. Macaba

    Macaba What's a Dremel?

    Joined:
    4 Mar 2006
    Posts:
    107
    Likes Received:
    1
    To use the internal oscillator, you have to set the OSCCON register.
    Something like:

    OSCCON = 01110000 'Set internal Osc to 8MHZ

    Double check the datasheet, but it should work for your PIC (It works for 16F819)

    MAKE SURE the CONFIG1 register has the Fosc values correctly set to 101 or 100 to select the internal oscillator.

    You can read up on these registers in Chapter 15 (Special Features of the CPU) of the Datasheet.
     

Share This Page