Menu

Tiny+ Bootloader for PIC18F26K40 or PIC27K40

Requests
2019-10-11
2020-05-24
  • Johna Johnson

    Johna Johnson - 2019-10-11

    Hello.

    Has anyone got a firmware for the Tiny Bootloader+ for the PIC18F26K40 or PIC27K40 please? And teh PC app to work with them.

    I altered the firmware for them, but the PC application does not support them and I tried to use the PIC18F26K42 bits and pieces on the PC application, but it keeps coming back with the error that it will overwrite the bootloader. It has something to do with the on-board eeprom address being different on the PIC18FxxK40 and PIC18FxxK42 devices to standard 18F devices, but I can't see where it is looking for the eeprom address to load it and check it etc...

    Maybe the developer hasn't realised that the on-board eeprom address is differrent, and much higher, on these devices. I'm at my wits end trying to solve this problem, so many thanks if it can be solved.

     
  • sheldon

    sheldon - 2020-05-05

    did a working file for the PIC18FxxK40 series devices was done and tested ?
    Is this bootloader actively being updated still ?

     
  • Dan

    Dan - 2020-05-06

    Hi sheldom.

    I don't own either PIC18F26K40 or PIC27K40, so I will only give advice.
    So I haven't done any testing.

    If you absolutely need it, please create it referring to the page below and upload it for someone.
    I think this act will also contribute to your skill improvement.

    Reference pages

    https://sourceforge.net/p/tinypicbootload/discussion/devices/thread/0457fc98/

    http://www.picbasic.co.uk/forum/showthread.php?t=24182

    I think that it is better to rework the Firmware of PIC18F24k42 and PIC18F26k42 equipped with NVM memory.

    DAN.

     
  • sheldon

    sheldon - 2020-05-06

    thanks dan ,
    i am working my way though getting this to work on several pics

    btw link to picbasic site is no longer working

    cheers

     
    • Anobium

      Anobium - 2020-05-06

      I just checked. I dont have a K40 solution.

      But, I know a man that has it!! I will ask him today.

       
  • sheldon

    sheldon - 2020-05-06

    thanks - looking at the data sheets i know the structure of the 18f25_26k40 differs to that of the 18f27_47k40 , and the 18f67K40 is a little differnt again - not just cos of the flash space on each ,

    i am working with the 18f47k40 series , other pics are 18f46k80,18f87k22 , which i think would be supported currently

     
    • Dan

      Dan - 2020-05-06
       
  • Dan

    Dan - 2020-05-06

    .

     

    Last edit: Dan 2020-05-06
  • Johna Johnson

    Johna Johnson - 2020-05-23

    Sorry for the late reply. Many thanks for the responses, but I re-wrote the Bootlaoder firmware for the PIC18F26K40 device. I converted the firmware to Proton BASIC, so it is easier to understand and simpler to manipulate and alter. The Proton compiler produces extremely compact Asm code and also accepts Asm mnemonics in the BASIC listings.

    I used an already functional device type (0x6E) and changed the parameters in the ini file for it because I couldn't quite see an empty spot in the over crowded ini file.

    Here is the code for the Proton BASIC compiler, if it helps anyone. It operates exactly the same as the code written in raw assembler. I'm now in the process of trying to create a bootloader for the dsPIC33CK devices based upon the original dsPIC33E types in the excellent Tiny+ bootloader, but having some difficulties for now. It will be written in Proton24, which is the same BASIC compiler, but for PIC24 and dsPIC33 devices.

    '
    ' Serial Bootloader for a PIC18F26K40 device.
    ' Operates with a 16MHz external oscillator and a Baud of 19200
    ' The code is based upon the Tiny+ Bootloader
    '
    ' Written for the Proton BASIC Compiler version 3.7.3.8 onwards
    '
        Device = 18F26K40
        Declare Xtal = 16
        Declare Library_Core = Off                      ' Disable the compiler's Library core and any extra items the compiler adds to a user's program
    
    $define cIdTypePIC      0x6E                        ' The microcntroller type for the PC application
    $define cMax_Flash      _code                       ' The amount of flash memory on th edevice (in bytes)
    $define cWriteBlockSize _block                      ' The size of the block write to flash memory
    $define cEepromSize     _eeprom                     ' Size of EEPROM (256 or 1024)
    
    $define cBootloader_Address $eval (cMax_Flash - 264) ' 264 bytes long reserved at the top of flash for the bootloader
    '
    ' Bit names of the NVMCONx SFRs
    '
    $define cRD      0
    $define cWR      1
    $define cWREN    2
    $define cWRERR   3
    $define cFREE    4
    $define cNVMREG0 6
    $define cNVMREG1 7
    '
    ' Create variables for the bootloader
    '
        Dim bWriteBuffer[64] As Byte                    ' Buffer used for holding data
        Dim bCRC             As Byte                    ' Holds the CRC value
        Dim bByteCount       As Byte                    ' Holds the amount of bytes for a block flash write
        Dim bFlags           As Byte                    ' Holds the requirement of which memory area to write
        Dim tEepromWrite     As bFlags.6                ' Set if eeprom memory is to be written
        Dim tConfigWrite     As bFlags.7                ' Set if config memory is to be written
    
        Dim bTimeoutCounter1 As Byte                    ' \
        Dim bTimeoutCounter2 As Byte                    ' |  Timeout counter for receiving a byte
        Dim bTimeoutCounter3 As Byte                    ' /
    
        Dim wFSR0 As FSR0L.Word                         ' Convert 8-bit SFRs FSR0L\H into a 16-bit SFR
    
    $ifndef False
        $define False 0
    $endif
    $ifndef True
        $define True 1
    $endif
    '-----------------------------------------------------------------------
    ' Reset
    '
        GoTo BootloaderStart                            ' Jump to the start of the bootloader
    '
    ' Set the high flash memory address where the bootloader sits
    '
        Org cBootloader_Address
        Nop                                             ' \
        Nop                                             ' | Space to store the first 4 mnemonics from the user program
        Nop                                             ' |
        Nop                                             ' /
    
    BootloaderStart:
        Clear ANSELC                                    ' Set PORTC to digital
    '
    ' UART1 Actual Baud = 19230.8
    ' UART1 Baud Error = 0.15625
    '
        SP1BRG  = 51                                    ' \
        SP1BRGH = 0                                     ' | Setup USART1 for 19200 Baud
        TX1STA  = 36                                    ' |
        RC1STA  = 144                                   ' /
    '
    ' Configure USART1 PPS
    '
        PPS_Unlock()                                    ' Unlock PPS
        TX1PPS = Pin_C6                                 ' Set PORTC.6 as TX
        RX1PPS = Pin_C7                                 ' Set PORTC.7 as RX
        RC6PPS = PPS_Fn_TX1                             ' Set PORTC.6 as TX
        RC7PPS = PPS_Fn_RX1                             ' Set PORTC.7 as RX
    '
    ' Wait for computer response
    '
        GoSub ReceiveByteInto_WREG                      ' Receive a byte from USART1 into WREG
        If WREG <> $C1 Then GoTo Bootloader_Exit        ' Expect $C1
        TXREG1 = cIdTypePIC                             ' Send the microcontroller type to the PC application
    
        Do                                              ' Create a loop
            Clrwdt                                      ' Clear the watchdog timer within the loop
            WREG = "C"                                  ' Everything OK so send the character "C" to the PC application
    ContinueLoop:
            TXREG1 = WREG                               ' Transmit the contents of WREG
            Clear bCRC
            GoSub ReceiveByteInto_WREG                  ' Receive the Upper address
            TBLPTRU = WREG
            bFlags = WREG                               ' For EEPROM and Config
            GoSub ReceiveByteInto_WREG                  ' Receive the High address
            TBLPTRH = WREG
            $if (cEepromSize = 1024)
            NVMADRH = WREG                              ' High address of EEPROM
            $endif
            GoSub ReceiveByteInto_WREG                  ' Receive the Low address
            TBLPTRL = WREG
            NVMADR = WREG                               ' Low address of EEPROM
    
            GoSub ReceiveByteInto_WREG                  ' Receive the byte count required for writing
            bByteCount = WREG                           ' Place it into variable bByteCount
    
            wFSR0 = AddressOf(bWriteBuffer)             ' FSR0L\H now hold Buffer Beginning address
            Tblrd*-                                     ' Read from flash memory with auto decrement of address in TBLPTR
    RcvOct:
            GoSub ReceiveByteInto_WREG                  ' Receive the type of write
            POSTINC0 = WREG                             ' For Config memory
            NVMDAT = WREG                               ' For EEPROM
            TABLAT = WREG                               ' For Flash memory
            Tblwt+*                                     ' Write to flash memory with auto increment of address
            Djnz bByteCount, RcvOct                     ' Loop for the amount of bytes to receive
    
            GoSub ReceiveByteInto_WREG                  ' Get CRC
    CRC_Failed:                                         ' CRC failed
            WREG = "N"                                  ' Get ready to send the character "N"
            If STATUSbits_Z = 0 Then GoTo ContinueLoop
    
            If tConfigWrite = True Then                 ' Skip if not writing to Config
                GoTo Write_Config                       ' Write Config
            EndIf
            WREG = (1 << cWREN)                         ' Setup for EEPROM write
            If tEepromWrite = False Then                ' Is it an EEPROM write?
                GoSub SetupEraseBlock                   ' No. So setup to erase the block of flash memory
            EndIf
            GoSub SetupWriteByte
            Continue
            '
            ' Write the configuration fuses (if required)
            '
    Write_Config:
            Dec FSR0L                                   ' FSR0 = FSR0 - 1
            Clrwdt                                      ' Clear the watchdog timer
            TABLAT = INDF0                              ' Load TABLAT
            WREG = ((1 << cNVMREG1) | (1 << cNVMREG0) | (1 << cWREN))  ' Setup for Config memory
            GoSub SetupWriteByte
            Tblrd*-                                     ' Write to memory and auto decrement address in TBLPTRL\H
            Tstfsz FSR0L                                ' FSR0L = 0?
            GoTo Write_Config                           ' \ Loop until FSR0L = 0
        Loop                                            ' /
    '
    ' Subroutines
    '
    SetupEraseBlock:
        WREG = $94                                      ' Setup Erase; EEPGD, FREE, WREN = 1, CFGS = 0
    
    SetupWriteByte:
        NVMCON1 = WREG
        NVMCON2 = $55                                   ' \ Unlock memory writes
        NVMCON2 = $AA                                   ' /
        Set NVMCON1bits_WR
        Retlw ((1 << cNVMREG1) | (1 << cWREN))          ' Setup for writes in WREG when returned
    
    ReceiveByteInto_WREG:
        Clrwdt                                          ' Clear the watchdog timer
        bTimeoutCounter1 = ((_xtal / 2) + 1)            ' For 20MHz => 11 => 1 second delay
    Repeat1:
        Clear bTimeoutCounter2
    Repeat2:
        Clear bTimeoutCounter3
    Repeat3:
        If PIR3bits_RC1IF = 0 Then NotReceivedYet       ' Receive a byte from USART1
        WREG = RC1REG                                   ' Place the read data into WREG
        bCRC = bCRC + WREG                              ' Calculate CRC
        Return
    
    NotReceivedYet:
        Clrwdt                                          ' Clear the watchdog timer within the inner loop
        Djnz bTimeoutCounter3, Repeat3
        Djnz bTimeoutCounter2, Repeat2
        Djnz bTimeoutCounter1, Repeat1
    '
    ' Timeout
    '
    Bootloader_Exit:
        Clear NVMCON1                                   ' Deactivate EECON
        Clear RCSTA1bits_SPEN                           ' Deactivate USART1
        GoTo(cBootloader_Address)                       ' Jump to the start of the user program
    
    '-----------------------------------------------------------------------------------------------
    ' Set config fuses for an external oscillator on a PIC18F26K40 device
    '
    Config_Start
        RSTOSC   = EXTOSC                   ' EXTOSC operating per FEXTOSC Bits
        FEXTOSC  = HS                       ' HS (crystal oscillator) above 8 MHz. PFM set to high power
        CLKOUTEN = Off                      ' CLKOUT function is disabled
        WDTE     = On                       ' Watchdog enabled
        CSWEN    = On                       ' Writing to NOSC and NDIV is allowed
        FCMEN    = Off                      ' Fail-Safe Clock Monitor disabled
        MCLRE    = EXTMCLR                  ' MCLR pin is MCLR
        PWRTE    = On                       ' Power up timer enabled
        LPBOREN  = Off                      ' LPBOREN disabled
        BOREN    = Off                      ' Brown-out turned off
        BORV     = VBOR_245                 ' Brown-out Reset Voltage (VBOR) set to 2.45V
        ZCD      = Off                      ' ZCD Zero Detect disabled.
        PPS1WAY  = Off                      ' PPSLOCK bit can be set and cleared repeatedly (subject to the unlock sequence)
        STVREN   = Off                      ' Stack full/underflow will not cause Reset
        Debug    = Off                      ' Background debugger disabled
        XINST    = Off                      ' Extended Instruction Set and Indexed Addressing Mode disabled
        WDTCPS   = WDTCPS_15                ' Watchdog Divider ratio 1:1048576 (32 seconds)
        WDTCWS   = WDTCWS_7                 ' Window always open (100%). Software control. Keyed access not required
        WDTCCS   = LFINTOSC                 ' WDT input clock selector->WDT reference clock is the 31.2kHz HFINTOSC output
        SCANE    = Off                      ' Scanner module is Not available for use. SCANMD bit is ignored
        LVP      = Off                      ' HV On MCLR/VPP must be used for programming
        WRT0     = Off                      ' Block 0 (000800-001FFFh) not SetupWriteByte-protected
        WRT1     = Off                      ' Block 1 (002000-003FFFh) not SetupWriteByte-protected
        WRTC     = Off                      ' Configuration registers (300000-30000Bh) not SetupWriteByte-protected
        WRTB     = Off                      ' Boot Block (000000-0007FFh) not SetupWriteByte-protected
        WRTD     = Off                      ' Data EEPROM not SetupWriteByte-protected
        Cp       = Off                      ' UserNVM code protection disabled
        CPD      = Off                      ' DataNVM code protection disabled
        EBTR0    = Off                      ' Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
        EBTR1    = Off                      ' Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
        EBTRB    = Off                      ' Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
    Config_End
    
     

    Last edit: Johna Johnson 2020-05-23
    • sheldon

      sheldon - 2020-05-24

      HI Johna ,

      Thank very much
      btw as you probably know microchip in there “wisdom” had dropped support for MPASM from 5.40 version of MPLABX
      so 5.35 was the last version of MPASM ver 5.87 – so don’t get caught when updating and droped support for 64bit machines for MPASM as well

      I think proton basic still uses MPASM , like wise PBP does as well to get its hex file

      Ill need to support a bootloader for other chips as the 18f87k22, 18f46k80 , so I assuming the code you have here I can easly change things about to suit , but will check registers use

      I have build the asm from the site for the 18f87k22 , but are not able to get a response from the usart1 either as reset or “ABC” ,

      the usb to ttl -ch340 has not dtr / rts pin

      is the ABC response built into the bootloader code ????

      chip It uses a 16.368 tcxo , as exteral osc , using a setting of PPL4 on config ,
      what value should I show for the XTAL value

      in my orginal code in PBP and look like you do it here , in calculate the correct values for the USART port to communicate

      still trying to make the orginal asm work on the 18f87k22 – if I can get to talk to the pic via serial in any way would be a bonus atm


      All email contents are confidential communications and not released to third parties without written authorisation from author of this email
      Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10

      From: Johna Johnsontop204@users.sourceforge.net
      Sent: Saturday, 23 May 2020 19:43
      To: [tinypicbootload:discussion] requests@discussion.tinypicbootload.p.re.sourceforge.net
      Subject: [tinypicbootload:discussion] Tiny+ Bootloader for PIC18F26K40 or PIC27K40

      Sorry for the late reply. Many thanks for the responses, but I re-wrote the Bootlaoder firmware for the PIC18F26K40 device. I converted the firmware to Proton BASIC, so it is easier to understand and simpler to manipulate and alter. The Proton compiler produces extremely compact Asm code and accepts mnemonics in the BASIC listings.

      I used an already functional device type (0x6E) and changed the parameters in the ini file for it, because I couldn't quite see an empty spot in the over crowded ini file.

      Here is the code for the Proton BASIC compiler, if it helps anyone. It operates exactly the same as the code written in raw assembler. I'm now in the process of trying to create a bootloader for the dsPIC33CK devices based upon the original dsPIC33E types in the excellent Tiny+ bootloader, but having some difficulties for now. It will be written the Proton24, which is the same BASIC compiler, but for PIC24 and dsPIC33 devices.

      '

      ' Serial Bootloader for a PIC18F26K40 device.

      ' Operates with a 16MHz external oscillator and a Baud of 19200

      ' The code is based upon the Tiny+ Bootloader

      '

      ' Written by Les Johnson for the Proton BASIC Compiler version 3.7.3.0 onwards

      '

      Device = 18F26K40
      
      Declare Xtal = 16
      
      Declare Library_Core = Off                      ' Disable the compiler's LIbrary core and any extra itmes the compiler adds to a user's program
      

      $define cIdTypePIC 0x6E ' The microcntroller type for the PC application

      $define cMax_Flash _code ' The amount of flash memory on th edevice (in bytes)

      $define cWriteBlockSize _block ' The size of the block write to flash memory

      $define cEepromSize _eeprom ' Size of EEPROM (256 or 1024)

      $define cBootloader_Address $eval (cMax_Flash - 264) ' 264 bytes long reserved at the top of flash for the bootloader

      '

      ' Bit names of the NVMCONx SFRs

      '

      $define cRD 0

      $define cWR 1

      $define cWREN 2

      $define cWRERR 3

      $define cFREE 4

      $define cNVMREG0 6

      $define cNVMREG1 7

      '

      ' Create variables for the bootloader

      '

      Dim bWriteBuffer[64] As Byte                    ' Buffer used for holding data
      
      Dim bCRC             As Byte                    ' Holds the CRC value
      
      Dim bByteCount       As Byte                    ' Holds the amount of bytes for a block flash write
      
      Dim bFlags           As Byte                    ' Holds the requirement of which memory area to write
      
      Dim tEepromWrite     As bFlags.6                ' Set if eeprom memory is to be written
      
      Dim tConfigWrite     As bFlags.7                ' Set if config memory is to be written
      
      
      
      Dim bTimeoutCounter1 As Byte                    ' \
      
      Dim bTimeoutCounter2 As Byte                    ' |  Timeout counter for receiving a byte
      
      Dim bTimeoutCounter3 As Byte                    ' /
      
      
      
      Dim wFSR0 As FSR0L.Word                         ' Convert 8-bit SFRs FSR0L\H into a 16-bit SFR
      

      $ifndef False

      $define False 0
      

      $endif

      $ifndef True

      $define True 1
      

      $endif

      '-----------------------------------------------------------------------

      ' Reset

      '

      GoTo BootloaderStart                            ' Jump to the start of the bootloader
      

      '

      ' Set the high flash memory address where the bootloader sits

      '

      Org cBootloader_Address
      
      Nop                                             ' \
      
      Nop                                             ' | Space to store the first 4 mnemonics from the user program
      
      Nop                                             ' |
      
      Nop                                             ' /
      

      BootloaderStart:

      Clear ANSELC                                    ' Set PORTC to digital
      

      '

      ' UART1 Actual Baud = 19230.8

      ' UART1 Baud Error = 0.15625

      '

      SP1BRG  = 51                                    ' \
      
      SP1BRGH = 0                                     ' | Setup USART1 for 19200 Baud
      
      TX1STA  = 36                                    ' |
      
      RC1STA  = 144                                   ' /
      

      '

      ' Configure USART1 PPS

      '

      PPS_Unlock()                                    ' Unlock PPS
      
      TX1PPS = Pin_C6                                 ' Set PORTC.6 as TX
      
      RX1PPS = Pin_C7                                 ' Set PORTC.7 as RX
      
      RC6PPS = PPS_Fn_TX1                             ' Set PORTC.6 as TX
      
      RC7PPS = PPS_Fn_RX1                             ' Set PORTC.7 as RX
      

      '

      ' Wait for computer response

      '

      GoSub ReceiveByteInto_WREG                      ' Receive a byte from USART1 into WREG
      
      If WREG <> $C1 Then GoTo Bootloader_Exit        ' Expect $C1
      
      TXREG1 = cIdTypePIC                             ' Send the microcontroller type to the PC application
      
      
      
      Do                                              ' Create a loop
      
          Clrwdt                                      ' Clear the watchdog timer within the loop
      
          WREG = "C"                                  ' Everything OK so send the character "C" to the PC application
      

      ContinueLoop:

          TXREG1 = WREG                               ' Transmit the contents of WREG
      
          Clear bCRC
      
          GoSub ReceiveByteInto_WREG                  ' Receive the Upper address
      
          TBLPTRU = WREG
      
          bFlags = WREG                               ' For EEPROM and Config
      
          GoSub ReceiveByteInto_WREG                  ' Receive the High address
      
          TBLPTRH = WREG
      
          $if (cEepromSize = 1024)
      
          NVMADRH = WREG                              ' High address of EEPROM
      
          $endif
      
          GoSub ReceiveByteInto_WREG                  ' Receive the Low address
      
          TBLPTRL = WREG
      
          NVMADR = WREG                               ' Low address of EEPROM
      
      
      
          GoSub ReceiveByteInto_WREG                  ' Receive the byte count required for writing
      
          bByteCount = WREG                           ' Place it into variable bByteCount
      
      
      
          wFSR0 = AddressOf(bWriteBuffer)             ' FSR0L\H now hold Buffer Beginning address
      
          Tblrd*-                                     ' Read from flash memory with auto decrement of address in TBLPTR
      

      RcvOct:

          GoSub ReceiveByteInto_WREG                  ' Receive the type of write
      
          POSTINC0 = WREG                             ' For Config memory
      
          NVMDAT = WREG                               ' For EEPROM
      
          TABLAT = WREG                               ' For Flash memory
      
          Tblwt+*                                     ' Write to flash memory with auto increment of address
      
          Djnz bByteCount, RcvOct                     ' Loop for the amount of bytes to receive
      
      
      
          GoSub ReceiveByteInto_WREG                  ' Get CRC
      

      CRC_Failed: ' CRC failed

          WREG = "N"                                  ' Get ready to send the character "N"
      
          If STATUSbits_Z = 0 Then GoTo ContinueLoop
      
      
      
          If tConfigWrite = True Then                 ' Skip if not writing to Config
      
              GoTo Write_Config                       ' Write Config
      
          EndIf
      
          WREG = (1 << cWREN)                         ' Setup for EEPROM write
      
          If tEepromWrite = False Then                ' Is it an EEPROM write?
      
              GoSub SetupEraseBlock                   ' No. So setup to erase the block of flash memory
      
          EndIf
      
          GoSub SetupWriteByte
      
          Continue
      
          '
      
          ' Write the configuration fuses (if required)
      
          '
      

      Write_Config:

          Dec FSR0L                                   ' FSR0 = FSR0 - 1
      
          Clrwdt                                      ' Clear the watchdog timer
      
          TABLAT = INDF0                              ' Load TABLAT
      
          WREG = ((1 << cNVMREG1) | (1 << cNVMREG0) | (1 << cWREN))  ' Setup for Config memory
      
          GoSub SetupWriteByte
      
          Tblrd*-                                     ' Write to memory and auto decrement address in TBLPTRL\H
      
          Tstfsz FSR0L                                ' FSR0L = 0?
      
          GoTo Write_Config                           ' \ Loop until FSR0L = 0
      
      Loop                                            ' /
      

      '

      ' Subroutines

      '

      SetupEraseBlock:

      WREG = $94                                      ' Setup Erase; EEPGD, FREE, WREN = 1, CFGS = 0
      

      SetupWriteByte:

      NVMCON1 = WREG
      
      NVMCON2 = $55                                   ' \ Unlock memory writes
      
      NVMCON2 = $AA                                   ' /
      
      Set NVMCON1bits_WR
      
      Retlw ((1 << cNVMREG1) | (1 << cWREN))          ' Setup for writes in WREG when returned
      

      ReceiveByteInto_WREG:

      Clrwdt                                          ' Clear the watchdog timer
      
      bTimeoutCounter1 = ((_xtal / 2) + 1)            ' For 20MHz => 11 => 1 second delay
      

      Repeat1:

      Clear bTimeoutCounter2
      

      Repeat2:

      Clear bTimeoutCounter3
      

      Repeat3:

      If PIR3bits_RC1IF = 0 Then NotReceivedYet       ' Receive a byte from USART1
      
      WREG = RC1REG                                   ' Place the read data into WREG
      
      bCRC = bCRC + WREG                              ' Calculate CRC
      
      Return
      

      NotReceivedYet:

      Clrwdt                                          ' Clear the watchdog timer within the inner loop
      
      Djnz bTimeoutCounter3, Repeat3
      
      Djnz bTimeoutCounter2, Repeat2
      
      Djnz bTimeoutCounter1, Repeat1
      

      '

      ' Timeout

      '

      Bootloader_Exit:

      Clear NVMCON1                                   ' Deactivate EECON
      
      Clear RCSTA1bits_SPEN                           ' Deactivate USART1
      
      GoTo(cBootloader_Address)                       ' Jump to the start of the user program
      

      '-----------------------------------------------------------------------------------------------

      ' Set config fuses for an external oscillator on a PIC18F26K40 device

      '

      Config_Start

      RSTOSC   = EXTOSC                   ' EXTOSC operating per FEXTOSC Bits
      
      FEXTOSC  = HS                       ' HS (crystal oscillator) above 8 MHz. PFM set to high power
      
      CLKOUTEN = Off                      ' CLKOUT function is disabled
      
      WDTE     = On                       ' Watchdog enabled
      
      CSWEN    = On                       ' Writing to NOSC and NDIV is allowed
      
      FCMEN    = Off                      ' Fail-Safe Clock Monitor disabled
      
      MCLRE    = EXTMCLR                  ' MCLR pin is MCLR
      
      PWRTE    = On                       ' Power up timer enabled
      
      LPBOREN  = Off                      ' LPBOREN disabled
      
      BOREN    = Off                      ' Brown-out turned off
      
      BORV     = VBOR_245                 ' Brown-out Reset Voltage (VBOR) set to 2.45V
      
      ZCD      = Off                      ' ZCD Zero Detect disabled.
      
      PPS1WAY  = Off                      ' PPSLOCK bit can be set and cleared repeatedly (subject to the unlock sequence)
      
      STVREN   = Off                      ' Stack full/underflow will not cause Reset
      
      Debug    = Off                      ' Background debugger disabled
      
      XINST    = Off                      ' Extended Instruction Set and Indexed Addressing Mode disabled
      
      WDTCPS   = WDTCPS_15                ' Watchdog Divider ratio 1:1048576 (32 seconds)
      
      WDTCWS   = WDTCWS_7                 ' Window always open (100%). Software control. Keyed access not required
      
      WDTCCS   = LFINTOSC                 ' WDT input clock selector->WDT reference clock is the 31.2kHz HFINTOSC output
      
      SCANE    = Off                      ' Scanner module is Not available for use. SCANMD bit is ignored
      
      LVP      = Off                      ' HV On MCLR/VPP must be used for programming
      
      WRT0     = Off                      ' Block 0 (000800-001FFFh) not SetupWriteByte-protected
      
      WRT1     = Off                      ' Block 1 (002000-003FFFh) not SetupWriteByte-protected
      
      WRTC     = Off                      ' Configuration registers (300000-30000Bh) not SetupWriteByte-protected
      
      WRTB     = Off                      ' Boot Block (000000-0007FFh) not SetupWriteByte-protected
      
      WRTD     = Off                      ' Data EEPROM not SetupWriteByte-protected
      
      Cp       = Off                      ' UserNVM code protection disabled
      
      CPD      = Off                      ' DataNVM code protection disabled
      
      EBTR0    = Off                      ' Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
      
      EBTR1    = Off                      ' Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
      
      EBTRB    = Off                      ' Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
      

      Config_End

      Tiny+ Bootloader for PIC18F26K40 or PIC27K40https://sourceforge.net/p/tinypicbootload/discussion/requests/thread/b9730dde34/?limit=25#04ff

      Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/tinypicbootload/discussion/requests/

      To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

       

Log in to post a comment.

MongoDB Logo MongoDB