Hid bootloader and 18f2550

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Jerry Messina
Swordfish Developer
Posts: 1246
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: Hid bootloader and 18f2550

Post by Jerry Messina » Thu Oct 15, 2015 9:55 am

Hmmm...that should be ok. The following works for me:

Code: Select all

device = 18F2550

// allow PORTE.3 (MCLR) to be used as an input
config MCLRE = OFF

// friendly alias name for the switch input pin
public dim INPUT_SW as PORTE.3      // sw w/ext pullup

// the bootloader creates another alias name for the switch
dim BOOTSELECT_IN as INPUT_SW

// bootloader function to read the switch
Public Inline Function UserBootselect() As Boolean
    // << add code to read switch or IO pin >>
    // << just return false if not used >>
   result = false              // run application
   
    If (BOOTSELECT_IN = 0) Then     // read low-active IO pin
       result = true               // stay in bootloader
   EndIf
End Function

dim b as bit

// can't use 'input()' with PORTE.3 and the 28-pin devices
// it uses TRISE to make the pin an input, and there's no TRISE defined for the 2550
// for those chips it's always an input anyway, so it's not needed
'input(PORTE.3)
// since you can't use PORTE.3, you can't use an alias name either (since they're the same)
'input(INPUT_SW)
'input(BOOTSELECT_IN)

// just use this to read the pin
b = PORTE.3
// or this
b = INPUT_SW
// or this
b = BOOTSELECT_IN

// this is ok too
if UserBootSelect() then
    ' switch activated... do something
endif
If you got an error like 'Identifier not declared: BOOTSELECT_IN' that's likely because the pin isn't declared public. Either use the UserBootselect() function to read the pin or change the declaration in userio.bas to:

Code: Select all

public dim BOOTSELECT_IN as INPUT_SW
It shouldn't have complained about TRISE not being found. If it did there's something else going on.

Post Reply