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.

Cannot set PortB of PIC18LF1220 to 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
I am using PIC18LF1220. The output functions (on PortA) work fine, however, the input functions on PortB are not working. I have checked hardware connections to Pin and they are fine. I think I am missing something in the code. My code is as below.
Code:
#include <hitech.h>
 #include <stdio.h>
 #include <pic18.h>
 #include "delay.c"
#define _XTAL_FREQ 20000000  //20Mhz
  
 void main (void)
 {
    ADCON0 = 0x00;
     ADCON1 = 0x0F; // Configure all ports with analog function as digital      INTCON=0;
    TRISA=0;
     TRISB=255;
    PORTA=0;
 
    while (1)
     {
        if (RB1==0) 
           RA1=1;
       else
          RA1=0;
 }

Can anyone point what is wrong? Have I missed setting some register? thanks for your help
 

Code:
TRISB = 0b11111111;//makes Bport input
TRISA = 0b00000000;//makes A port output

- - - Updated - - -

why you are using 20 mhz clock in this program? try with 4 Mhz,set oscon reg ..
Code:
 OSCCON= 0b01101111;
 

Code:
TRISB = 0b11111111;//makes Bport input
TRISA = 0b00000000;//makes A port output

- - - Updated - - -

why you are using 20 mhz clock in this program? try with 4 Mhz,set oscon reg ..
Code:
 OSCCON= 0b01101111;
Thanks. It works now.

why would TRISB =255; not work and TRISB = 0b11111111; work?
 

Code:
TRISB = 0b11111111;
..this means 0b-from this compiler can easily understand you are giving some binary data.Always try to do in this forms!!
 

set the PWMcon0 register to zero
or any other register related to portb
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top