Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F887 programming problem

Status
Not open for further replies.

alinpion

New Member
Hello!

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.

What do you think is the problem??
 
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:

__CONFIG _CONFIG1, _PWRTE_ON & _WDT_OFF & _INTOSC & _BOR_ON & _LVP_OFF & _CP_OFF & _MCLRE_ON & _IESO_OFF & _FCMEN_OFF
__CONFIG _CONFIG2, _WRT_OFF & _BOR40V
 
If this is Hitech C 9.82 or 9.83, the proper config word is -

Code:
__CONFIG(LVP_OFF & FCMEN_OFF & IESO_OFF & BOREN_OFF & MCLRE_OFF & PWRTE_ON & WDT_OFF & FOSC_INTRC_NOCLKOUT);

If this is an older version of Hitech C, the proper config word setting is something like -

Code:
__CONFIG(LVPDIS & FCMDIS & IESODIS & BORDIS & MCLRDIS & PWRTEN & WDTDIS & FOSC_INTRC_NOCLKOUT);

The 2nd config word need not be messed with unless you're using brown out reset or write protecting the program memory.
 
The COMPARATOR is on you need to turn it off the CM1CON0.7 = 0
 
The COMPARATOR is on you need to turn it off the CM1CON0.7 = 0

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.
 
Last edited:
Jon Thanks for the info i did read the datasheet and i do no that reset it is off. But i also no that some compilers set these bits by mistake.


If you have debug set in configure you can't use those pins in the datasheet
And low voltage programming is about it for configures

ADC off been cleared only leaves the comparator some how being set.
 
Last edited:
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.
 
Last edited:
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) ???
 

Attachments

  • G540_840 Manual.doc
    945.5 KB · Views: 353
  • PIC_CONFIG.doc
    2.8 MB · Views: 478
  • P1010011.JPG
    P1010011.JPG
    1.7 MB · Views: 273
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top