• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Beginning Programming; 12F629

Status
Not open for further replies.
Hey all, I'm getting started programming PICs, preferrably in C. I have a fairly strong background in C, so it is naturally my language of choice. I already have several C compilers to work with, as well as a modified JDM programmer.

Anyhow, I'm finding tons of resources on programming the 16 and 18 series PICs, but not alot on the 12 series, which I want to use for a compact design.

My goal is to have an LED connected to GP0 flash at 10Hz while a button connected to GP1 is pressed, but otherwise remain off. I found several simple programs for this in BASIC and ASM, but none in C.

Also, I have a working program for simply flashing an LED in C, but it's developed for the 16F84. As I understand, the 12 and 16 series use different instruction sets, so it won't work on the 12F629.

Any advice, or help? I'm quite new to this.
 
I tried the BoostC compiler, but I didn't care for it. I'm currently using mikroC compiler though.

Anyhow, thanks for clearing that up about the 12F629.

Basically, when I compile the program for a 16F, it works fine, but for the 12F629 it gives me a bunch of errors like I said before. The program I'm using is;

Code:
void main() 
{ 

while(1) 
   { 
    output_high(PIN_A0); 
    delay_ms(500); 
    output_low(PIN_A0); 
    delay_ms(500); 
   } 

}
Supposedly, mikroC takes care of the headers and the fuses, but I like to see all of the coding. Is there a C compiler that works more like that? Something similiar to ol' Visual Studio? lol

Anyhow, perhaps someone can shed some light on the program I'm using, I'm sure I'm doing something it doesn't like. :p
 
First off, the PIC 8pin, 6pin devices use GPIO,0, GPIO,1,.. instead of PortA,1, PortA,2....etc. So unless the compiler is somehow doing the conversion for you? Sometime you will have to look at the compiler manual/docs, data sheets, or failing that, search out an example using your particular device and compiler.

P.S. The 12f629 is in the same family as the popular 12f675, so code for that should work with the 12f629.
 
Last edited:

Mike - K8LH

Well-Known Member
I tried the BoostC compiler, but I didn't care for it......
What didn't you like about it? You can run it in the MPLAB IDE if you don't care for the SourceBoost IDE.

Anyway, here's an MPLAB BoostC project source file for the 12F629 that compiles fine.

Kind regards, Mike

Code:
#include <system.h>

#pragma DATA _CONFIG, _MCLRE_OFF&_WDT_OFF&_INTRC_OSC_CLKOUT

#pragma CLOCK_FREQ 4000000

void main()
{ cmcon = 7;                        // comparator off, digital I/O
  trisio = 0b00000010;              // GP0 output, GP1 input
  gpio = 0;                         // make all outputs '0'
  option_reg.NOT_GPPU = 0;          // enable weak pull-ups
  wpu.1 = 1;                        // enable GP1 weak pull-up

  while(gpio.GP1 == 0)              // while GP1 switch pressed
  { gpio.0 = 1;                     // flash LED at 10 Hz rate
    delay_ms(50);                   //
    gpio.0 = 0;                     //
    delay_ms(50);                   //
  }
}
 
Last edited:
First off, the PIC 8pin, 6pin devices use GPIO,0, GPIO,1,.. instead of PortA,1, PortA,2....etc. So unless the compiler is somehow doing the conversion for you? Sometime you will have to look at the compiler manual/docs, data sheets, or failing that, search out an example using your particular device and compiler.

P.S. The 12f629 is in the same family as the popular 12f675, so code for that should work with the 12f629.
*facepalm* Wow, somehow I knew I was doing something stupidly simple like that. Thanks!

What didn't you like about it? You can run it in the MPLAB IDE if you don't care for the SourceBoost IDE.

Anyway, here's an MPLAB BoostC project source file for the 12F629 that compiles fine.

Kind regards, Mike
Thanks for the code, I'll give that a shot when I get home. I didn't try and run it in MPLAB, I just didn't care for the IDE. Anyhow, thanks for the help, that bit of code explains alot.
 
Ok, I got BoostC for MPLAB, but it only supports 16 and 18 series PICs. I tried compiling that program in mikroC, but it had several errors.

