problem programming pic microcontrollers

Thread Starter

gatoulisss

Joined Jan 23, 2015
69
hello,
i have a problem with programming my pic microcontrollers...
im writing a very simple code just to test them
the programm is about to blink a led. in the simulation the programm running just fine also on the compiler no problems at all the programmer says that the programming ends succesfully but on the circuit nothing works.
i have test the same program in 5 diferrent pic (3xpic16f84A, 1xpic16f88, 1xpic16f628A) microcontrollers and i have the same problem any help?

i upload some fotos of the situation.DSC097651.jpg p1.jpg p2.jpg
 

JohnInTX

Joined Jun 26, 2012
4,787
Do you have an oscillator hooked up to the PIC? It won't run without one. See Oscillator Configurations (6.2 in the F84A databook) for info. For stand-alone use (without the PICKit) you'll also need a reset network (RC at least) on MCLR.

On your circuit, you need to put the resistor in series with the LED as RA1 will source current when its set to a '1'.

What you have WILL work on RA4 however since its open-drain. A side benefit is the on power up, the LED will be ON (RA4 is hi impedence). When the code runs, it initializes the port to '0' shunting the LED. The flash of LED ON then OFF during power up is a nice way to know that the processor is running and at least got to initIO()

It would be helpful to post your code in CODE tags so that we can test it on our systems. For MikroC, also post what your project settings are (configuration fuzes etc), preferably in comments in the source code.
 
Last edited:

Thread Starter

gatoulisss

Joined Jan 23, 2015
69
yes i have the digital I/O enabled on pic16f88 but again nothing

here is the code


void main() {

trisa1_bit=0;
for(;; ){
porta.f1=1;
delay_ms(1000);
porta.f1=0;
delay_ms(1000);
}
}

about the fuses i have watchdog off and internal oscillator checked
 

JohnInTX

Joined Jun 26, 2012
4,787
You have to clear ANSEL in the code to make RA1 digital for the 16F88. Your previous post was for the 16F84A. These have different requirements to configure the IO.

In addition to the the WDT and INTOSC fuses, if you don't pull up MCLR externally, be sure to disable MCLR with the fuzes and enable the PowerUp Timer (16F88)


Something like this:
Code:
// This is for 16F88
void main() {
  ANSEL=0;  // all ports digital
  PORTA=0;  // all portA = out 0
  TRISA=0;
  PORTB=0; // all portB = out 0
  TRISB=0;

  for(;; ){
  PORTA.F1=1;
  Delay_ms(1000);
  PORTA.F1=0;
  Delay_ms(1000);
  }
}
BTW I changed the case of Delay_ms and PORTx. I run MikroC with case-sensitivity ON and highly recommend that you do so as well.
 
Last edited:

Thread Starter

gatoulisss

Joined Jan 23, 2015
69
You have to clear ANSEL in the code to make RA1 digital for the 16F88. Your previous post was for the 16F84A. These have different requirements to configure the IO.

In addition to the the WDT and INTOSC fuses, if you don't pull up MCLR externally, be sure to disable MCLR with the fuzes. (16F88)
the above code is for the pic16f84a
i need to find the main problem so i try to program the pic16f84a i just mention the other to so we are sure its not fault of microcontroller.
when i am trying to compile via mplab i have this error
PK3Err0033: 4 bytes expected, 0 bytes received

Failed to properly connect to PICkit 3
thanks
 

MaxHeadRoom

Joined Jul 18, 2013
28,702
MPLAB is fussy about the sequence for connection to Pickit3, go by the recommendation notes.
Do not connect pickit3 or power the circuit.
Compile the code, set Pickit3 as programmer, then connect Pick3, then power the circuit.
Any other way and it is hit and miss as to if you get the error or not.
Max.
 

JohnInTX

Joined Jun 26, 2012
4,787
the above code is for the pic16f84a
i need to find the main problem so i try to program the pic16f84a
The 16F84A does not have an internal oscillator so you'll have to provide one with a crystal, resonator, RC or external oscillator. Any references to INTOSC in your project setup are not for the 'F84A
 

Thread Starter

gatoulisss

Joined Jan 23, 2015
69
The 16F84A does not have an internal oscillator so you'll have to provide one with a crystal, resonator, RC or external oscillator. Any references to INTOSC in your project setup are not for the 'F84A
so lets try with the pic16f88
the only change in the code is that i use ansel=1; correct?
but i continue having the same problem
 

JohnInTX

Joined Jun 26, 2012
4,787
ANSEL=0 for all digital.
Try the code I posted with the additional config settings i.e. MCLR disabled, power up timer ON.

EDIT: You need to change the LED circuit as I indicated above. If you don't, the IO will not work properly for single bit changes. The schematic you posted is not what you have wired on the picture of the proto-board. You need PORT->resistor->LED->GND.
 
Last edited:

spinnaker

Joined Oct 29, 2009
7,830
Instead of asking all of these questions lets start wit the basics.

How do you know it is not running?

What have you done to debug the code?
Debug is your friend. It will show you if your code is not running or if it is running help you determine the problem

