• AVR Freaks

Hot!PIC18F4550 - How to clear LVP bit in C code ?

Author
danbakana
Junior Member
  • Total Posts : 107
  • Reward points : 0
  • Joined: 2012/08/27 05:21:28
  • Location: 0
  • Status: offline
2019/11/14 11:01:16 (permalink)
0

PIC18F4550 - How to clear LVP bit in C code ?

I'm trying to modify the LVP bit to 0 using TBLWT command, but, I don't know how to use this command in C and I didn't find anywhere how to do it. Does someone know how to do it ?

Edited:
I'm having problems to use RB5/KBI1/PGM as I/O. For those who need more information, I explained more in another question here:

https://www.microchip.com/forums/m1118698.aspx
post edited by danbakana - 2019/11/14 16:02:34
#1

13 Replies Related Threads

    1and0
    Access is Denied
    • Total Posts : 9989
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: PIC18F4550 - How to clear LVP bit in C code ? 2019/11/14 11:17:48 (permalink)
    +1 (1)
    danbakana
    I'm trying to modify the LVP bit to 0 using TBLWT command, but, I don't know how to use this command in C and I didn't find anywhere how to do it. Does someone know how to do it ? 

    Read your PIC datasheet on how to write the Flash memory, and the compiler user's guide to
    __asm("TBLWT");

    post edited by 1and0 - 2019/11/14 11:20:03
    #2
    Antipodean
    Super Member
    • Total Posts : 1778
    • Reward points : 0
    • Joined: 2008/12/09 10:19:08
    • Location: Didcot, United Kingdom
    • Status: online
    Re: PIC18F4550 - How to clear LVP bit in C code ? 2019/11/14 11:24:56 (permalink)
    +3 (3)
    This is a repeat of post earlier today.
    https://www.microchip.com/forums/m1118698.aspx
     
     

    Do not use my alias in your message body when replying, your message will disappear ...

    Alan
    #3
    Jim Nickerson
    User 452
    • Total Posts : 6365
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: PIC18F4550 - How to clear LVP bit in C code ? 2019/11/14 11:45:45 (permalink)
    +1 (1)
    I read the this

    the LVP bit may only be programmed by entering the High-Voltage ICSP mode

    to mean TBLWT may not be used to change this bit

    Attached Image(s)

    #4
    1and0
    Access is Denied
    • Total Posts : 9989
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: PIC18F4550 - How to clear LVP bit in C code ? 2019/11/14 12:14:14 (permalink)
    +1 (1)
    ... and from section 25.10 of the PIC18F4550 datasheet:
    The LVP bit may be set or cleared only when using standard high-voltage programming (VIHH applied to the MCLR/VPP/RE3 pin).

    #5
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11425
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: PIC18F4550 - How to clear LVP bit in C code ? 2019/11/14 12:21:42 (permalink)
    +1 (1)
    The LVP bit may be set or cleared only when using standard high-voltage programming

     
    But I wonder if that is only part of the ICSP logic, rather than the internal table write logic.
    #6
    NorthGuy
    Super Member
    • Total Posts : 5806
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: PIC18F4550 - How to clear LVP bit in C code ? 2019/11/14 12:28:00 (permalink)
    +1 (1)
    Why would you want to clear LVP from your program?
    #7
    1and0
    Access is Denied
    • Total Posts : 9989
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: PIC18F4550 - How to clear LVP bit in C code ? 2019/11/14 12:30:15 (permalink)
    +1 (1)
    jtemples
    But I wonder if that is only part of the ICSP logic, rather than the internal table write logic.

    Yeah.  Also from the 18F4550 datasheet:
    Programming the Configuration registers is done in a manner similar to programming the Flash memory. The WR bit in the EECON1 register starts a self-timed write to the Configuration register. In normal operation mode, a TBLWT instruction, with the TBLPTR pointing to the Configuration register, sets up the address and the data for the Configuration register write. Setting the WR bit starts a long write to the Configuration register. The Configuration registers are written a byte at a time. To write or erase a configuration cell, a TBLWT instruction can write a ‘1’ or a ‘0’ into the cell.

    I know the watchdog timer postscale config bits on the PIC18F can be rewritten at runtime. So try it and see.
    #8
    1and0
    Access is Denied
    • Total Posts : 9989
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: PIC18F4550 - How to clear LVP bit in C code ? 2019/11/14 12:30:52 (permalink)
    +1 (1)
    NorthGuy
    Why would you want to clear LVP from your program?

    OP wants to use that pin as a digital I/O.  And it looks like he cannot do it via ICSP.
     
    Edit: Quoted from OP's other thread:
    danbakana
    I read that I can fix it by disabling LVP Configuration bit( That, as I could see, is set 1 by default). In the datasheet says that the LVP pin can only be set or cleared when using standard high-voltage programming. But, what it means ? Does it means that I only can change it during programming and not during execution ?
    Another doubt is, if I change LVP I will nedd to programm the PIC through pins ICPGC and ICPGD ? If it is true, I will have a problem because these pins are not connected in the device, the are not available

    Does someone has any sugestion how can I solve this problem ?

    post edited by 1and0 - 2019/11/14 12:34:35
    #9
    Mysil
    Super Member
    • Total Posts : 3476
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: PIC18F4550 - How to clear LVP bit in C code ? 2019/11/14 16:15:02 (permalink)
    +1 (1)
    Hi,
    Even when you have cleared LVP bit in Configuration register,
    you shall be able to Erase and Reprogram the chip using ordinary
    High Voltage Programming & Erase = 12 V  on /MCLR/Vpp/RE3  pin 18 and programming
    on RB6/PGC  and RB7/PGD pins.
    Use a PICkit 3 or PICkit 4  or other capable programmer,
    But why can't you this all the time?
     
    See attached textfile, I seem to have used some bad language:
     
        Mysil
    post edited by Mysil - 2019/11/14 16:17:07
    #10
    ric
    Super Member
    • Total Posts : 24593
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PIC18F4550 - How to clear LVP bit in C code ? 2019/11/14 16:41:43 (permalink)
    +1 (1)
    Lemmie try Mysel's text:

    Hi,

    Even when you have cleared LVP bit in Configuration register,
    you shall be able to Erase and Reprogram the chip using ordinary
    High Voltage Programming & Erase = 12 V  on /MCLR/Vpp/RE3  pin 18 and programming
    on RB6/PGC  and RB7/PGD pins.
    Use a PICkit 3 or PICkit 4  or other capable programmer,

    But why can't you this all the time?
    You say in the other thread that you are using PICkit 3,
    so go into MPLAB X ,  Project Properties, PICkit 3 properties, and select 'Option Categories:'  'Programming'
    Uncheck any LVP stuff and select HVP programming mode entry.
    Then you may go to Configuration bit settings in the code, and do:    #pragma config LVP = OFF


    There seem to be some differences around,

    When I create a new project for PIC18F4550  using MPLAB X v5.25 and select PICkit 3 as programmer,
    Then open 'Project Properties'   'PICkit 3'  'Option Categories:  Program Options'
    there is nothing to specify selection between "Use low voltage programming mode entry" or not.
    For another project created some time ago using an earlier version of MPLAB X,
    There is a checkbox: 'Use low voltage programming mode entry' that is Unchecked.
    Admittedly, that project is for another chip type.

    In another project,  created not very long ago for PIC18F46K42, also with an earlier version of MPLAB X,
    'Project Properties'  'PICkit 3'    'Option Categories:  Program Options'

    there are Two different checkboxes on separate lines:
    'Use high voltage programming mode entry' [ ]
    'Use low voltage programming mode entry'  [ ]
    They are both Unchecked, so I really do not know what is done, configuration bits have #pragma config LVP = ON

    I have Not examined what differences are in 'configurations.xml'  in the 'nbproject' folder.
    I do not know if differences are due to different MPLAB X versions, or different selection of devices.


        Mysil

     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #11
    ric
    Super Member
    • Total Posts : 24593
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PIC18F4550 - How to clear LVP bit in C code ? 2019/11/14 16:44:17 (permalink)
    +1 (1)
    Yes, I changed two characters in the text, and you would have to have very sharp eyes to see the change.
    I'm still trying to determine the exact trigger.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #12
    danbakana
    Junior Member
    • Total Posts : 107
    • Reward points : 0
    • Joined: 2012/08/27 05:21:28
    • Location: 0
    • Status: offline
    Re: PIC18F4550 - How to clear LVP bit in C code ? 2019/11/14 16:52:12 (permalink)
    0
    Very nice. I will try to use mplabx, to change configuration, or revert the configuration if needed. I'm using Mikro C for PIC, but I will try use mplabx to change the configuration bits. Unfortunatelly, I only will be able to perform the test next monday, that will be when I will have access to the device again.
    #13
    NorthGuy
    Super Member
    • Total Posts : 5806
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: PIC18F4550 - How to clear LVP bit in C code ? 2019/11/14 18:43:30 (permalink)
    +1 (1)
    I think Mikro C should have means to change config bits.
     
    If anything, you can change the config bits directly in the HEX file before programming.
    #14
    Jump to:
    © 2019 APG vNext Commercial Version 4.5