I've just started to work with PIC16F887 and I have some problems. For programming I use (Genius) G540 programmer with the following configuration: FOSC0=0 ; FOSC1=1 ; FOSC2=0 ; WDTEN=1 ; PWRTE=0 ; MCLRE=0 ; CP=0 ; CP0=0 ; BODEN0=1 ; BODEN1=1 ; IESO=1 ; PCMEN=1 ; LVP=1 ; DEBUG=0 ; BOR4V=1 ; WRT0=0 ; WRT1=0.
The problem is that when I program the microcontroler the circuit will not respond properly; let's say I write the following sequence:
void main(){
ANSEL=0;
ANSELH=0;
PORTB=0b11111111;
TRISB=0;
}
For oscilator I use a 8Mhz Cristal with 22pF capacitors.
After programming the output of PORTB is something like: 00101111 and could change after another programming with the same program. Also I have to mention that the first time when I program the PIC all the FOSC0.....MCLRE....WRT1 pins where 1.
Your prob may be LVP being on causing the MCU to slip into prg mode. I think u have to hold RB3 low to prevent that. Anyway try this config, and forget the external oscillator crystal & caps:
No it is not. Only certain PICs (like the 16F628A) required this in the init routine. The F887 is not one of them. The comparator is off by default on this chip. Check your data sheet.
The DEBUG bit in the config word is not a bit that the code writer should ever play with. It is off by default...leave it out of the config word. MPLAB controls that bit setting depending on whether it is in debug or program mode. It explicitly states this in the Debug Express section of the PICkit 2 manual.
I have never seen a compiler that messes with the comparator bits for no reason. However, it is a requirement to set/clear the required bits in ANSEL and ANSELH to set up the port pins for either analog or digital I/O modes in the init routine.
Like I said on the first post I use for programming Genuis G540 ("a piece of sh..t") and what I've noticed is that I give the program one configuration let's say:FOSC0=0 ; FOSC1=1 ; FOSC2=0 ; WDTEN=1 ; PWRTE=0 ; MCLRE=0 ; CP=0 ; CP0=0 ; BODEN0=1 ; BODEN1=1 ; IESO=1 ; PCMEN=1 ; LVP=0 ; DEBUG=0 ; BOR4V=1 ; WRT0=0 ; WRT1=0 and after programming when I read the microcontroller it gives me all 1 (FOSC0=1 ; FOSC1=1 ; FOSC2=1 ; WDTEN=1 ; PWRTE=1 ; MCLRE=1 ; CP=1 ; CP0=1 ; BODEN1=1 ; BODEN1=1 ; IES0=1 ; PCMEN=1 ; LVP=1 ; DEBUG=1 ; BOR4V=1 ; WRT0=1 ; WRT1=1).
Another question?
How many times I can program this bits (FOSC0,FOSC1...etc) ???