Usefull PIC programming tips for PIC16f877A

This article totally depends on my experiences when I doing some microcontroller projects based on PIC16f877A. Further more following article describe the answers which I found for following questions.

Make RA4(4th bit of PORTA) as a digital output.

All the bits on all the ports in PIC16f877A microcontroller can be configure as digital input or output except RA4. All other bits on ports can be configure as a digital I/O by changing its TRIS register's values and configuring ADCON1 register(for analog input pins). But if we consider about RA4 pin, its behavior different than other I/O pins.
RA4 is an open collector I/O pin. Therefore when we want to use RA4 as a digital output, we have to pull up RA4 by a resistor. This approach can be understand by following example.
This is an example program to use RA4 as a digital output using Hi-Tech C.

#include <htc.h>
#define _XTAL_FREQ 4000000
void main(){
    TRISA = 0;//PORTA is output
   
    //configure ADCON1 to set PORTA as digital I/O
    PCFG0 = 0;
    PCFG1 = 1;
    PCFG2 = 1;
    PCFG3 = 0;
   
    ADON = 0;//ADC modulde is off
   
    while(1){
        RA4 = 1;//Now LED will off
        __delay_ms(100);
        __delay_ms(100);
        __delay_ms(100);
        RA4 = 0;//Now LED will on
        __delay_ms(100);
        __delay_ms(100);
        __delay_ms(100);
    }
}

Finally what we have to do is, supply a current to LED attached to RA4 and change the logic to on and off the LED.

Status on RA4 LED status
1 (High) Off
0 (Low) On

References and further readings-
The best source for understand the behavior of the PIC is "Data sheet".

This is a cropped part from PIC16f877A data sheet.



All the bits on PROTB can be used as digital input except RB3. Because by default the Low-Voltage ICSP Programming (LVP) is enabled in PIC16f877A which lead to disable RB3 I/O function. If you do not use LVP, you can disable LVP by following these steps in MPLAB IDE.

  1. Configure
  2. Configuration bit.
  3. Uncheck Configuration Bits set in code.
  4. Select disable on LVP field.
  5. Close and recompile the code.
Now you can use RB3's input function by changing TRISB's 3rd bit into 1.(TRISB3 = 1)

References and further readings-
The best source for understand the behavior of the PIC is "Data sheet".

  This is a cropped part from PIC16f877A data sheet.

3 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
    Replies
    1. Thank you for info, But please don't use my blog for any business purposes, If you need to send any information for me, Please send me an email to my personal mail which you can find on
      http://milindapro.blogspot.com/p/about-me.html

      Delete
  2. But please can u post the datasheet page number wehere u cropped…

    ReplyDelete