A simple startup question


Closed Thread
Results 1 to 7 of 7
  1. #1
    teilhardo's Avatar
    teilhardo Guest

    Question A simple startup question

    Hi,
    I just acquired the pic serial programmer and the Pic Pro compiler but I still need to know how to program a pic 16f628 to turn a pin high for 1 minute and low for 5 minutes. For a basic stamp this could be accomplished by:

    loop:
    high 1
    pause 60000
    low 1
    pause 60000
    pause 60000
    pause 60000
    pause 60000
    pause 60000
    goto loop

    I tried doing this on my 16f628 attached vdd to a 3V power supply but have not yet been succesful using code designer lite
    I would really appreciate anybody helping me out.
    Thanks,
    Tei

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Hi Tei,

    Your code should work as-is, but if you can provide a little more information, it helps list members to help you isolate the problem.

    What oscillator speed are you using?
    Are you using the internal RC osc or an external crystal or resonator?
    Do you have a pull-up resistor from Vcc to /MCLR or do you have /MCLR disabled?
    What type of 3V power supply are you using?
    Have you managed to get an LED to blink at all to test your circuit?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    teilhardo's Avatar
    teilhardo Guest


    Did you find this post helpful? Yes | No

    Default

    Hi Bruce,
    Thanks for answering. I plan to use the internal oscillator (and I think that I put that parameter into the programmer software right). What is /MCLR?
    The 3V power supply is currently just two AA batteries in series.
    Thanks again for the help,
    Tei

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by teilhardo
    I plan to use the internal oscillator (and I think that I put that parameter into the programmer software right).
    See this thread http://www.picbasic.co.uk/forum/showthread.php?t=543

    What is /MCLR?
    /MCLR is the PIC reset pin. It can also serve as an input pin on PICs with the option of turning off the /MCLR reset function.
    See this thread & the data sheet. http://www.picbasic.co.uk/forum/show...highlight=MCLR

    You might want to start out by building the circuit shown in your manual to blink the LED. Here's a simple blink program for your PIC. Note this does not require the external oscillator or resistor from Vcc to the /MCLR pin as shown in your PBP manual.
    Code:
    @ DEVICE PIC16F628,MCLR_OFF,LVP_OFF,INTRC_OSC,WDT_OFF
    
    Main:
       HIGH 0
       PAUSE 1000
       LOW 0
       PAUSE 1000
       GOTO Main
    
       END
    The first thread by Melanie explains what's up with the first line. It's well worth reading for anyone just getting started.

    Now, let's assume you build the "It's Alive" circuit exactly as shown in your manual, but you use the 16F628 VS the 16F84.
    Code:
    @ DEVICE PIC16F628,MCLR_ON,LVP_OFF,XT_OSC,WDT_OFF
    
    Main:
       HIGH 0
       PAUSE 1000
       LOW 0
       PAUSE 1000
       GOTO Main
    
       END
    Now /MCLR functions as the external device "reset" so you need the 4.7K pull-up from Vcc to the /MCLR pin, and you'll need the external crystal as shown in the It's Alive circuit example.

    Another option since you're using batteries is to use the WDT (watch dog timer). This example puts the PIC to sleep for the delay periods you want, and controls the LED.
    Code:
    @ DEVICE PIC16F628,MCLR_OFF,LVP_OFF,INTRC_OSC,WDT_ON
    
    Main:
       HIGH 0       ' LED on here
       SLEEP 60    ' Enter low power mode for around 1 minute
       LOW 0        ' LED now off
       SLEEP 300   ' Enter low power mode for around 5 minutes
       GOTO Main  ' Repeat the process
    
       END
    This example doesn't require the resistor to /MCLR, and uses the internal oscillator. This version will make those tiny little AA batteries last a good deal longer too. When in SLEEP mode the PIC uses very little power. This example is sleeping for the majority of your time delay periods.

    With the MeLabs serial programmer, make sure you have a check mark next to the two following things under the Options menu;

    Update configuration from file <-- this uses the config fuse options embedded in your .HEX file.

    Reread file before programming <-- this makes sure you're always loading & using the latest version of your code after it's been compiled.

    Now try your original example, but add the @ DEVICE line shown below to the top.
    Code:
    @ DEVICE PIC16F628,MCLR_OFF,LVP_OFF,INTRC_OSC,WDT_OFF
    loop:
       high 1
       pause 60000
       low 1
       pause 60000
       pause 60000
       pause 60000
       pause 60000 
       pause 60000
       goto loop
    This should get you started, but nothing is going to help you more than reading through the 16F628 data sheet, PBP manual & examples, and your programmers help file.

    All this stuff will make a lot more sense once you have....;o}
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    teilhardo's Avatar
    teilhardo Guest


    Did you find this post helpful? Yes | No

    Default Still some trouble

    Hi Bruce,
    Thank you very much for the informative descriptions. Unfortunately, after programming word for word into cd lite and then programming the PIC, it still ceases to work. I attached 3VDC to VDD, ground to VSS and then using an ohm meter, tested the voltage at RB0 and RA0, but got 0V everywhere I tried. Is it possible that 2.55V (the measured series voltage in the batteries) is to low?
    Thanks,
    Tei

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Minimum operating voltage for the non LF parts is 3V. Look in the data sheet under Electrical Specifications.

    Running at lower voltages, you'll normally need to turn off brown out detection, and power up timer.

    These are config fuse settings. You can change them by adding them to your config directive line, or using your programmers software.

    BODEN_OFF disables brown out detection allowing you to run the PIC at minimum voltage. PWRTE_OFF disables the power up timer.

    Change your config fuse directive line to something like this if you're not disabling these with your programmer before burn time.

    @ DEVICE MCLR_OFF,LVP_OFF,INTRC_OSC,WDT_OFF,BODEN_OFF,PWRTE _OFF

    You can save yourself a lot of time & aggravation by just getting a cheapo regulated +5VDC power supply. If you're just getting started, it's a lot easier working with 5V than a low-power design.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  7. #7
    teilhardo's Avatar
    teilhardo Guest


    Did you find this post helpful? Yes | No

    Default

    No wonder it didn't work. I'll run down to radioshack and see what I can get

Similar Threads

  1. Stupid simple question.....
    By chien_fu in forum mel PIC BASIC
    Replies: 18
    Last Post: - 23rd February 2010, 13:21
  2. Really simple question for you experts :)
    By lew247 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 4th June 2008, 01:43
  3. SIMPLE question
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 5th February 2008, 18:27
  4. really simple, dumb question
    By picster in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 3rd March 2007, 22:02
  5. Simple question, I hope? (Serial control, 16F84A)
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 31st December 2005, 19:47

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