Thursday, May 21, 2020

Using Reset pin of PIC16F887 as a digital input pin

The master clear reset ($MCLR) pin of PIC16F887 could be disabled. With the advantage of ignoring this external reset, we can use this pin (RE3) as a digital input only.

We can disable the $MCLR reset circuitry by clearing the MCRLE in the CONFIG1 configuration register. When it's cleared, the $MCLR pin is internally connected to VDD.

The 16-bit configuration word register 1 listed below:

BIT 15





 BIT 8
 N/AN/A$DEBUGLVPFCMENIESOBOREN1BOREN0

BIT 7





 BIT 0
 $CPD$CPMCLRE$PWRTEWDTEFOSC2FOSC1FOSC0

In the XC8, we just use the "#pragma" directive to set the configuration like this:
#pragma config MCLRE = OFF

In this example, I use the RE3 pin as a digital input to count the external pulse. PortA used as a digital output port displaying the counting result on a single SSD. The OSC1 and OSC2 pin of PortA used as a digital output as a result of clocking the CPU from the internal RC oscillator with no clock out option.

Using Reset pin of PIC16F887 as a digital input pin
Schematic diagram.
MCLR pin is internally pulled high.
RE3 is a digital input pin counting the button pressed.
PORTA output the counting result to a single SSD.

The XC8 source code:

#include<xc.h>
// PIC16F887 Configuration Bit Settings
// CONFIG1
#pragma config FOSC = INTRC_NOCLKOUT
#pragma config WDTE = OFF
#pragma config PWRTE = OFF
#pragma config MCLRE = OFF
#pragma config CP = OFF
#pragma config CPD = OFF
#pragma config BOREN = ON
#pragma config IESO = ON
#pragma config FCMEN = ON
#pragma config LVP = ON
// CONFIG2
#pragma config BOR4V = BOR40V
#pragma config WRT = OFF
#define _XTAL_FREQ 4000000
#define btnCount RE3
void main(void){
    unsigned char ssd[16]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,
        0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
    char countButton=0;
    /*Select 4 MHz internal Oscillator*/
    SCS=1;
    OSCCONbits.IRCF=0x06;
    /*clear PortA*/
    PORTA=0x00;
    /*set PortA to output*/
    TRISA=0x00;
    /*clear analog inputs*/
    ANSEL=0x00;
    while(1){
        if(btnCount==0){
            __delay_ms(250);
            countButton+=1;
        }
        if(countButton>15)
            countButton=0;
        PORTA=ssd[countButton];
    }
}
A screen shot the program simulation:

Using Reset pin of PIC16F887 as a digital input pin
A simulation screen shot.
The counting result fed from RE3 reaches 6.

No comments:

Post a Comment

Search This Blog

Labels

25AA010A (1) 8051 (7) 93AA46B (1) ADC (30) Analog Comparator (1) Arduino (15) ARM (6) AT89C52 (7) ATMega32 (56) AVR (57) CCS PICC (28) DAC (1) DHT11 (2) Display (105) Distance Sensor (3) DS18B20 (3) dsPIC (2) dsPIC30F1010 (2) EEPROM (5) Environment Sensor (4) esp8266 (1) I2C (29) Input/Output (67) Interrupt (19) Keil (5) Keypad (10) LCD (47) Master/Slave (1) MAX7221 (1) MCP23017 (5) MCP23S17 (4) Meter (3) MikroC (2) Motor (15) MPLABX (71) Nokia 5110 LCD (3) OLED (2) One-Wire (6) Oscillator (8) PCB (6) PCD8544 (3) PCF8574 (5) PIC (107) PIC12F (2) PIC16F628A (2) PIC16F630 (1) PIC16F716 (3) PIC16F818 (10) PIC16F818/819 (2) PIC16F84A (15) PIC16F876A (1) PIC16F877A (9) PIC16F88 (1) PIC16F887 (60) PIC18 (19) PIC18F1220 (4) PIC18F2550 (3) PIC18F4550 (12) PWM (11) RTC (8) Sensor (10) SH1106 (1) Shift Register (11) Shift Registers (3) SPI (24) STM32 (6) STM32 Blue Pill (6) STM32CubeIDE (6) STM32F103C8T6 (6) SysTick (3) temperature sensor (11) Thermometer (21) Timer/Counter (31) TM1637 (2) UART (7) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (94)