Problem with PORTA on pic 18f4550!

Discussion in 'Embedded Systems and Microcontrollers' started by empnik, Oct 3, 2009.

  1. empnik

    Thread Starter New Member

    Oct 8, 2008
    2
    0
    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.
     
  2. walid el masry

    Active Member

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

    Code ( (Unknown Language)):
    1.  
    2.     CLRF PORTA;clear any value stored in PORTA register
    3.     BSF STATUS,RP0;goto bank1 in ram
    4.     MOVLW 0X06;make all pins of PORTA are digital i/o in your case put 0xff
    5.     MOVWF ADCON1;movw the value to ADCON1
    6.     BCF STATUS,RP0;return to bank0
    7.     MOVLW 0X00;put zeros in work register
    8.     TRIS PORTA;make PORTA pins digital i/o or select your suitable case
    9.  
    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

     
  3. Tahmid

    Active Member

    Jul 2, 2008
    344
    25
    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.
     
  4. walid el masry

    Active Member

    Mar 31, 2009
    132
    0
    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
     
  5. empnik

    Thread Starter New Member

    Oct 8, 2008
    2
    0
    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.
     
  6. Tahmid

    Active Member

    Jul 2, 2008
    344
    25
    Thank you empnik.
     
Loading...