PORTC input pin problem: could peripherals get in the way?

Status
Not open for further replies.

Vizier87

Active Member
Hi guys,

I've been trying to program an input pin for a relatively new PIC for me: PIC16F1455. Normally in my case IF a direct TRIS register assignment did not work for an I/O, I'd go around the peripherals and disable them all and it has pretty much worked for me all this while.

But not with this new fella.

The datasheet has given associated functions such as follows:


What I'm trying to do is to just set RC4 as an input. Here's the code (MikroC):

C:
void main() {
  

     /////////////////////////////////////////////////////////
     // Configuration for this to work: Do not overwrite!  ///
     /////////////////////////////////////////////////////////
     OSCCON = 0b00111110;
     OSCTUNE = 3;

     trisa = 0;
     porta = 0;

     UCON=0;
     LATA=0;
     ANSELA=0;
     TRISA=0;   

     LATC=0;
     ANSELC=0;
  
     trisc0_bit = 0;
     trisc1_bit = 0;
     trisc2_bit = 0;
     trisc3_bit = 0;
     trisc4_bit = 1;
     trisc5_bit = 0;
  
     /////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////


     while(1){


         if (trisc4_bit == 1){
            Indicator = 1;
         }

         else Indicator = 0;

     }


}

I've tried disabling many others like
CM1CON0, CM1CON1, CM2CON0, CM2CON1 and all associated registers/bits but it didn't work.

The current code always turn the indicator LED high, although a direct check on the RC4 pin registers close to 0V.

Anything else I might be missing here?

By the way, an output pin works just ok. I can toggle all the PORTC pins pretty well.

Thanks,
Vizier87
 
If my very limited understanding of your "C" program is correct (I use assembler.) You are testing TRISC bit 4 which you have set to a 1 . I would have thought that you should be testing the state of PORTC bit 4. Also I can't see how the word indicator is assigned to a port and bit within that port.

Les.
 
Last edited:
Shucks that was embarrassing. Sorry.

Ok now I'm going go to the details which is why I'm testing the input pin - was for a Manchester comms which didn't work.

Thanks. I worked on this for like two days and failed to detect that.
 
I can only offer Assembly, but it might allow you to have some insight.




Code:
; PIC16F1455 Configuration Bit Settings


#include "p16f1455.inc"


 __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_ON & _BOREN_ON & _CLKOUTEN_OFF & _IESO_ON & _FCMEN_ON

 __CONFIG _CONFIG2, _WRT_OFF & _CPUDIV_NOCLKDIV & _USBLSCLK_48MHz & _PLLMULT_4x & _PLLEN_ENABLED & _STVREN_ON & _BORV_LO & _LPBOR_OFF & _LVP_ON

 

 

    BANKSEL OSCCON

    movlw   b'10111000'

    ;         X.......    Software PLL Enable bit

    ;          .X......  Software PLL Multiplier Select bit ; 0 = 3x ; 1 = 4x

    ;         ..XXXX..  Internal Oscillator Frequency Select bits (See Datasheet)

    ;         ......XX  System Clock Select bits (See Datasheet)

    movwf   OSCCON

 

    BANKSEL    ANSELC

    CLRF    ANSELC        ;digital I/O

    BANKSEL    TRISC

    MOVLW    B'111111'

    MOVWF    TRISC
 


Thanks Sir. I've got the problem sorted out. Seems to be just a simple configuration issue.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…