This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Unprotect SYSCON3 in XC164CS device

Hi everybody;
Im trying to manage the peripherals in a XC164CS device while the main program is executing. I belive that the SYSCON3 register is protected because when I try to writting in it, the initial value remains and don't change. Am I right?
How do you unprotect this register? Thank you very much.

  • I think you are correct. This is a Dave tool generated function to unlock protected registers. You can call it prior to modifying SYSCON3.

    //****************************************************************************
    // @Function      void MAIN_vUnlockProtecReg(void)
    //
    //----------------------------------------------------------------------------
    // @Description   This function makes it possible to write one protected
    //                register. After calling of this function and write on the
    //                protected register is the security level set to low
    //                protected mode.
    //
    //----------------------------------------------------------------------------
    // @Returnvalue   None
    //
    //----------------------------------------------------------------------------
    // @Parameters    None
    //
    //----------------------------------------------------------------------------
    // @Date          11/6/2009
    //
    //****************************************************************************
    
    // USER CODE BEGIN (UnlockProtecReg,1)
    
    // USER CODE END
    
    void MAIN_vUnlockProtecReg(void)
    {
      uword uwPASSWORD;
    
      if((SCUSLS & 0x1800) == 0x0800)      // if low protected mode
      {
    
        uwPASSWORD = SCUSLS & 0x00FF;
        uwPASSWORD = (~uwPASSWORD) & 0x00FF;
        SCUSLC = 0x8E00 | uwPASSWORD;      // command 4
    
      }  // end if low protected mode
    
      if((SCUSLS & 0x1800) == 0x1800)      // if write protected mode
      {
        SCUSLC = 0xAAAA;                   // command 0
        SCUSLC = 0x5554;                   // command 1
    
        uwPASSWORD = SCUSLS & 0x00FF;
        uwPASSWORD = (~uwPASSWORD) & 0x00FF;
    
        SCUSLC = 0x9600 | uwPASSWORD;      // command 2
        SCUSLC = 0x0800;                   // command 3; new PASSWOR is 0x00
    
        uwPASSWORD = SCUSLS & 0x00FF;
        uwPASSWORD = (~uwPASSWORD) & 0x00FF;
        SCUSLC = 0x8E00 | uwPASSWORD;      // command 4
    
      }  // end if write protected mode
    
    } //  End of function MAIN_vUnlockProtecReg
    

  • Thank you very much Walt:
    It works well! :)