Problem with PORTA on pic 18f4550!

Thread Starter

empnik

Joined Oct 8, 2008
2
Please help! Part of code(written in C) in MPLAB is:
TRISA=0xf0;
ADCON1=0x0f;
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
133
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
    MOVWF ADCON1;movw the value to ADCON1
    BCF STATUS,RP0;return to bank0
    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 :D :D

 

Tahmid

Joined Jul 2, 2008
343
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
133
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
 

Thread Starter

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.
 
Top