Do you have a scope, logic probe? Anything you can use to measure the i/o pin? Make sure it is not your led that is the issue.

Where are you configuration settings (fuses)? This will determine what OSC is used.

You should set Latches and read Ports.
 

Thread Starter

gatoulisss

Joined Jan 23, 2015
69
Instead of asking all of these questions lets start wit the basics.

How do you know it is not running?

What have you done to debug the code?
Debug is your friend. It will show you if your code is not running or if it is running help you determine the problem

Do you have a scope, logic probe? Anything you can use to measure the i/o pin? Make sure it is not your led that is the issue.

Where are you configuration settings (fuses)? This will determine what OSC is used.

You should set Latches and read Ports.
i use same code same bread board but different microcontroler, pc and compliler and it run just fine... the code is ok, something wrong with my computer or programmer(just bought it) or pics
 

JohnInTX

Joined Jun 26, 2012
4,787
i use same code same bread board but different microcontroler, pc and compliler and it run just fine...
So.... specifically, if the exact same circuit as wired works in some configuration, what exactly is that configuration?

Which PIC, which compiler/version and programmer work?

Which PIC and compiler and programmer don't work?

Are you saying that the same MicroC on a different computer is the problem or are you changing from XC8 to MicroC or something like that? Which programmer is working and which one isn't?

Are you sure that you are building for RELEASE and not debug. If you are compiling in MikroC and programming with PK3, it has to be for RELEASE. I assume you are loading the .HEX file from MikroC into the stand-alone programmer app for PK3?

The code I posted loads and simulates fine for a PIC16F88.
 

MagicMatt

Joined Sep 30, 2013
117
Just to go back to basics here... there's a verify button on the programming software. That will check that the chip has been programmed ok. If it verifies, the issue is not with the programming procedure or the programmer, but must be your actual circuit, or the program you have written, or both. Does it verify?
 

Thread Starter

gatoulisss

Joined Jan 23, 2015
69
Just to go back to basics here... there's a verify button on the programming software. That will check that the chip has been programmed ok. If it verifies, the issue is not with the programming procedure or the programmer, but must be your actual circuit, or the program you have written, or both. Does it verify?
yes it verifying it succesfully


So.... specifically, if the exact same circuit as wired works in some configuration, what exactly is that configuration?

Which PIC, which compiler/version and programmer work?

Which PIC and compiler and programmer don't work?

Are you saying that the same MicroC on a different computer is the problem or are you changing from XC8 to MicroC or something like that? Which programmer is working and which one isn't?

Are you sure that you are building for RELEASE and not debug. If you are compiling in MikroC and programming with PK3, it has to be for RELEASE. I assume you are loading the .HEX file from MikroC into the stand-alone programmer app for PK3?

The code I posted loads and simulates fine for a PIC16F88.
im studying engineer on electronics and i use my university equipment... also my teacher couldnt find something wrong on my circuit... he said it must be something in microcontrollers wrong but because i ve tested 5 different maybe i have to do somethink first so i can make them work...
 

tshuck

Joined Oct 18, 2012
3,534
yes it verifying it succesfully




im studying engineer on electronics and i use my university equipment... also my teacher couldnt find something wrong on my circuit... he said it must be something in microcontrollers wrong but because i ve tested 5 different maybe i have to do somethink first so i can make them work...
Please post your current data for this device.

Post your schematic, a photo of the current setup, and your current code (including configuration bits for the PIC). In other words, don't mention other chips than the one you intend to use.

The only reason your issue has persisted this long is because you have not been clear.

You've mentioned you want to use the 16F88, yet all your images show 16F84A.
 

Thread Starter

gatoulisss

Joined Jan 23, 2015
69
Please post your current data for this device.

Post your schematic, a photo of the current setup, and your current code (including configuration bits for the PIC). In other words, don't mention other chips than the one you intend to use.

The only reason your issue has persisted this long is because you have not been clear.

You've mentioned you want to use the 16F88, yet all your images show 16F84A.

im uploading step by step pictures of what im doing... Photo 29-1-15 - 11 05 52 μ.μ..jpg Photo 29-1-15 - 11 06 18 μ.μ..jpg Photo 29-1-15 - 11 06 25 μ.μ..jpg Photo 29-1-15 - 11 06 32 μ.μ..jpg Photo 29-1-15 - 11 07 40 μ.μ..jpg Photo 29-1-15 - 11 09 49 μ.μ..jpg Photo 29-1-15 - 11 11 14 μ.μ..jpg Photo 29-1-15 - 11 14 54 μ.μ..jpg Photo 29-1-15 - 11 05 52 μ.μ..jpg Photo 29-1-15 - 11 06 18 μ.μ..jpg Photo 29-1-15 - 11 06 25 μ.μ..jpg Photo 29-1-15 - 11 06 32 μ.μ..jpg Photo 29-1-15 - 11 07 40 μ.μ..jpg Photo 29-1-15 - 11 09 49 μ.μ..jpg Photo 29-1-15 - 11 11 14 μ.μ..jpg Photo 29-1-15 - 11 14 54 μ.μ..jpg Photo 29-1-15 - 11 18 16 μ.μ..jpg Photo 30-1-15 - 12 15 32 π.μ..jpg
 

