Here, I'd like to document some configurations of the PIC16F887 for simple projects that don't relate to A/D conversion: (I'm no expert but the settings here are working for me)
- ANSEL = 0x00; // Make Digital I/O for PORTA (default is analog I/O), this is a must for input buttons, keys or whatever digital input/output
- ANSELH = 0x00; // Make Digital I/O for PORTB, this is a must otherwise the behavior of the ports will be unexpectable
- OSCCON = 0x75; // 8MHz Internal Oscillator , consumes more power
Or
- OSCCON = 0x65; // 4MHz Internal Oscillator , consumes less power
- ANSELH = 0x00; // Make Digital I/O for PORTB, this is a must otherwise the behavior of the ports will be unexpectable
- OSCCON = 0x75; // 8MHz Internal Oscillator , consumes more power
Or
- OSCCON = 0x65; // 4MHz Internal Oscillator , consumes less power
Timer1 Module Settings
- T1CON = 0x8F; // TMR1 Prescaler 1:1 external clock
- INTCON = 0xC0; // Set GIE, PEIE
- TMR1H = 0x80;
- TMR1L = 0x00;
- Delay_ms(10); // Delay for setting up TMR1
- PIE1.TMR1IE = 1; // enable interupt
- INTCON = 0xC0; // Set GIE, PEIE
- TMR1H = 0x80;
- TMR1L = 0x00;
- Delay_ms(10); // Delay for setting up TMR1
- PIE1.TMR1IE = 1; // enable interupt
Note: Microcontroller Devices are very sensitive to noise. Ground Plane and Noise Decoupling capacitor at power source may be needed.