With;

Code:
#include <system.h>
It can't find system.h.


Without it nor the #pragma's, it gives the following errors.



Ideas? I think it's just mikroC.

The code I'm using is;

Code:
#include <system.h>
#pragma DATA _CONFIG, _MCLRE_OFF & _WDT_OFF & _INTRC_OSC_CLKOUT
#pragma CLOCK_FREQ 4000000				

void main()
{ 
  cmcon = 7;
  trisio = 0b00000010;
  gpio = 0;
  option_reg.NOT_GPPU = 0;
  wpu.1 = 1;

  while(gpio.GP1 == 0)              				
  { 
    gpio.0 = 1;                     				
    delay_ms(50);						
    gpio.0 = 0;
    delay_ms(50);
  }
}
 
Last edited:

be80be

Well-Known Member
BoostC supports 12f629 it the same core as 16f628 it's take a look here and it show's what chips you can use SourceBoost Technologies

PIC12

PIC12F609, PIC12HV609, PIC12F615, PIC12HV615, pic12f629, PIC12F635, PIC12C671, PIC12C672, PIC12CE673, PIC12CE674, PIC12F675, rfPIC12F675f, rfPIC12F675k, rfPIC12F675h, PIC12F683
 
Last edited:
Thanks everyone, I got it working. In the MPLAB Project Wizard I set it as using a 12F629, but used the BoostC 16 Series compiler. Everything from there on worked perfectly. ^_^

Now though, I have a question about looping. I know the mcu needs to be intentionally stuck in an infinite loop, correct? In a simple program like that one, it's clearly looped by the "while" statement. However, if in a more complicated program, several other functions take place before the "void main", will the while loop still be in effect?

Sorry if that sounds a little cloudy, it's just weird to phrase correctly.
 
Sorry for the double posts and whatnot, but I have another question and my internet time is limited.

I've got the 12F629 working for the project I needed it for, so I'm onto something else. Now, I'm working on using a 16F882. However, I'm having problems with the coding for it.

Just so I can get an idea of the 16F882's structure, could someone post a blinking LED program for it?
 

Nigel Goodwin

Super Moderator
Most Helpful Member
It's a 14 bit device and uses the same core as all others, the 16F628 examples in my tutorials will work with VERY minor changes - just compare the two datasheets.
 

be80be

Well-Known Member
This has some good C code it for a pickit1 it use 12f675 but all you change for most of them is 12f675 to 12f629 inc and lkr.secsoftwaredownload down load the one that is All lessons
 
Last edited:

Pommie

Well-Known Member
Most Helpful Member
This should get you up and running,

Code:
#include <system.h>
#pragma DATA _CONFIG, _DEBUG_OFF & _MCLRE_ON
                    & _CP_OFF & _PWRTE_OFF
                    & _WDT_OFF & _INTOSCIO
                    & _LVP_OFF
#pragma CLOCK_FREQ 8000000

void main(void){
    osccon=0x72;            //8 meg
    ansel=0;                //all digital
    anselh=0;
    trisa.0=0;              //make output
    while(1)              				
    { 
        porta.0 = 1;                     				
        delay_ms(200);						
        porta.0 = 0;
        delay_ms(200);
    }
}
Mike.
 

be80be

Well-Known Member
Just so I can get an idea of the 16F882's structure, could someone post a blinking LED program for it?
 
Last edited:

Pommie

Well-Known Member
Most Helpful Member
12f629 doesn't have analog-to-digital converter I thought it did but it don't
I used the same Hex on both chips lol for a blinky
Not to say it wrong Mike I bet you been playing with the 12f683 I love that chip
But, he asked about the 16F882 which is what the above code is for.

Mike.
 

be80be

Well-Known Member
I missed that Thanks for the help Mike I have a door lock Thanks to you and digg He showed me how to use arrays better. I think I like C better then basic. Thought he was still using the 12f629. Man I hope some day I can pop clean
code out like you can Mike . My thing is I want to put the horse behind the cart. Still need to work on flow:D
 
Last edited:
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top