Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] PIC18F4550 PORTB.B7 always returns 1

Status
Not open for further replies.

Alloy

Advanced Member level 4
Joined
Apr 3, 2016
Messages
116
Helped
0
Reputation
0
Reaction score
0
Trophy points
16
Activity points
1,003
Hey.
Why this code:
Code:
void main() {
   OSCCON =  0X70;       // Set internal oscillator at 8MHz
   ADCON1 = 0x0F;        // Configure AN pins as digital

 UART1_Init(9600);
 
 
 // enable weak pull-ups on port B
 INTCON2.RBPU = 1;
 
 TRISB.F7 = 1;    //Configure RB7 as input (PGD)
 while(1){
         if(PORTB .B7)
         {
                    UART1_Write_Text("0");
         }
         else
         {
                    UART1_Write_Text("1");
         }
         Delay_ms(500);
 }

}
always prints 1?
I have disconnected the programmer..
I have button on RB7...
and button does not work...
 

as per datasheet following programming of B port helps
CLRF PORTB ; Initialize PORTB by
; clearing output
; data latches
CLRF LATB ; Alternate method
; to clear output
; data latches
MOVLW 0Eh ; Set RB<4:0> as
MOVWF ADCON1 ; digital I/O pins
; (required if config bit
; PBADEN is set)
MOVLW 0CFh ; Value used to
; initialize data
; direction
MOVWF TRISB ; Set RB<3:0> as inputs
; RB<5:4> as outputs
; RB<7:6> as inputs
 

RBPU bit is low active, you'll write 0 to it to enable pull-ups. Code should work apart from this point.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top