---
+ Post New Thread
Results 1 to 9 of 9
  1. #1
    Full Member level 5
    Points: 3,123, Level: 13
    MahmoudHassan's Avatar
    Join Date
    Oct 2010
    Posts
    252
    Helped
    36 / 36
    Points
    3,123
    Level
    13
    Blog Entries
    8

    Configuring port A as digital input for pic16f877a in MikroC

    Hello
    i wanted to configure port A to be digital but i have problem with that simply it
    doesnot worked

    iam using MikroC
    PIC16F877a
    attached protues file for the problem
    i tried to configure it like that

    first iteration
    ADCON1 = 0x0F; // All AtoD pins on PORTA to digital
    CMCON = 0x07; // Disable Comparators
    ADCON1 = 0x0F; // Make PORTA all inputs for switches


    Second iteration

    ADCON1 = 1; // Set inputs as analog, Ref=+5V
    TRISA = 0x00; // Set PORT A as inputs

    Third iteration

    PORTA = 0;
    ADCON1 = 0x06;
    TRISA = 0xCF;


    Fourth Iteration

    ADCON1=6;
    TRISA=1;



    so anybody recommend me other iterations

    Thanks

    (iam newbie)

    any help appreciated

    •   Alt11th March 2011, 03:39

      advertising

        
       

  2. #2
    Advanced Member level 3
    Points: 5,488, Level: 17
    Achievements:
    7 years registered

    Join Date
    Jun 2007
    Posts
    819
    Helped
    209 / 209
    Points
    5,488
    Level
    17

    Re: Configuring port A as digital input for pic16f877a in MikroC

    you can just call the function in mikroC? haha



  3. #3
    Full Member level 5
    Points: 5,121, Level: 16

    Join Date
    Mar 2006
    Posts
    309
    Helped
    43 / 43
    Points
    5,121
    Level
    16

    Re: Configuring port A as digital input for pic16f877a in MikroC

    hi
    in mikroC too you have to configure the ports as inputs and outputs.there's no function in microC which automatically make ports. if you want to make inputs, write 1 to the pins which is to be used as an inputs
    disable ADC and Comparators.it's clearly mentioned in microchip data sheet. i think the system is not working because you did not configure the controller parameters like MCLR in proteus and the compiler.

    ml


    1 members found this post helpful.

  4. #4
    Full Member level 5
    Points: 3,123, Level: 13
    MahmoudHassan's Avatar
    Join Date
    Oct 2010
    Posts
    252
    Helped
    36 / 36
    Points
    3,123
    Level
    13
    Blog Entries
    8

    Re: Configuring port A as digital input for pic16f877a in MikroC

    I don't know what is MCLR ?
    any information about it ?



    •   Alt11th March 2011, 15:23

      advertising

        
       

  5. #5
    Full Member level 5
    Points: 3,123, Level: 13
    MahmoudHassan's Avatar
    Join Date
    Oct 2010
    Posts
    252
    Helped
    36 / 36
    Points
    3,123
    Level
    13
    Blog Entries
    8

    Re: Configuring port A as digital input for pic16f877a in MikroC

    Thanks a lot finally it works (i don't know how but it did ! )

    But what about MCLR usage ? what is it ?



  6. #6
    Newbie level 1
    Points: 249, Level: 2

    Join Date
    Aug 2011
    Posts
    1
    Helped
    0 / 0
    Points
    249
    Level
    2

    Re: Configuring port A as digital input for pic16f877a in MikroC

    MahmoudHassan
    can you tell me how did it work plz



  7. #7
    Full Member level 5
    Points: 3,123, Level: 13
    MahmoudHassan's Avatar
    Join Date
    Oct 2010
    Posts
    252
    Helped
    36 / 36
    Points
    3,123
    Level
    13
    Blog Entries
    8

    Re: Configuring port A as digital input for pic16f877a in MikroC

    ADCON1=0b00000110;
    TRISA=255;// configure port A as input
    but take care it is for pic16f877a in MikroC



  8. #8
    Administrator
    Points: 57,939, Level: 58
    Awards:
    3rd Helpful Member
    bigdogguru's Avatar
    Join Date
    Mar 2010
    Location
    Southwest, USA
    Posts
    8,143
    Helped
    2140 / 2140
    Points
    57,939
    Level
    58
    Blog Entries
    3

    Re: Configuring port A as digital input for pic16f877a in MikroC

    Quote Originally Posted by MahmoudHassan View Post
    Thanks a lot finally it works (i don't know how but it did ! )

    But what about MCLR usage ? what is it ?
    The MCLR has two functions:

    1. a MCU reset pin (Master Clear)

    2. Vpp a high voltage (9-13v) for programming the device's Flash and EEPROM

    Many of the PICs allow the MCLR feature to be disable so that the pin can act as a normal I/O pin.

    MCLR Pin function with ICD3

    In-circuit Serial Programming (ICSP)

    Hope the info clears up the question concerning the MCLR.

    BigDog


    1 members found this post helpful.

  9. #9
    Newbie level 1
    Points: 133, Level: 1

    Join Date
    Mar 2012
    Posts
    1
    Helped
    0 / 0
    Points
    133
    Level
    1

    Re: Configuring port A as digital input for pic16f877a in MikroC

    in second iteration

    U write :
    ADCON1 = 1; // Set inputs as analog, Ref=+5V
    TRISA = 0x00; // Set PORT A as inputs

    if U want port A as input you must config it like that TRISA = 0xff;

    and this what happened with you when you write TRISA = 255; because ff == 255

    this my vision



+ Post New Thread
Please login