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.

Trouble programming the config mem on a pic16F628A

Status
Not open for further replies.

FlyingDutchMan

New Member
Hiya all,

I had a project a while ago which involved making a tacho/speedo/odo/running time for my motorbike. It has been running almost without a hitch (the cyrstal fell off once) for 8000km. At the time I used a microchip ICD2 to program it. Now the trouble begins when I now want to modify it a little. (so much for the "if it ain't broke don't fix it").

However since I'm not at uni anymore, I don't have access to free tools, so I went out and made myself a budget programmer via the serial port. I had intended on using PonyProg2000 for programming it. But it seems that its support for the 16F628 is somewhat lacking. I tried to get the source code off Source Forge, but without a module name for CVS it is somewhat similar to beating ones head against a brick wall.

So I spent a couple of hours today writing a programmer for it. I'm now at the stage where I can read and write the pics Flash and EEPROM, without any errors. My trouble is now with the configuration words. Despite my best efforts to write to them, I'm being thwarted.

This is what I'm currently doing to write to the configuration word:
Code:
  /* Firstly erase the device */
  /* Assert MCLR */
  setTXD(serialPort, TRUE);
  writeCommand(serialPort, LOAD_CONFIGURATION);
  writeData(serialPort, 0x3F62);
  writeCommand(serialPort, LOAD_DATA_FOR_PROGRAM_MEM);
  writeData(serialPort, 0x3FFF);
  writeCommand(serialPort, BULK_ERASE_PROGRAM_MEM);
  writeCommand(serialPort, BULK_ERASE_EEPROM_MEM);
  printf("\nDevice erased.\nProgramming.\n");
  /* Deassert MCLR */
  setTXD(serialPort, FALSE);
  wait(100000);

  /* Then program it */
  /* Assert MCLR */
  setTXD(serialPort, TRUE);

  /* Programming Flash/EEPROM goes here */

  /* Program config word - go into config space */
  writeCommand(serialPort, LOAD_CONFIGURATION);
  writeData(serialPort, 0x3F62);

  for(pc = 0x2000; pc<0x2008; pc++)
  {
    writeCommand(serialPort, READ_DATA_FROM_PROGRAM_MEM);
    checkSum = readData(serialPort);
    printf("\npc=0x%4X:0x%4X", pc, checkSum);

    if(pc==0x2007)
    {
      writeCommand(serialPort, LOAD_DATA_FOR_PROGRAM_MEM);
      writeData(serialPort, 0x3F62);
      writeCommand(serialPort, BEGIN_PROGRAMMING_CYCLE);
      writeCommand(serialPort, READ_DATA_FROM_PROGRAM_MEM);
      checkSum = readData(serialPort);
      printf("\npc=0x%4X:0x%4X", pc, checkSum);
    }

    writeCommand(serialPort, INCREMENT_ADDRESS);
  }

The output that code gives me is:
Code:
pc=0x2000:0x3FFF
pc=0x2001:0x3FFF
pc=0x2002:0x3FFF
pc=0x2003:0x3FFF
pc=0x2004:0x3FFF
pc=0x2005:0x3FFF
pc=0x2006:0x1068
pc=0x2007:0x  40
pc=0x2007:0x 340
pc=0x2006:0x1068 tells me that I'm at least in the right place - that is the device ID for the PIC16F628A. However the configuration word goes from 0x0040 to 0x0340 during my write to it. AFAIK, when you do a bulk erase, the config word should goto 0x3FFF, and goto whatever you want when you write to it. Am I missing something here?

EDIT: I have now managed to get the pic running. However it is by a somewhat round about method - Program the EEPROM and Flash with my program and then the config word with ponyprog (it does work a little bit!). I still don't know what I'm doing wrong though. It does seem that my program isn't touching the config word - ponyprog can read/write to it, and my program still reads 0x0040 or 0x0340.
 
Have a look at This Page. This is a pic programmer that supports both serial and parallel programmers and the source is available for download.

Mike.
 
Thanks for the link. With a little tweaking of the serial port interface, I got it working fine. I'm still hoping to get my own program fully working - winpic source code provides quite a bit of info, but it seems that my code to write the config word is essiantially the same. I've attached the source code for it for those of you who might be interested. I'm using the free Borland Compiler v5.5 (**broken link removed**). It should work with a COM84 programmer setup - except with the DTR logic inverted.
 

Attachments

  • picit.c
    12.6 KB · Views: 250
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top