# Problem with PORTA on pic 18f4550!

#### empnik

Joined Oct 8, 2008
2
TRISA=0xf0;
but when I try to simulate it and to give PORTA some values it does not respond. I tried with LATA but its the same. I check WATCH all the time: TRISA and ADCON1
are OK but PORTA still does not respond. Does anyone has some idea? Is it the problem with configuration bits or is there some other register which is connected with PORTA. I want only 4 lower bits to be the output.

#### walid el masry

Joined Mar 31, 2009
132
that is what i used for PIC16f876 in assemply

Rich (BB code):
    CLRF PORTA;clear any value stored in PORTA register
BSF STATUS,RP0;goto bank1 in ram
MOVLW 0X06;make all pins of PORTA are digital i/o in your case put 0xff
MOVLW 0X00;put zeros in work register
TRIS PORTA;make PORTA pins digital i/o or select your suitable case
in my opinion in your code you didn't goto bank1 to access ADCON1
try to do it and then tell me cause i can't do it too in c

#### Tahmid

Joined Jul 2, 2008
344
Hi empnik,
Though you have made all the PortA Pins Digital I/O by using ADCON1=0x0f,some of the PortA Pins are multiplexed for use in Comparator Module. So, if you keep the Comparator off by using CMCON=0x07, I think your program will work. So, test by adding that.

HI WALID EL MASRY,
Program with Pic 16F and Pic 18F are having distinct difference. It is the beauty of PIC18Fthat no bank changing is required when using SFR and upto a certain limit of General Purpose Registers, as they are in Default Access Bank. If you go through the Datasheet, it will be clear to you all.
With Thanks and regards.

#### walid el masry

Joined Mar 31, 2009
132
i saw the datasheet 1st time and i found the banks of the chip but never see what you r talking about but really it is cool it makes the code smaller and much easier since you may forget to switch between banks when writing the code

thnx 4 info

#### empnik

Joined Oct 8, 2008
2
Thanks Tahmid!!! I love you. It was CMCON i didn't set. In datasheet there is no mention of it in theme PORTA and LATA.

#### Tahmid

Joined Jul 2, 2008
344
Thank you empnik.