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.

PIC18F1220 RB2 not becoming input

Status
Not open for further replies.

Tiwana6330

Member level 1
Joined
Feb 3, 2011
Messages
36
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,536
Hi. I have run into a strange problem. I am using PIC18LF1220. The microcontroller is working fine except pin RB2. I have configured RB2 as input but it always reads 0 volts. To eliminate possibility of (hardare) PCB problem, I bent the RB2 pin so now its not touching the PCB. Then I am applying 3.3 volt directly from power supply to the pin. However, the pin is not registering that as high. I have also tried changing the chip. Code is below

Code:
#include <hitech.h>
 #include <pic18.h>
  
 void main (void)
 {
    ADCON0 = 0x00;    
 ADCON1 = 0x7F; // 7F Configure all ports with analog function as digital
 INTCON=0;
 
 TRISB = 0b11111111; //makes Bport input
 TRISA = 0b00000000; //makes A port output
 
 PORTA=0;
  
 while (1)
 {
 if (RB2==1)
 RA0=1;
 else 
 RA0=0;
 }
 }

note that other pin on PortB (RB0) is working fine as input

Can anyone please help. I think I am missing something in config bits
 

Read the datasheet again, you'll find why it doesn't works on pin RB2.

RB0 can be configured as analog pin.
But RB2 cannot be . Thats why it doesn't works.

Best wishes :)
 

Read the datasheet again, you'll find why it doesn't works on pin RB2.

RB0 can be configured as analog pin.
But RB2 cannot be . Thats why it doesn't works.

Best wishes :)

I am trying to set RB2 as digital I/O not as analog. Any other ideas why it would not work?
 

What version of the HiTech PICC18 Compiler are you using?

The more recent versions only require the inclusion of the following header file:

Code:
#include <htc.h>

Not:

Code:
#include <hitech.h>
#include <pic18.h>

Reference: PIC18F1220/1320 Datasheet, Section: 10.2 PORTB, TRISB and LATB Registers, Page: 90
Pins RB0-RB2 are multiplexed with INT0-INT2; pins
RB0, RB1 and RB4 are multiplexed with A/D inputs;
pins RB1 and RB4 are multiplexed with EUSART; and
pins RB2, RB3, RB6 and RB7 are multiplexed with
ECCP.

Although, according to the datasheet the CCP1CON should be cleared on POR, you might try manually clearing it which should disable the ECCP module.

Also, as there is no indication of the Configuration Register state, you need to ensure the watchdog timer has been disabled.

Otherwise, the device will continually Reset which would prevent the RA0 from being set high for any significant duration.

BigDog
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top