[SOLVED] PIC16F877 Input button not working properly

Status
Not open for further replies.

WStevens_sa

Member level 2
Joined
Jan 5, 2011
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
South Africa
Activity points
1,695
Hi all

My project is as follows. PICF877 programmed to be a RTC using TMR0 with prescaler for 1 second delay which displays day and time on a 2 x 16 LCD as "MON 00:00:00. RC0 sets hours which works and RC1 is supposed to set the minutes but does not work.

Where have I gone wrong. RC1 is not triggering "if (Button(&PORTC, 1, 1, 1)) "

 

Hi;

Modify this line
TRISC = 1; // Configure PORTC as inputs
// this configures only PORTC.0 as input

to
TRISC = 3; // Configure PORTC.0 and PORTC.1 as inputs
 
check this sample code may b it will help you.....it is for mikro c compiler u can check on the simulator......i hpe this willl be helpful to you..
Code:
bit oldstate;                                    // Old state flag

void main() {

  ANSEL  = 0;                                    // Configure AN pins as digital I/O
  ANSELH = 0;
  C1ON_bit = 0;                                  // Disable comparators
  C2ON_bit = 0;

  TRISB0_bit = 1;                                // set RB0 pin as input
  
  TRISC = 0x00;                                  // Configure PORTC as output
  PORTC = 0xAA;                                  // Initial PORTC value
  oldstate = 0;
  
  do {
    if (Button(&PORTB, 0, 1, 1)) {               // Detect logical one
      oldstate = 1;                              // Update flag
    }
    if (oldstate && Button(&PORTB, 0, 1, 0)) {   // Detect one-to-zero transition
      PORTC = ~PORTC;                            // Invert PORTC
      oldstate = 0;                              // Update flag
    }
  } while(1);                                    // Endless loop
}
 
Okay. I understand now. The port set for inputs works accordingly.

TRISC = 5 which is binary 101

RC0 = 1
RC1 = 0
RC2 = 1
RC3 = 0
RC4 = 0
RC5 = 0
RC6 = 0
RC7 = 0

So only RC0 and RC2 will allow inputs.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…