Logo Search packages:      
Sourcecode: odyssey version File versions

void Pic16f8xxDevice::bulk_erase ( void   )  [protected, virtual]

Bulk erase the program and data memory of a flash device.

Precondition:
The device has flash memory.

Code protection on the device is verified to be completely off.

The device is turned completely off.

Postcondition:
The device is turned completely off.
Exceptions:
runtime_error Contains a description of the error.

Reimplemented from Pic16Device.

Definition at line 36 of file Pic16f8xxDevice.cxx.

References PicDevice::COMMAND_BEGIN_PROG, PicDevice::COMMAND_INC_ADDRESS, PicDevice::COMMAND_LOAD_CONFIG, PicDevice::erase_time, PicDevice::flags, Device::io, PIC_FEATURE_EEPROM, PicDevice::pic_off(), PicDevice::set_program_mode(), IO::shift_bits_out(), IO::usleep(), PicDevice::write_command(), and Pic16Device::write_ee_data().

                                     {
      try {
            this->set_program_mode();

            /* This clears program memory and the config word. */
            this->write_command(COMMAND_LOAD_CONFIG);
            this->io->shift_bits_out(0x7ffe, 16, 1);
            this->io->usleep(1);
            for(int i=0; i<7; i++)
                  this->write_command(COMMAND_INC_ADDRESS);
            this->write_command(0x01);    /* Bulk Erase Setup1 */
            this->write_command(0x07);    /* Bulk Erase Setup2 */
            this->write_command(COMMAND_BEGIN_PROG);
            this->io->usleep(this->erase_time);
            this->write_command(0x01);
            this->write_command(0x07);

            if(this->flags & PIC_FEATURE_EEPROM) {
                  /* This clears the data EEPROM */
                  this->write_ee_data(0x3fff);
                  this->write_command(0x01);
                  this->write_command(0x07);
                  this->write_command(COMMAND_BEGIN_PROG);
                  this->io->usleep(this->erase_time);
                  this->write_command(0x01);
                  this->write_command(0x07);
            }

            this->pic_off();
      } catch(std::exception& e) {
            this->pic_off();
            throw;
      }
}


Generated by  Doxygen 1.6.0   Back to index