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
Code: Select all
public dim BOOTSELECT_IN as INPUT_SW