JohnInTX

Joined Jun 26, 2012
4,787
Thanks for the comprehensive dumps.

A few things:

First, be sure the LED circuit is correct. In the latest photo of the breadboard, it looks like the resistor and LED leads are plugged into different rows - maybe the resistor lead is just bent... Check that then disconnect the blue wire from the PIC and connect it to +5V to make sure that the LED lights up.

I would adjust your configuration bits as follows In the Project ->Edit Project window:
Fail-Safe Clock monitor and Internal External Switchover are enabled. Disable them. CONFIG2 = 3FFCh

Oscillator Selection: INTRC oscillator; CLKO function on RA6.. That way you can probe RA6 to see if the oscillator is running. If you don't have a scope, a DVM should read about 40% of Vdd if its running, Vdd or GND if it isn't.

Power Up Timer: Enabled. This will give the oscillator time to start. Its recommended if you don't use a MCLR/ network.
Leave the other stuff disabled as it is. CONFIG1 = 3F19h

Note that with the internal oscillator, you have to set OSCCON in your code to set the osc frequency. The default frequency is 31KHz. Add OSCCON = 0x60; as the first line of your init code to set the system clock to 4MHz. See section 4.6 of the datasheet. Note that setting 4MHz in MikroC's project setup window does not set the PIC frequency, it only tells MikroC how to calculate delays.

You might consider better power to the PIC. Bring +5V and GND to the PIC via the busses on the proto board then connect Vdd/Vss with short wires. Decouple Vdd/Vss as close to the PIC as possible with a 1uF tantalum cap in parallel with a .1 ceramic. Usually, PICs will run OK with almost any hookup but since you are having problems, its not a bad idea.

Be sure to check the basics, power supply voltage, GND etc. Make sure Vpp can go high without fouling your 5V regulator (although if it consistantly programs and verifies, it's probably OK). Verify the oscillator is running.

I built your code and got essentially the same .HEX image except for some of the delay values. Don't know why that is.

I would also recommend you do NOT set up your ports like you have. Single-bit changes on the PORTs and especially on TRIS can be cause problems. The preferred way is shown in post #6. Doing things like trisab1_bit=0 frequently does NOT work as expected. Same for PORTs. Search AAC for read-modify-write and r-m-w for lots of info on this problem.

Finally - again- use CODE tags to post your code. I typed in yours from the photo but you are not making it easy.

See what that does..
Good Luck.
 

Thread Starter

gatoulisss

Joined Jan 23, 2015
69
Thanks for the comprehensive dumps.

A few things:

First, be sure the LED circuit is correct. In the latest photo of the breadboard, it looks like the resistor and LED leads are plugged into different rows - maybe the resistor lead is just bent... Check that then disconnect the blue wire from the PIC and connect it to +5V to make sure that the LED lights up.

I would adjust your configuration bits as follows In the Project ->Edit Project window:
Fail-Safe Clock monitor and Internal External Switchover are enabled. Disable them. CONFIG2 = 3FFCh

Oscillator Selection: INTRC oscillator; CLKO function on RA6.. That way you can probe RA6 to see if the oscillator is running. If you don't have a scope, a DVM should read about 40% of Vdd if its running, Vdd or GND if it isn't.

Power Up Timer: Enabled. This will give the oscillator time to start. Its recommended if you don't use a MCLR/ network.
Leave the other stuff disabled as it is. CONFIG1 = 3F19h

Note that with the internal oscillator, you have to set OSCCON in your code to set the osc frequency. The default frequency is 31KHz. Add OSCCON = 0x60; as the first line of your init code to set the system clock to 4MHz. See section 4.6 of the datasheet. Note that setting 4MHz in MikroC's project setup window does not set the PIC frequency, it only tells MikroC how to calculate delays.

You might consider better power to the PIC. Bring +5V and GND to the PIC via the busses on the proto board then connect Vdd/Vss with short wires. Decouple Vdd/Vss as close to the PIC as possible with a 1uF tantalum cap in parallel with a .1 ceramic. Usually, PICs will run OK with almost any hookup but since you are having problems, its not a bad idea.

Be sure to check the basics, power supply voltage, GND etc. Make sure Vpp can go high without fouling your 5V regulator (although if it consistantly programs and verifies, it's probably OK). Verify the oscillator is running.

I built your code and got essentially the same .HEX image except for some of the delay values. Don't know why that is.

I would also recommend you do NOT set up your ports like you have. Single-bit changes on the PORTs and especially on TRIS can be cause problems. The preferred way is shown in post #6. Doing things like trisab1_bit=0 frequently does NOT work as expected. Same for PORTs. Search AAC for read-modify-write and r-m-w for lots of info on this problem.

Finally - again- use CODE tags to post your code. I typed in yours from the photo but you are not making it easy.

See what that does..
Good Luck.

Problem solved!! it was OSCCON = 0x60; missing from the code...! i write it and i program again the pic and everything now works!! thank you a lot!!!
 
Top