• AVR Freaks

Hot!read GP4 input on 12F617

Author
02GF74
Senior Member
  • Total Posts : 143
  • Reward points : 0
  • Joined: 2006/11/29 08:25:28
  • Location: 0
  • Status: offline
2020/05/27 04:07:44 (permalink)
0

read GP4 input on 12F617

Apologies if this is a repeat post (I'm having trouble with accounts).
I have 12F617 device with pin 3 (GP4) held high via 10k resistor.  My program should turn a LED on or off according to the input value; I connect pin3 to 0V.  Turning the LED on/off works but I suspect I am missing some configuration for the input.
Note that is the if/else are commented out, the LED is turned on/off very rapidly (viewed on an oscilloscope).
 
// CONFIG
#pragma config FOSC = INTOSCCLK // Oscillator Selection bits (INTOSC oscillator: CLKOUT function on RA4/AN3/T1G/OSC2/CLKOUT, I/O function on RA5/T1CKI/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON // MCLR Pin Function Select bit (MCLR pin is MCLR function and weak internal pull-up is enabled)
#pragma config CP = OFF // Code Protection bit (Program memory is not code protected)
#pragma config IOSCFS = 8MHZ // Internal Oscillator Frequency Select (8 MHz)
#pragma config BOREN = ON // Brown-out Reset Selection bits (BOR enabled)
#pragma config WRT = OFF // Flash Program Memory Self Write Enable bits (Write protection off)

#include <xc.h>

#define relayOut GPIObits.GP2
#define relayIn GPIObits.GP5
#define start GPIObits.GP4
#define speedo GPIObits.GP3

void main(void)
{
    // configure device
    init( );
    
    while(1)
    {
        if( start == 0 )
            relayOut = 1; // set high = on
        else
            relayOut = 0; // set low = off
        
    }
}


void init( void )
{
    ANSELbits.ANS3 = 0; // GP4 is digital I/O, not analogue
    
    // Note: TRISIO = TRISA; IO direction register
    TRISIObits.TRISIO5 = 1; // GP5 input ; relayIn
    TRISIObits.TRISIO4 = 1; // GP4 input ; start
    TRISIObits.TRISIO3 = 1; // GP3 input ; speedo
    TRISIObits.TRISIO2 = 0; // GP2 output ; relayOut
    
}


#1

4 Replies Related Threads

    ric
    Super Member
    • Total Posts : 28324
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: read GP4 input on 12F617 2020/05/27 04:23:11 (permalink)
    +1 (1)
    Change
    #pragma config FOSC = INTOSCCLK // Oscillator Selection bits (INTOSC oscillator: CLKOUT function on RA4/AN3/T1G/OSC2/CLKOUT, I/O function on RA5/T1CKI/OSC1/CLKIN)
    to
    #pragma config FOSC = INTOSCIO  // Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA4/AN3/T1G/OSC2/CLKOUT, I/O function on RA5/T1CKI/OSC1/CLKIN)

    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!
    #2
    ric
    Super Member
    • Total Posts : 28324
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: read GP4 input on 12F617 2020/05/27 04:44:36 (permalink)
    +1 (1)
    The comment on the FOSC setting should have given you a clue.
    You can't override config settings with TRIS/ANSEL settings.
     

    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
    02GF74
    Senior Member
    • Total Posts : 143
    • Reward points : 0
    • Joined: 2006/11/29 08:25:28
    • Location: 0
    • Status: offline
    Re: read GP4 input on 12F617 2020/05/28 00:38:30 (permalink)
    0
    excellent - thanks - but to be fair the source is copied from internet and the length of that comment is not visible in full in my MPLAB X window - but fixed :)
     
    I take it the only place those pragma and register definitions are in the include file?
    update: documentation is found in:
    C:/Program%20Files%20(x86)/Microchip/xc8/v2.10/docs/chips/12f617.html
    post edited by 02GF74 - 2020/05/28 01:11:13
    #4
    ric
    Super Member
    • Total Posts : 28324
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: read GP4 input on 12F617 2020/05/28 01:44:34 (permalink)

    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
    Jump to:
    © 2020 APG vNext Commercial Version 4.5