PDA

View Full Version : Program was working until I messed around with ICD



Skarr11
- 12th April 2010, 23:46
Greetings! Newbie here.

I am using a 16F876A with the ME Labs U2 programmer and MCS+ v 3.0.0.5. It's slow going but I'm learning. I managed to successfully load the bootloader, establish correct serial communication, and program the PIC using the bootloader several times with different programs. So it was working...

Today I wanted to learn a bit about the ICD function, using the same program I had been working with, and selected ICD compile and program. That didn't work (error message regarding missing debug files), so I wanted to go back to the original program and make sure it was working. It didn't, and I suspected maybe the bootloader code was overwritten, so I tried to reload it using the U2 programmer, put the PIC back into my circuit, then compile and program the PIC with the original program using the Microcode Loader as the programmer. Programming hangs on the "reset microcontroller" message despite me cycling power to the PIC.

Just to be sure, here are the steps I took to load the Bootloader code and then my program:

(1) Insert PIC into U2 programmer,
(2) Open meLabs programmer and select the pre-compiled 16F876A_04.hex file,
(3) In the View...Configuration menu, set to "Not Protected",
(4) Select Program,
(5) Remove PIC from programmer and insert into circuit,
(6) Launch MCS+, load program, select Compile and Program.
(7) When the "Reset Required" message appears, cycle power to PIC and wait, and wait, and wait. Then, nothing.

A couple of questions:

(1) How to verify that the bootloader code exists in the chip after programming? And is it an easy mistake to accidentally overwrite it? I don't recall doing anything special the first time I loaded the bootloader code, although I stumbled through it until it worked and don't recall exactly what I did.

(2) Did I somehow invoke some ICD mode by selecting ICD compile and program, and could that be preventing the original program from being loaded?

(3) What have I missed or messed up?

Below is the program I got to work and now can't:


Define LOADER_USED 1 'Only required if bootloader used to program PIC
define OSC 4

Init:
adcon1 = 6 ' Set all PortA to digital I/O
trisa = %00000001 ' set PortA RA4-RA1 to outputs, RA0 input
porta = %00000010 ' Set PortA RA1 high to turn on LED1

Main:
' *** Test the switch state ***
if portA.0 = 0 then led2 'If switch is pressed then jump to LED2 routine

PortA.1 = 1 ' Turn LED1 on
portA.2 = 0 ' Turn LED2 off
goto Main ' Jump to the top of the main loop

LED2:
'*** Turn LED2 on ***
porta.2 = 1 ' LED2 on
porta.1 = 0 ' LED1 off
goto Main ' Jump to the top of the main loop

Thanks in advance for any help you can offer!

HenrikOlsson
- 13th April 2010, 06:15
Hi,

Overwriting the bootloader when loading the chip WITH the bootloader should be pretty hard to do. As long as you DEFINE LOADER_USED 1 (which you have done) it should tell you if your program is growing too big and "into" the region of the bootloader.

Verifying that the bootloader IS in the chip is done with your programmer and its software. Usually the programmer/software automatically verifies after programming but it should be possible to "manually" issue a verify. Put the chip in, open the 16F876A_04.hex (or whatever) and run verify. (I'm not familiar with your particular programmer though...)

When you ICD Compile and program the compiled code is different from when you Compile and program. However, simply doing a normal Compile and program should work. The fact that the bootloader software doesn't see the PIC reset indicates something might be up with the serial connection to the PC. Check and recheck that everything is OK on that part (correct serial port selected, MAX232 etc wired correctly).

You could also try to load the .hex of YOUR program with the U2 programmer and see if it works then. If it does you KNOW that it's something with the bootloader and/or connection and NOT with the PIC itself.

/Henrik.

Skarr11
- 13th April 2010, 23:31
Thank you for your reply, Henrik.

I was able to successfully load my program using the U2 programmer and the circuit works correctly, so it's definitely not the programmer, as you suggested.

I didn't mess with the serial connection or change COM port or settings, but I'll check again just to rule it out. I did change the baud rate of the COM port in an attempt to get it working, so maybe that's not consistent; I'll check that too.

Were the steps I took to load the bootloader correct?

jellis00
- 14th April 2010, 00:05
(2) Did I somehow invoke some ICD mode by selecting ICD compile and program, and could that be preventing the original program from being loaded?


You may have performed an "ICD compile & program" without intending to. Go back and do a "Compile & program" and see if your code then works. Once you know your code will compile and is working and are ready to use the ICD, here are a couple of tricks I have learned recently in using the MCSP ICD:
1) Place a PAUSE 100 statement as the first executable statement in you code. When ICD runs without being in animation, the ICD will stop on this very first statement and you can then step thru your code from there one statement at a time while reviewing variables and memory values.
2) To isolate where your code may be hanging up with the ICD, bracket suspect sections of code with a DEBUG DISABLE and a DEBUG ENABLE at start and end of the suspect section or routine. This will cause the ICD to skip over these sections of code. Once your program runs with the ICD you will have isolated where in your code the hangup with ICD was occuring and can look for a code incompatibility in that section of code. This happened to me recently and with some help from David at Mecanique and Darrel Taylor I finally isolated the problem and got my code working with the MCSP ICD.

HTH.

Skarr11
- 17th April 2010, 00:33
I got it running again after I checked the serial connection with a simple program. Got the bootloader working again, and it all seems OK now. I have no idea why it wasn't working previously.

I think after I get a little more knowledge under my belt I'll delve into the ICD stuff, but until then I'll stick to LCDs and debug statements. I need to learn that more anyway.

Thanks for all your help!