PDA

View Full Version : new to 8 pin pic



hoyles
- 22nd February 2008, 16:44
i wrote the program below that runs fine on a 16f84a, but i would like to port it over to a 12f629. i have no experience with this pic chip at all. help would be greatly appreciated.

i use it to send a positive pulse to a 2-coil latching relay using the same pushbutton.

push button on ra0 and rb0 pulses a "1" for about 1/2 second.(turns relay on)
push button on ra0 and rb1 pulses a "1" for about 1/2 second.(turns relay off)

i would also like to add an option of holding the same pushbutton down for a longer period of time, first, pulsing 1/2 second on rb0 .(turns relay on) and then go into a timer mode of about one hour and then pulsing 1/2 second on rb1..(turns relay off)

existing 16f84a program:

b0 var Byte
pb0 var PORTA.0

TRISB = %00000000

loop:
If pb0 = 1 and b0 = 0 Then one
If pb0 = 1 And b0= 1 Then two
Goto loop

one:
high 0
b0 =1
pause 2
low 0
goto loop

two:
low 0
high 1
b0 =0
pause 2
low 1
goto loop

end

thanks, in advance

mike

skimask
- 22nd February 2008, 16:52
help would be greatly appreciated.
Help? greatly appreciated? Looks to me like you want somebody to write the program for you...

I think (ok, I know) you'll get a lot more response and assistance if you write a program that attempts to use the functions you wish to use, and the rest of us can HELP YOU look thru the code to figure out why it's not performing up to your expectations.

