PIC18F4550 pin Input/Output code

Discussion in 'Embedded Systems and Microcontrollers' started by Vindhyachal Takniki, Apr 29, 2016.

  1. Vindhyachal Takniki

    Thread Starter Member

    Nov 3, 2014
    349
    6
    I am using PIC18F4550 with MPBALX IDE V2.26, Xc8 V1.32.
    Below are codes for making pin as output & input. Are these codes ok.
    I have tried on proteus & it is working. But after few seconds, it throw warning that not in real time due to excessive cpu load.

    1. Output

    /* output low w& make it output */
    LATBbits.LATB0 = 0U;
    TRISBbits.TRISB0 = 0U;

    /* make low & the high */
    LATBbits.LATB0 = 0U;
    LATBbits.LATB0 = 0U;

    /* keep on inverting */
    while(1)
    {
    LATBbits.LATB0 = !LATBbits.LATB0;
    }


    2. Input

    /* output low w& make it output */
    LATBbits.LATB0 = 0U;
    TRISBbits.TRISB0 = 0U;

    /* make it input */
    TRISBbits.TRISB1 = 1U;

    /* keep on reading */
    while(1)
    {
    LATBbits.LATB0 = PORTBbits.RB1;
    }
     
Loading...