Old and beyond help ?


Closed Thread
Results 1 to 40 of 47

Hybrid View

  1. #1
    Join Date
    Dec 2007
    Location
    Northants England
    Posts
    38

    Unhappy Old and beyond help ?

    Just returning to PIC programming after a years gap and seem to have forgotten what little I knew. Have just bought the PICkit2 to use in conjunction with PICbasic Pro. Managed (with some difficulty to get them working together and have tried to implement the good old blink program on the 44 pin demo board (PIC 16f887)with the following code:

    define osc 4
    TRISD = 0
    loop: PORTD.0 = 1 ' Turn on LED connected to PORTD.0
    Pause 500 ' Delay for .5 seconds

    PORTD.0 = 0 ' Turn off LED connected to PORTD.0
    Pause 500 ' Delay for .5 seconds

    Goto loop ' Go back to loop and blink LED forever
    End

    All the darned thing does when I compile and program from McS is to fire up the PICKit2 OK and when I hit the Auto imort hex and write file button it programs the thing OK but when I put the power onto the demo board all 8 of the LEDs on port B light. Got a feeling it has something to do with those darned configuration thingies .. Never did really understand those and now the old grey cells are packing up at a rate of knots... I would be very grateful if anyone could indicate what particular piece of stupidity I have perpetrated this time round.. Thanks for your patience folks ....

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    The default oscillator config for the 887 is XT. But it's easy to switch to the internal oscillator without using configs.
    Just add OSCCON = %01100001 for 4mhz, or OSCCON = %01110001for 8mhz.
    And clear PORTD before setting TRIS.

    Code:
    define osc 4
    OSCCON = %01100001
    PORTD = 0
    TRISD = 0
    loop: PORTD.0 = 1 ' Turn on LED connected to PORTD.0
    Pause 500 ' Delay for .5 seconds
    
    PORTD.0 = 0 ' Turn off LED connected to PORTD.0
    Pause 500 ' Delay for .5 seconds
    
    Goto loop ' Go back to loop and blink LED forever
    End
    Tested on my PicKit2 with 887 on the Debug Express board.
    DT

  3. #3
    Join Date
    Dec 2007
    Location
    Northants England
    Posts
    38


    Did you find this post helpful? Yes | No

    Smile

    Thanks for that Darrel, works a treat although I am still not quite sure why I need to clear PORTd before using TRIS. It has always seemed to me that there is a real need for a genuine idiot's guide (speaking as a genuine idiot). For instance the PICbasic manual early on gives the usual little blink program but there is no mention of setting up oscillators clearing registers etc. without which it wont work ! Just a thought as I have always felt that mant people are put off learning about a fantastic piece of kit which is a shame as once having got over all these teething troubles the system is a joy to use.
    Thanks again
    Regards
    David Marks

  4. #4
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default It is good practice

    Hi,

    It is good practise to set the PORT to a known state before using the TRIS register to enable the outputs. When the pic starts up the PORT register can be anything so by setting it before we enable the outputs we dont have to sit there looking at our project going up in smoke just becuse the PORT ended up at a random unlucky combination.

    /me

  5. #5
    Join Date
    Dec 2007
    Location
    Northants England
    Posts
    38


    Did you find this post helpful? Yes | No

    Default

    Thanks Jumper I take the point. Now another daft question. In order to get my Christmas "Star of David" working I need three 8 bit ports and was planning to use the 44 pin demo board. Port A.6 and PortA.7 will not work as outputs presumable because they are connected to the crystal . Sinc I am using the internal oscillator can I do anything to make these two pins available as outputs. Incidentally maybe I am going blind but I can't see any reference to the osccal command in the manual.
    Cheers

  6. #6
    Join Date
    Oct 2004
    Location
    North Norfolk UK
    Posts
    146


    Did you find this post helpful? Yes | No

    Default

    Hi David

    One quick way to always find out what pins can do is look at the graphical pin layout in the datasheet in this case for the 887 on page 6, It shows the osc pins as being multiple use. I might then look on table 1-1 on page 16 and find say RA6/osc2/clkout and the table will describe, as it does here, that this pin can be assigned RA6 (portA 6) or osc1 or clkin. Also gives brief info and again in this case gives a bit more info that RA6 is a TTL CMOS general purpose I/O, Usually these chips are defaulted in their pin configuration but are easily changed, I would then search down to page 45 which confirms how these pins can be used.

    I might guess that if you choose the internal osc without a clock_out/in then the pin could become an I/O, so then I might hunt through section 4, I know it might sound boring but once you have read and got a feel for the oscillator module on one chip all the others are very very similar. I have not been following your project and I am just looking in briefly, so I hope I may have helped rather than hindered but I see you have been grappling with the config fuses already.

    Don't worry I'm sure you'll get those lights up before Crimbo.

    anyway doesn't one only need 12 leds to represent this particular motif


    __

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