
APPLICATION NOTES FOR SPECIAL STARTUP REQUIREMENTS

Applies to 12C50X, 12C67X, 12CE67X, 16F87X and similar



SPECIAL STARTUP SEQUENCES
-------------------------

  ICD DEBUGGING: defined in 'startup.txt'

  ICD debugging requires a NOP instruction at address 0. The
  following statements are found in the header file when using ICD
  debugging:

    #define _NOP 0x0000
    #pragma cdata[0] = _NOP
    #pragma resetVector 1    // change to address 1

  Note that the full definitions for ICD debugging is found in the
  16F87X header files.



INSERTING SPECIAL INSTRUCTIONS OR DATA AT CERTAIN LOCATIONS:
------------------------------------------------------------

  The following #pragma will insert a code/data word at a certain
  location in the program memory:

    #pragma cdata[ADDRESS] = VALUE  // or EXPRESSION
    ADDRESS: 0 .. 0x7FFE
    VALUE: 0 .. 0x3FFF

  There is no check on validity of the inserted data or address. The
  data is added at the end of the assembly and hex file.

  It is even possible to overwrite assembled instructions. However,
  this is normally not recommended since it is not defined how the
  device programmer (or assembler) handles this conflict.



RESET VECTOR NOTES
------------------

 Removing the reset vector:

   #pragma resetVector -

 Setting the reset vector to address 2:

   #pragma resetVector 2




12C50X/12CE51X/16C505 WINDOWED DEVICES
--------------------------------------

  When using the internal oscillator on UV erasable (windowed)
  devices, the calibration value have to be reprogrammed
  after erasure. This is done by first adding the following to the
  application program:

    #ifdef CalValue
     #define ResetAddress  0x3FF   // 16C509(A)
     #define _MOVLW 0xC00
     #pragma cdata[ResetAddress]= _MOVLW + CalValue
    #endif
    ..
    void main( void)
    {
        OSCCAL = W;
        ..
    }

  First usage of device: read calibration value at address 0x3FF/0x1FF
  using your device programming equipment.

  After erasure of device:
   a) Add COMMAND LINE option, and replace NN
      with the actual value for the device:  -DCalValue=0xNN
   b) Alternatively use  #define CalValue 0xNN
      and replace NN with the actual value for the device. The value
      have to be changed for each device used.



12C67X/12CE67X: CALIBRATION OF THE INTERNAL OSCILLATOR
------------------------------------------------------

  The following instruction sequence will initialize the calibration
  register when using the internal oscillator:

   #if defined _16C671  ||  defined _12CE673
    #define ADDRESS_LAST_CODE_LOCATION 0x3FF
   #elif defined _16C672  ||  defined _12CE674
    #define ADDRESS_LAST_CODE_LOCATION 0x7FF
   #endif

    ..
    #asm
     DW /*CALL*/ 0x2000 + ADDRESS_LAST_CODE_LOCATION
    #endasm
    OSCCAL = W;
    ..

  *** Windowed devices ***
  First usage of device: read calibration value at address 0x3FF/
  0x7FF using your device programming equipment.

  Add the following initialization code:

   #ifdef CalValue
    OSCCAL = CalValue;
   #else
    #asm
     DW /*CALL*/ 0x2000 + ADDRESS_LAST_CODE_LOCATION
    #endasm
    OSCCAL = W;
   #endif

  After erasure of device:
   a) Add COMMAND LINE option, and replace NN
      with the actual value for the device:  -DCalValue=0xNN
   b) Alternatively use  #define CalValue 0xNN
      and replace NN with the actual value for the device. The value
      have to be changed for each device used.