hoyles
- 22nd February 2008, 17:05
the program (under "existing program" line works fine.

i want to transfer it to a 12f629 and continue to use it (and, if possible, add a section to it that will act as a timer to keep the relay on until the time has expired, turning the relay off.

i'm not really proud of it, but i did write the code for the existing program.
i do not want anybody to do it for me, thus the word "help"

what is this forum for?
i just wanted to be pointed in the correct direction.

mike

skimask
- 22nd February 2008, 17:13
the program (under "existing program" line works fine.
i want to transfer it to a 12f629 and continue to use it (and, if possible, add a section to it that will act as a timer to keep the relay on until the time has expired, turning the relay off.
i'm not really proud of it, but i did write the code for the existing program.

Well, if it works, then you should be proud of it. I don't care if it's the ol' blinky LED, or the next best nuclear fission controller. If it works, show it to the folks on the block... Can they do any better? Most likely not...

Transfer the program! It should transfer right over...except for the fact that the 12F629 doesn't have a PortB... I'll let you figure that one out...


i do not want anybody to do it for me, thus the word "help"
what is this forum for?
i just wanted to be pointed in the correct direction.

Funny how that works...'cause that's exactly what people want these days...instant gratification... It's amazing how many folks are the 'one-post' types looking for something for nothing.

Archangel
- 22nd February 2008, 17:32
Hello hoyles,
Open up the data sheet for the 12F . . . and see, as skimask said no port B, no Port A, funny thing called GPIO.
search here: http://www.google.com/custom?hl=en&cof=AH%3Aleft%3BS%3Ahttp%3A%2F%2Fwww.picbasic.co.u k%2Fforum%3BL%3Ahttp%3A%2F%2Fwww.crownhill.co.uk%2 Flogo.gif%3BLH%3A37%3BLW%3A174%3B&domains=picbasic.co.uk&q=12f675&btnG=Search&sitesearch=picbasic.co.uk search for 12F675 or whatever chip you like, lots of examples, use the link above unaltered.
I set it as my home page, except I have it default to web search not picbasic forum search. :)

hoyles
- 22nd February 2008, 17:36
hey skimask,

what do you do, get on this forum to make it harder to learn about pic programming?

thought the purpose of this forum was to get information not to get humiliated.

you must be in between bank robbing jobs (skimask) and have so much spare time on your hands that this is your way of getting pleasure.

skimask
- 22nd February 2008, 17:49
hey skimask,
what do you do, get on this forum to make it harder to learn about pic programming?
thought the purpose of this forum was to get information not to get humiliated.


Yep, that's exactly what I do...make it harder to learn...because that would require most people to actually put forth the effort to actually learn something new for a change, rather than be spoon fed, which is easier, yes? Which is exactly how I read your 1st post... and, AND, if you look REAL hard, you'll see that your 2nd post and my response to your 2nd post, along with Joe's follow-up to that, might also point you in the right direction to accomplish your goal.

And BTW...

you must be in between bank robbing jobs (skimask) and have so much spare time on your hands that this is your way of getting pleasure.
Did you come up with that one yourself? Or did someone give it to you on a forum somewhere else?
No, I don't have a lot of spare time. What I do have is a PC that's practically always on, so I leave a tab open to this site. When I pass by the workstation, I hit refresh and see what's up.

ruijc
- 22nd February 2008, 18:01
Hello hoyles,

let me give you some pointers on that ;)

For the PIC12F629/675 you have no portb, it's called GPio

So:

where you have :


TRISB = %00000000
pb0 var PORTA.0


you need to have something like:


trisio=%000001
pb0 var gpio.0

and for:



If pb0 = 1 and b0 = 0 Then one


you need to have something like:

if ( pb0=1 ) and ( b0=0 ) then one

Get the ideia?

hoyles
- 22nd February 2008, 18:33
thanks ruijc,

i guess what i should have asked first was, how to access the i/o pins on the 12f629 and how to identify them as inputs or outputs.
can i assume that the 6 i/o ports will be gpio.0 thru gpio.5?
are there any pull up resistors needed for the inputs?
are there any picbasic cammands that may not be used in this pic?

thanks,
mike

skimask
- 22nd February 2008, 18:44
thanks ruijc,
i guess what i should have asked first was, how to access the i/o pins on the 12f629 and how to identify them as inputs or outputs.
can i assume that the 6 i/o ports will be gpio.0 thru gpio.5?
are there any pull up resistors needed for the inputs?
are there any picbasic cammands that may not be used in this pic?
thanks,
mike

The answer to EVERY one of those questions is right in the PBP manual.

-You ask about I/O ports, there's a couple of pages in the PBP manual that have specific (to the 8 pin PIC) examples of the 8 pin PIC I/O ports and accessing them, as either inputs or outputs and setting or reading those inputs or outputs.
-You ask about pull ups? There may or may not be a section in the 12F629 datasheet about pullups.
-You have a 12 bit PIC, there's a whole section in the PBP manual on the 12 bit PIC and commands that may or may not have special needs when used with 12 bit PICs.
Tell me I'm wrong, and prove it, and I'll GIVE you every PIC I have in my desk drawer.

hoyles
- 22nd February 2008, 18:48
thanks skimask,

i did not realize that there was specific info on the 8 pin pic in the manual.

that should be a great help.

thanks again,
mike

Bruce
- 22nd February 2008, 19:40
Hi Mike,

Welcome to the forum. This series PIC has a 4MHz internal oscillator, an analog comparator,
and a host of other goodies you'll need the data sheet to get familiar with.

CMCON = 7 will disable the onboard comparator so you can use associated pins as digital I/O.

If you plan to use the internal oscillator, then you'll want to enable it using the INTRC_OSC
option in config. Use this below to get started. Just place the next line at the very beginning
of your program.



@ DEVICE pic12F629, INTRC_OSC_NOCLKOUT,WDT_OFF,PWRT_ON,MCLR_OFF,BOD_ON ,CPD_OFF,PROTECT_OFF
DEFINE OSCCAL_1K 1' Set OSCCAL for 1k ' <-- this loads the factory calibration value for the int osc

DEFINE OSCCAL_1K 1 is in your PBP manual.

If you're curious about what all these config options are, just look in the data sheet under
the Special Features of the CPU section. You might also want to use the search feature
here to turn up even more info, but this will get you up & going for now.

I/O-pins on these are refered to as GPIO. GPIO.0, GPIO.1, etc,,.

The TRIS register is called TRISIO. TRISIO = %xxx x being 1's or 0's for inputs or outputs.

Now try something simple just to get familiar with the 12F part;


@ DEVICE pic12F629, INTRC_OSC_NOCLKOUT,WDT_OFF,PWRT_ON,MCLR_OFF,BOD_ON ,CPD_OFF,PROTECT_OFF
DEFINE OSCCAL_1K 1

CMCON = 7

loop:
High GPIO.0 ' Turn on LED connected to 0
Pause 500 ' Delay for .5 seconds

Low GPIO.0 ' Turn off LED connected to 0
Pause 500 ' Delay for .5 seconds

GoTo loop ' Go back to loop and blink LED forever


TIP: Just in case, you might want to first read a new 12F629 with your device programmer,
and jot down the factory calibration value. If your programmer erases this, you'll need to
know what it was.

There should be several threads around here with info on finding the proper value again, so
I won't re-type it all again here.

Use the search feature here to look around for more on using the 12F series. If you have
more questions after reading any of them, then fire away.

MeLabs has a few examples for the LAB-X4 board you might also want to have a look at;
http://www.microengineeringlabs.com/doclist.htm#X4

P.S. The 12F629 is not a 12-bit core device. It's 14-bit, so pretty much any PBP command
should work just fine with it. As long as it's not a hardware command for a peripheral that
doesn't exist on the PIC itself.

hoyles
- 22nd February 2008, 19:58
thanks bruce,

that is the exact information i was looking for.

now it's time to experiment with it.

i have learned a lot over the years from your website. keep up the good work!

thanks again,

mike

skimask
- 22nd February 2008, 20:58
P.S. The 12F629 is not a 12-bit core device. It's 14-bit, so pretty much any PBP command should work just fine with it. As long as it's not a hardware command for a peripheral that doesn't exist on the PIC itself.
Jeeze...I don't know how many times I've done that to myself! I've done bunches of applications with the 12Fxxx and it seems like every time, I talk myself into the fact it's a 12-bit...only to RE-figure out after a few days that it's actually a 14.
(Ok...I'll take a burger and one FOREHEAD SLAP to go...)

Bruce
- 22nd February 2008, 21:24
Some of the 12Fxxx series are 12-bit core. Just not this one. In general, 12F5xx are
12-bit core, and 12F6xx are 14-bit core. The Program Memory Organization section of most
data sheets will normally indicate the core type, so it's worth a quick check if you're not
sure.