• AVR Freaks

Hot!PIC12F675 GPIO2 No Function

Page: 12 > Showing page 1 of 2
Author
KE4NYV
Super Member
  • Total Posts : 186
  • Reward points : 0
  • Joined: 2005/10/30 13:48:23
  • Location: Greenbackville, VA, USA.
  • Status: offline
2020/01/02 18:26:26 (permalink)
0

PIC12F675 GPIO2 No Function

No matter what I have tried, I cannot get GPIO2 to toggle an LED (just a simple test).  GPIO1 is working.
 
Here is my code:
 
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>

// PIC12F675 configuration
#pragma config FOSC = INTRCIO
#pragma config WDTE = OFF
#pragma config PWRTE = OFF
#pragma config MCLRE = ON
#pragma config BOREN = OFF
#pragma config CP = OFF
#pragma config CPD = OFF
 
#define _XTAL_FREQ 4000000
 
void main(void)
{
    ANSEL = 0x00; //disable all analog pins and make digital I/O
    ADCON0 = 0x00; //disable internal ADC
    CMCON = 0x07; //disable comparator
    VRCON = 0x00; //disable voltage reference
    T1CONbits.TMR1CS = 0x0; //disable external clock on GP5
    
    TRISIO = 0b11000000; // set mode of all pins
    
    while(1)
    {
        GP0 = 0;
        GP1 = 1;
        GP2 = 1;
        GP3 = 0;
        GP4 = 0;
        GP5 = 0;
        _delay(250000); // 0.5 second delay
        
        GP0 = 0;
        GP1 = 0;
        GP2 = 0;
        GP3 = 0;
        GP4 = 0;
        GP5 = 0;
        _delay(250000); // 0.5 second delay
    }
}

 
I appreciate any help!  I have been working with PIC18 devices for a long time and while I am still crummy at programming C, I have some base code for doing simple functions.  I really only needed an 8 pin device, so I decided to use the PIC12F675 and so far, everything seems different.

Jason Rausch - Amateur Radio Callsign: KE4NYV
RPC Electronics, LLC
www.rpc-electronics.com
#1

