PIC 12f629 cant get GP0, GP1, GP2 to go high

Discussion in 'Programmer's Corner' started by amitr12345, Jun 24, 2013.

  1. amitr12345

    Thread Starter Member

    Jun 17, 2013
    37
    2
    i have a pic 12f629 and i can't get it to go high on GPIO1 or GPIO2 or any GP for that matter.

    my code is :
    Code ( (Unknown Language)):
    1.  
    2. #include <htc.h>        /* HiTech General Include File */
    3. #endif
    4. #include <stdint.h>        /* For uint8_t definition */
    5. #include <stdbool.h>       /* For true/false definition */
    6. #include <stdio.h>
    7. #include <stdlib.h>
    8. #include <pic.h>
    9.  
    10.  
    11. #include "system.h"        /* System funct/params, like osc/peripheral config */
    12. #include "user.h"          /* User funct/params, such as InitApp */
    13. #define _XTAL_FREQ 4000000
    14. /******************************************************************************/
    15. /* Main Program                                                               */
    16. /******************************************************************************/
    17. __CONFIG(FOSC_INTRCIO & BOREN_ON & CP_OFF & MCLRE_ON & WDTE_OFF & PWRTE_OFF & CPD_OFF);
    18. //__CONFIG(IOSCFS_4MHZ & WDTE_ON & PWRTE_ON & MCLRE_ON & BOREN_OFF & CP_OFF);
    19.  
    20. void main(void)
    21. {    
    22.     TRISIO = 0b000000; //GP1 LED ONLY
    23.     INTCON = 0x0;     /* disable all interrupts */
    24.     CMCON = 0x0;     /* turn off comparators */ tried also CMCON=0x7;
    25.     GPIO = 0b000111;
    26.     for(;;){;}
    27. }
    28.  
    would appreciate any help ..
     
    Last edited by a moderator: Jun 25, 2013
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    ... You have a pull-up resistor on MCLR? You have it enabled...
     
  3. amitr12345

    Thread Starter Member

    Jun 17, 2013
    37
    2
    No, i havent.. Is it critical to have a 10k resistor between vdd and mclr?

    I checked that mclr is 5volt all the time, which means it lets the circuit run

    Correct me if i am wrong?
     
  4. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    you also need to set the ANSEL register in order to configure the pins as digitalI/O...
     
  5. amitr12345

    Thread Starter Member

    Jun 17, 2013
    37
    2
    Tried it with mclr off.. Same thing
     
  6. amitr12345

    Thread Starter Member

    Jun 17, 2013
    37
    2
    Ansel is non existent in 12f629.
     
  7. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Consider this your correction. MCLR us a master reset, leaving one floating is bad juju... Either connect a pull-up, or disable it in the configuration...
     
  8. amitr12345

    Thread Starter Member

    Jun 17, 2013
    37
    2
    Changed mclr to off, and i will connect a pull up..

    But still, is there a reason why gp0, gp1, gp2 doesnt go high?

    By the way gp4 and 5 outputs 2volts...??
     
  9. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    I'd say check your connections and post a schematic of the whole thing...
     
  10. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    CMCON=7; is a must. The comparator is on GP0-GP2...

    Read P37 and P39 of the datasheet.

    Allen
     
  11. amitr12345

    Thread Starter Member

    Jun 17, 2013
    37
    2
    here is the last code which doesn't output to high also GP0, GP1, GP2:

    Code ( (Unknown Language)):
    1.  
    2. __CONFIG(FOSC_INTRCIO & BOREN_ON & CP_OFF & MCLRE_OFF & WDTE_OFF & PWRTE_OFF & CPD_OFF);
    3.  
    4. void main(void)
    5. {
    6.     TRISIO = 0b000000; //GP1 LED ONLY
    7.     INTCON = 0x0;     /* disable all interrupts */
    8.     CMCON = 0x7;     /* turn off comparators */
    9.     GPIO = 0b111111;
    10.     for(;;){;}
    11. }
    12.  
    no schematic, because nothing is connected, just want to see high on GP2..
    any new ideas ? maybe chip is damaged ?
     
    Last edited by a moderator: Jun 25, 2013
  12. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    It's entirely possible that the compiler is optimizing the for loop away, making the chip(probably) reset and reinitialize the PIC, which would mean you should see about 1/2 VDD on the outputs.... Perhaps something like:
    Code ( (Unknown Language)):
    1. __CONFIG(FOSC_INTRCIO & BOREN_ON & CP_OFF & MCLRE_OFF & WDTE_OFF & PWRTE_OFF & CPD_OFF);
    2.  
    3. volatile unsigned char volatileVariable;
    4. void main(void)
    5. {
    6.     TRISIO = 0b000000; //GP1 LED ONLY
    7.     INTCON = 0x0;     /* disable all interrupts */
    8.     CMCON = 0x7;     /* turn off comparators */
    9.     GPIO = 0b111111;
    10.     for(volatileVariable = 0;;++volatileVariable){;}
    11. }
    ...would work...
     
  13. amitr12345

    Thread Starter Member

    Jun 17, 2013
    37
    2
    tried it, doesnt work...

    maybe damaged chip ?
     
  14. amitr12345

    Thread Starter Member

    Jun 17, 2013
    37
    2
    Maybe i should ask in another way.

    Supposed u had a pic 12f629 no circuit wired yet. U just wanted to check that gp2 goes high. In hi-tech(the code style i used), what would be your code so it would work ?
     
  15. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    I changed the code a bit and it works...

    Code ( (Unknown Language)):
    1. #include <pic.h>
    2.  
    3. __CONFIG (FOSC_INTRCIO & BOREN_ON & CP_OFF & MCLRE_OFF & WDTE_OFF & PWRTE_OFF & CPD_OFF);
    4.  
    5. void main(void)
    6. {
    7. CMCON = 0x7; /* turn off comparators */
    8. INTCON = 0x0; /* disable all interrupts */
    9. while (1)
    10. {
    11. TRISIO = 0b000000; //GP1 LED ONLY
    12. GPIO = 0b111111;
    13. }
    14. }
    Attached is the simulation with proteus.

    Allen
     
  16. amitr12345

    Thread Starter Member

    Jun 17, 2013
    37
    2
    thank u...

    i will try it when i get home.. it make sense to change the sorting of the code
     
  17. amitr12345

    Thread Starter Member

    Jun 17, 2013
    37
    2
    tried it.. tested on GP0->GP2.. the legs are not connected to anything.

    shows 0.1 volts in the legs of the microcontroller.

    could the chip be damaged ??
     
  18. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    It's possible the chip it's damaged, but unlikely, these things can take a beating...

    What programmer are you using? What us your power supply, both the voltage and the supply device?
     
  19. amitr12345

    Thread Starter Member

    Jun 17, 2013
    37
    2
    I am using a 5 volt regulated power supply

    Also in programming and also in burning.

    Using pickit 3 with mplab ipe, mplabx compiler
     
  20. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    MPLABX isn't a compiler... it looks like you are trying to use the Hi-Tech compiler...

    Make sure your files are included in your workspace...
     
Loading...