Very first use of PBP (newbie!)


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Sep 2007
    Posts
    26

    Default Very first use of PBP (newbie!)

    Hi all,

    I just got my first program working on PBP. I have bought lots of books but am waiting for them to arrive. I was just wondering why I had this problem getting the blink.bas example working.

    Portb.0 doesn't work. I tried portb.1 by chance and it worked. As I understand it, there are all sorts of registers to set and I have got the datasheet for the PIC I am using (16F886) but for someone as new as me, the datasheet doesn't tell me why. I have got a lot to learn!

    I thought High and Low caused pins to become outputs so I didn't need to do anthing special with registers.

    I have done quite a bit of work with PICAXE and when I change the osc freq on PICAXE the pause command is affected. I tried changing the freq from 4 to 8 in this code example and expected the LED to blink twice as fast but it didn't. Is PBP cleverer or have I not actually doubled the clock freq. I am using the internal osc.

    Can anybody lend me a small hand with getting started on understanding datasheets and this specific problem.

    Thanks

    Rich
    Code:
    define osc 8
    led var Portb.0
    led2 var Portb.1
    loop:   High led         ' Turn on LED connected to PORTB.0
    High led2         ' Turn on LED connected to PORTB.0
            Pause 500       ' Delay for .5 seconds
    
            Low led           ' Turn off LED connected to PORTB.0
            low led2
            Pause 500       ' Delay for .5 seconds
    
            Goto loop       ' Go back to loop and blink LED forever
            End

  2. #2
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    This may not be the problem, but try setting all the I/O to digital (i.e not analog) by adding the following to the top of your code:

    Code:
    ANSEL=0
    ANSELH=0
    For info on the ANSEL registers, see pages 42 and 50 in the 16F886's datasheet.

  3. #3
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    Hi Rich,

    Just declaring DEFINE OSC 8 does not set the clock completely. Are you using and external crystal or resonator or are you using the internal oscillator?

    You program looks like it should work once the oscillator question is determined. It would hurt to add at the start of your program: TRISB = %00000000. 0's set the port pins to outputs and 1's set the pins as inputs. So if you wanted Port B.2 for example to be an input and the rest of Port B to be outputs then TRISB = %00000100 would take care of that. High and low statements make the particular output pin either high or low. You could set PortB.0 to low by saying PortB.0=0 or in your case just like you have it in your program.

    I was trying to get online with Microchip to look at the datasheet for your PIC but they seem to be down right now. Look at the pin descriptions near the from of the datasheet. It describes the features available on each pin. If the Port B pins can be analog as well as digital then you must disable the analog feature as Kamikaze was saying.

    I really think from the very limited information you have provided the problem is in the oscillator. Give us more information on that: internal vs external: if external are you using a crystal or resonator, 4 or 8mhz. I won't be back until tonight so maybe someone else might jump in here to help out, but I think what I have put here should help you get on track.

    HTH,

    BobK

  4. #4
    Join Date
    Jul 2007
    Posts
    53


    Did you find this post helpful? Yes | No

    Default A few things are wrong here

    Rich,

    "define osc 8" Is NOT changing oscillator frequency, It's just telling PBP at which frequency the oscillator is running. And most important, all defines must be in UPPERCASE when using PBP. Not 100% sure if required, but I would also try writing PORTB.0 uppercase.

    BobK is right too, try adding define TRISB = %00000000. I don't exactly remember why, but I had some problem a while ago using high and low without having defined the port as an output, (but PORTB.0=1 was working fine!)

    Picaxe is fantastic to learn PIC, but is missing all details related with PIC registers. When you're programming with PBP you have to read and understand the datasheet of the chip you're using. Then you will be able enjoy PBP and use all the flexibility of you're PIC.

    J-P
    Last edited by GrandPa; - 15th September 2007 at 19:41.

  5. #5
    Join Date
    Sep 2007
    Posts
    26


    Did you find this post helpful? Yes | No

    Default Fixed it

    Hi all,

    thanks for your help everyone. It ended up being the setting of ANSEL and ANSELH. I added the ANSEL line and portb.0 started working. So I tried to alternate all portb pins between low and high in same block of code. Then the portb.0 through portb.5 pins didn't work but portb6 and 7 did. So I added ANSELH=0 and then they all started working.

    I have learnt something. Read and understand the datasheet. This is my first experience of translating the datasheet into programming registers and now I know how important it is. It's not a PICAXE!!

    So if DEFINE OSC 8 doesn't change internal osc freq, what does I wonder. I am of course, not using an external osc and the chip supports 8mhz. I will read datasheet and see if I can work it out but if I haven't posted back here by the time someone sees this, please enlighten me!

    Thanks again guys

    Rich

  6. #6
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Check out page 64 of the datasheet. It will tell you how to set the internal oscillator frequency.

    To set the oscillator to 8Mhz for example:

    Code:
    define osc 8
    OSCON=%01110000
    or 4Mhz:

    Code:
    define osc 4
    OSCON=%01100000
    *edit* Page 64 according to adobe anyway - page 62 according to the page numbers at the bottom of the pages.

  7. #7
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi Rich,
    You picked a PIC with lots of options that differ from run of the mill, Multi config registers and the like. Hard to learn to drive in a performance car, maybe start out with a Rambler or a Fiat check your other post for answers.
    JS
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  8. #8
    Join Date
    Sep 2007
    Posts
    26


    Did you find this post helpful? Yes | No

    Default

    Cool guys, very cool. I now understand how to use the registers a lot better. Setting the osc freq makes perfect sense!

    I am using the 16f886 because I used to do a lot with Picaxe and it is the chip that the 28x1 Picaxe chip is based on. I have a few of them so I am reusing.

    When I was young I used to do lots of handbrake turns and all sorts of crazy stuff. Whilst I'm sure I am lucky to still be alive, I really believe it has made me a better driver!

    Thanks again

    Rich

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 12:55
  2. PBP, ASM and LST files
    By HenrikOlsson in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th January 2010, 13:43
  3. Compiler differences between PBP 2.33 & 2.46
    By nikopolis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd May 2006, 19:01
  4. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th December 2005, 23:30
  5. PBP / XP Crash
    By pondindustrial in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 27th November 2005, 03:16

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