View previous topic :: View next topic |
Author |
Message |
mmc01
Joined: 16 Jun 2010 Posts: 31
|
How to program PIC 12F629 ? |
Posted: Mon Jul 21, 2014 11:16 pm |
|
|
I program to 12F629. It have GP0-GP5. I can't use the code like this. 12F629 should use internal clock. I want to use microcontroller for 5 PIN only. What the number of microcontroller PIC suitable for me ? How to program PIC 12F629 ?
Code: |
void main (void)
{
while(TRUE){
if(!input(GP0)){
output_high(GP2);
delay_ms(500);
}
}
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19559
|
|
Posted: Mon Jul 21, 2014 11:36 pm |
|
|
Post the rest of your code. The processor setup etc..
These are what define which pins you can use.
The only PIC's with 5 I/O pins or more, are the 8 pin PIC's like the 629, so stick with what you have.
Programming it depends on what programmer you have?.
Code: |
#include <12F629.h>
#FUSES NOWDT, INTRC_IO, NOMCLR, NOBROWNOUT
#use delay(INTERNAL=4000000)
void main()
{
setup_comparator(NC_NC);
output_low(GP2);
while(TRUE)
{
if(!input(GP0))
{
output_high(GP2);
delay_ms(500);
output_low(GP2); //you needto lower the line again
//or it'll stay high forever...
}
}
}
|
This is the 'example' program with fuses and clock, to give 5 general purpose I/O lines, and one input only line on GP3.
Note also that you have to pull GP2 low before and after you pull it high, or it'll just stay high forever. |
|
|
mmc01
Joined: 16 Jun 2010 Posts: 31
|
|
Posted: Tue Jul 22, 2014 12:47 am |
|
|
when I compile it show error like this. How to use 12F629 with CCS ?
Quote: | Error 12 "main.c" Line 8(15,18): Undefined identifier GP2
Error 12 "main.c" Line 11(18,21): Undefined identifier GP0
Error 12 "main.c" Line 13(25,28): Undefined identifier GP2
Error 12 "main.c" Line 15(24,27): Undefined identifier GP2
4 Errors, 0 Warnings |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19559
|
|
Posted: Tue Jul 22, 2014 12:52 am |
|
|
I used the names you used in your code. You must have them defined somewhere. Your definitions need to be added if you are using your own names. The standard names are PIN_A0 to PIN_A5 (for current compilers). |
|
|
mmc01
Joined: 16 Jun 2010 Posts: 31
|
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1938 Location: Norman, OK
|
|
Posted: Thu Jul 24, 2014 8:40 pm |
|
|
From the 12F629 CCS header file:
Quote: | // Constants used to identify pins are:
#define PIN_A0 40
#define PIN_A1 41
#define PIN_A2 42
#define PIN_A3 43
#define PIN_A4 44
#define PIN_A5 45
|
_________________ Google and Forum Search are some of your best tools!!!! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 25, 2014 12:11 am |
|
|
If you want to use the "GP" names for the pins, just add this code above main():
Code: |
#define GP0 PIN_A0
#define GP1 PIN_A1
#define GP2 PIN_A2
#define GP3 PIN_A3
#define GP4 PIN_A4
#define GP5 PIN_A5
|
|
|
|
|