20 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 18266
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: PIC12F675 GPIO2 No Function 2020/01/02 18:33:57 (permalink)
    +1 (1)
    1.  __delay_ms(500)  // 0.5 second delay
    2.  GP0 = 0;
         GP1 = 1;
         You could be having Read-Modify-Write Issues.  Try just doing the one pin (the LED)
     
    3. Why pick such an old PIC? it is over 10 years old
     
    #2
    ric
    Super Member
    • Total Posts : 25592
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC12F675 GPIO2 No Function 2020/01/02 18:44:43 (permalink)
    +1 (1)
    As Neil suggests, you're almost certainly getting RMW issue because this PIC does not have LAT registers.

    The easiest solution would be to use a more modern 8 pin device.


    Otherwise, try:

        while(1)
        {
            GP0 = 0;
            NOP();
            GP1 = 1;
            NOP();
            GP2 = 1;
            NOP();
            GP3 = 0;
            NOP();
            GP4 = 0;
            NOP();
            GP5 = 0;
            _delay(250000); // 0.5 second delay
            
            GP0 = 0;
            NOP();
            GP1 = 0;
            NOP();
            GP2 = 0;
            NOP();
            GP3 = 0;
            NOP();
            GP4 = 0;
            NOP();
            GP5 = 0;
            _delay(250000); // 0.5 second delay
        }

    or
        while(1)
        {
            GPIO = 0b00000110;
            _delay(250000); // 0.5 second delay
            GPIO = 0b00000000;
            _delay(250000); // 0.5 second delay
        }


    Also note. Nothing in this code requires stdio.h or stdlib.h
    Get out of the habit of always including them.

    Rather than "_delay(250000)", your code is self documenting if you use "__delay_ms(500)" instead.



    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #3
    KE4NYV
    Super Member
    • Total Posts : 186
    • Reward points : 0
    • Joined: 2005/10/30 13:48:23
    • Location: Greenbackville, VA, USA.
    • Status: offline
    Re: PIC12F675 GPIO2 No Function 2020/01/02 19:09:07 (permalink)
    0
    Thanks, it's working.  I removed the GPIO pins that I actually don't need and added the NOP(); instructions.  The _delay_ms(500); threw an error, so just to get it working I went back to my old delay.
     
    I am aware that the part is old.  What would you recommend replace it with?  Anything pin for pin compatible?
     

    #include <xc.h>
    // PIC12F675 configuration
    #pragma config FOSC = INTRCIO
    #pragma config WDTE = OFF
    #pragma config PWRTE = OFF
    #pragma config MCLRE = ON
    #pragma config BOREN = OFF
    #pragma config CP = OFF
    #pragma config CPD = OFF

    #define _XTAL_FREQ 4000000

    void main(void)
    {
    ANSEL = 0x00; //disable all analog pins and make digital I/O
    ADCON0 = 0x00; //disable internal ADC
    CMCON = 0x07; //disable comparator
    VRCON = 0x00; //disable voltage reference
    T1CONbits.TMR1CS = 0x0; //disable external clock on GP5

    TRISIO = 0b11000000; // set mode of all pins

    while(1)
    {
    GP1 = 1;
    NOP();
    GP2 = 0;
    NOP();
    _delay(250000); // 0.5 second delay

    GP1 = 0;
    NOP();
    GP2 = 1;
    NOP();
    _delay(250000); // 0.5 second delay
    }
    }


    Jason Rausch - Amateur Radio Callsign: KE4NYV
    RPC Electronics, LLC
    www.rpc-electronics.com
    #4
    ric
    Super Member
    • Total Posts : 25592
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC12F675 GPIO2 No Function 2020/01/02 19:29:32 (permalink)
    +2 (2)
    KE4NYV
    ... The _delay_ms(500); threw an error, so just to get it working I went back to my old delay.

    There's two underscores in the version I posted.
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #5
    NKurzman
    A Guy on the Net
    • Total Posts : 18266
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: PIC12F675 GPIO2 No Function 2020/01/02 19:33:15 (permalink)
    +1 (1)
    What is the Error?  500 maybe to large for a single instance.
    Microchip recommends PIC16F18313 if you look at PIC12F675 web page.
    But there are a few 8 pin options.
     
    You can use the Parametric search:
    https://www.microchip.com/ParamChartSearch/chart.aspx?branchID=1012
     
    Is it just me, or is everything useful on Microchip site hidden under layers of Marketing Garbage?
    #6
    ric
    Super Member
    • Total Posts : 25592
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC12F675 GPIO2 No Function 2020/01/03 01:41:10 (permalink)
    +1 (1)
    Setting all pins at once is still the safest way when you don't have a LATx register.
    Also note, you tried to set TRISIO5 to zero. It's always 1.
     
    #include <xc.h>

    // PIC12F675 configuration
    #pragma config FOSC = INTRCIO
    #pragma config WDTE = OFF
    #pragma config PWRTE = OFF
    #pragma config MCLRE = ON
    #pragma config BOREN = OFF
    #pragma config CP = OFF
    #pragma config CPD = OFF

    #define _XTAL_FREQ 4000000

    void main(void)
    {
        ANSEL = 0x00; //disable all analog pins and make digital I/O
        CMCON = 0x07; //disable comparator
        TRISIO = 0b11100000;    // set GPIO4-0 as outputs

        while(1)
        {
            GPIO = 0b00000010;    // GP2 low, GP1 high
            __delay_ms(500);    // 0.5 second delay
            GPIO = 0b00000100;    // GP2 high, GP1 low
            __delay_ms(500);    // 0.5 second delay
        }
    }




    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #7
    mkjitendra
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2019/12/15 23:42:19
    • Location: 0
    • Status: offline
    Re: PIC12F675 GPIO2 No Function 2020/01/03 01:58:08 (permalink)
    -1 (1)
    Hi KE4NYU,
                                According to datasheet 8 bit microcontroller PIC12F1612 does not have spi communication pins option. can spi communication be configured by software setting.
     
    #8
    1and0
    Access is Denied
    • Total Posts : 10346
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: PIC12F675 GPIO2 No Function 2020/01/03 04:59:49 (permalink)
    0
    ric
    Also note, you tried to set TRISIO5 to zero. It's always 1.

        TRISIO = 0b11100000;    // set GPIO4-0 as outputs


    I think you meant TRISIO3, and there are no TRISIO7 and TRISIO6. ;)
     
    #9
    ric
    Super Member
    • Total Posts : 25592
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC12F675 GPIO2 No Function 2020/01/03 05:10:24 (permalink)
    0
    Oops, yes, I should have been talking about TRISIO3, not 5.
    To set all usable outputs, it should be
    TRISIO = 0b11001000;
    but you'd get exactly the same effect with
    TRISIO = 0;
    as the top 2 bits are unimplemented, and TRISIO3 is read-only, locked at 1.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #10
    1and0
    Access is Denied
    • Total Posts : 10346
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: PIC12F675 GPIO2 No Function 2020/01/03 05:20:07 (permalink)
    0
    ric
    To set all usable outputs, it should be
    TRISIO = 0b11001000;
    but you'd get exactly the same effect with
    TRISIO = 0;
    as the top 2 bits are unimplemented, and TRISIO3 is read-only, locked at 1.

    Good idea! That would save one instruction. I'd write it as 6 bits:
     TRISIO = 0b001000;

    #11
    KE4NYV
    Super Member
    • Total Posts : 186
    • Reward points : 0
    • Joined: 2005/10/30 13:48:23
    • Location: Greenbackville, VA, USA.
    • Status: offline
    Re: PIC12F675 GPIO2 No Function 2020/01/03 06:21:34 (permalink)
    0
    ric
    There's two underscores in the version I posted.



    I had both in my code, not sure what was wrong.

    Jason Rausch - Amateur Radio Callsign: KE4NYV
    RPC Electronics, LLC
    www.rpc-electronics.com
    #12
    KE4NYV
    Super Member
    • Total Posts : 186
    • Reward points : 0
    • Joined: 2005/10/30 13:48:23
    • Location: Greenbackville, VA, USA.
    • Status: offline
    Re: PIC12F675 GPIO2 No Function 2020/01/03 06:26:53 (permalink)
    0
    NKurzman
    What is the Error?  500 maybe to large for a single instance.

     
    I'll have to go back and get that for you.  I'm at work presently.
     
    Microchip recommends PIC16F18313 if you look at PIC12F675 web page.
    But there are a few 8 pin options.
     
    You can use the Parametric search:
    https://www.microchip.com/ParamChartSearch/chart.aspx?branchID=1012

     
    Thanks, I'll check that part out.  It would be nice to get back to what I was used to seeing with the PIC18F parts I have been using for years.
     
    Is it just me, or is everything useful on Microchip site hidden under layers of Marketing Garbage?

     
    Absolutely.  I find myself going to Mouser 99% of the time for datasheets, just because I can get right to it with a simple search.
     
     

    Jason Rausch - Amateur Radio Callsign: KE4NYV
    RPC Electronics, LLC
    www.rpc-electronics.com
    #13
    1and0
    Access is Denied
    • Total Posts : 10346
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: PIC12F675 GPIO2 No Function 2020/01/03 07:30:31 (permalink)
    +2 (2)
    KE4NYV
    ... so just to get it working I went back to my old delay.

    #define _XTAL_FREQ 4000000

    _delay(250000); // 0.5 second delay
    _delay(250000); // 0.5 second delay


    Those won't give you 0.5 second delays. ;)
     
    #14
    KE4NYV
    Super Member
    • Total Posts : 186
    • Reward points : 0
    • Joined: 2005/10/30 13:48:23
    • Location: Greenbackville, VA, USA.
    • Status: offline
    Re: PIC12F675 GPIO2 No Function 2020/01/13 14:40:16 (permalink)
    0
    Thanks for the help, guys!
     
    Looks like I might migrate to the PIC16F18313

    Jason Rausch - Amateur Radio Callsign: KE4NYV
    RPC Electronics, LLC
    www.rpc-electronics.com
    #15
    ric
    Super Member
    • Total Posts : 25592
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC12F675 GPIO2 No Function 2020/01/13 14:45:23 (permalink)
    0
    1and0
    ric
    To set all usable outputs, it should be
    TRISIO = 0b11001000;
    but you'd get exactly the same effect with
    TRISIO = 0;
    as the top 2 bits are unimplemented, and TRISIO3 is read-only, locked at 1.

    Good idea! That would save one instruction. I'd write it as 6 bits:
     TRISIO = 0b001000;



    TRISIO = 0;
    would save yet another instruction.
    i.e. the PIC can clear a register with a single instruction.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #16
    piticbogdan
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2018/12/02 17:58:02
    • Location: 0
    • Status: offline
    Re: PIC12F675 GPIO2 No Function 2020/01/17 20:04:33 (permalink)
    0
    NKurzman
     
    3. Why pick such an old PIC? it is over 10 years old
     


    (1nA in sleep @2V ?)
    #17
    ric
    Super Member
    • Total Posts : 25592
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC12F675 GPIO2 No Function 2020/01/17 22:00:00 (permalink)
    0
    piticbogdan
    NKurzman
    3. Why pick such an old PIC? it is over 10 years old

    (1nA in sleep @2V ?)

    Where did you get 1 nano amp from? That is an unmeasurably small figure.
    The PIC12F675 is typically 9 micro amp running at 32kHz in LP oscillator mode at 2V (max 16 microamp)
    The PIC16F18313 is typically 8 microamp at 32kHz at 3V, would be even better at 2V, and in sleep mode can get down to 40nA at 1.8V.
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #18
    1and0
    Access is Denied
    • Total Posts : 10346
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: PIC12F675 GPIO2 No Function 2020/01/18 01:30:35 (permalink)
    0
    ric
     
    Where did you get 1 nano amp from?

    Page 3 and Parameter D020 on page 90 of the PIC datasheet http://ww1.microchip.com/downloads/en/DeviceDoc/41190G.pdf
    #19
    ric
    Super Member
    • Total Posts : 25592
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC12F675 GPIO2 No Function 2020/01/18 01:44:41 (permalink)
    +1 (1)
    ok, I'll pay that. I'd still challenge anyone to verify that outside a laboratory :)
    The '675 is 1.2nA at 3V, and the 18313 is 30nA at the same voltage.
    They don't publish the 18313 current at 2V, even though it's rated to operate right down to 1.8V.
     
    If you feel that the the difference between 30nA and 1nA is  relevant in your application, then go for the older simpler chip...
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2020 APG vNext Commercial Version 4.5