View Full Version : A simple startup question
teilhardo
- 3rd January 2006, 06:14
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
Bruce
- 6th January 2006, 22:01
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?
teilhardo
- 7th January 2006, 02:22
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
Bruce
- 7th January 2006, 04:08
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/showthread.php?t=2965&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.
@ 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.
@ 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.
@ 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.
@ 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}
teilhardo
- 7th January 2006, 06:52
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
Bruce
- 7th January 2006, 16:15
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.
teilhardo
- 7th January 2006, 20:33
No wonder it didn't work. I'll run down to radioshack and see what I can get
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.