News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Using the ICSP pins as GPIO

Started by JohnB, Jun 13, 2026, 11:39 AM

Previous topic - Next topic

JohnB

I have not been able to taggle either of the ISCP Clock or Data lines on the 16F15245.  I have added this in my Init code:

    pinmode(LATA.0, Output)
    pinHigh LATA.0
and set LVP=OFF

Is there anything else I need to do?
JohnB

trastikata

I did not check the PIC in question, but some pins have their analog function on by default at POR.

JohnB

At the start of Init I have

    ' Disable analog
    ANSELA = 0
    ANSELB = 0
    ANSELC = 0

I don't know if there is anything else I need to do to set it to digital.
JohnB

top204

In general, I have never had any problems with using the ICSP (In Circuit Serial Programming) pins, as general purpose I/O lines, as long as the programmer is disconnected from the circuit when it is operating, because some programmers can put a load on the pins.

The compiler sets a device's pins to digital before the user program starts , and disables some other peripherals. See the device's .def file. For example the "16F15245.def" file has the codes:

'-----------------------------------------------------------------------------------
' Make the device's I/O pins digital (if required) before the main program starts
' This can be added too by the user and shared on the forum
'
#IfnSym __SYSCOM_LIBRARY_OFF_      ' Has the library been disabled in the compiler?
    ANSELA = $00
    ANSELB = $00
    ANSELC = $00
    SLRCONA = $00
    SLRCONB = $00
    SLRCONC = $00
    INLVLA = $00
    INLVLB = $00
    INLVLC = $00
#EndIfSym


For a test, try a none-complex piece of code that will set the pins to repeatedly output low and output high, with a pair of LEDs connected to them. Even in the 21st century, you cannot beat a pair of flashing LEDs to signal a good or bad result.

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' A code listing template for a PIC16F15245 device operating at 32MHz with the internal oscillator.
'
' Written by Les Johnson for the Positron BASIC compiler.
'
    Device = 16F15245                                       ' Tell the compiler what device to compile for
    Declare Xtal = 32                                       ' Tell the compiler what frequency the device is operating at (in MHz)
    Declare Auto_Heap_Arrays = On                           ' Make all arrays "Heap" types, so they always get placed after standard variables
    Declare Auto_Heap_Strings = On                          ' Make all Strings "Heap" types, so they always get placed after standard variables
    Declare Auto_Variable_Bank_Cross = On                   ' Make sure all multi-byte variables remain within a single RAM bank
'
' Setup USART1
'
    Declare HSerial_Baud = 9600
    Declare HSerout1_Pin = PORTB.7
'
' Define the pins to use for the LEDs
'
$define LED1_Pin PORTA.0
$define LED2_Pin PORTA.1
'
' Create any global variables, constants and aliases here
'

'--------------------------------------------------------------------------------------------------
' The main program starts here
' Flash two LEDs
'
Main:
    Setup()                                                 ' Setup the program and peripherals

    Do                                                      ' Create a loop
        PinSet LED1_Pin                                     ' \ Illuminate the LEDs
        PinSet LED2_Pin                                     ' /
        DelayMs 500                                         ' Wait for half a second
        PinClear LED1_Pin                                   ' \
        PinClear LED2_Pin                                   ' / Extinguish the LEDs
        DelayMs 500                                         ' Wait for half a second
    Loop                                                    ' Do it forever

'--------------------------------------------------------------------------------------------------
' Setup the program and peripherals
' Input     : None
' Output    : None
' Notes     : None
'
Proc Setup()
    Osc_Init_32MHz()                                        ' Setup the device to operate with its internal oscillator at 32MHz
    PinLow LED1_Pin                                         ' \
    PinLow LED2_Pin                                         ' / Set the pins as output low
EndProc

'--------------------------------------------------------------------------------------------------
' Setup the PIC16F15245 to operate with its internal oscillator at 32MHz
' Input     : None
' Output    : None
' Notes     : None
'
Proc Osc_Init_32MHz()
    OSCEN   = %00000000
    OSCFRQ  = %00000101                                     ' FRQ 32 MHz
    OSCTUNE = %00000000
    DelayMs 100                                             ' Wait for the oscillator to stabilise
EndProc

'--------------------------------------------------------------------------------------------------
' Setup the config fuses for the internal 32MHz oscillator.
'
    Config1 FEXTOSC_OFF,_                                   ' External Oscillator not enabled
            RSTOSC_HFINTOSC_32MHZ,_                         ' HFINTOSC (32 MHz)
            CLKOUTEN_OFF,_                                  ' CLKOUT function is disabled. I/O function on RA4
            VDDAR_HI                                        ' VDD Internal analog systems are calibrated for operation between VDD = 2.3V - 5.5V

    Config2 MCLRE_EXTMCLR,_                                 ' If LVP = 0, MCLR pin is MCLR. If LVP = 1. RA3 pin function is MCLR
            PWRTS_PWRT_OFF,_                                ' PWRT is disabled
            WDTE_OFF,_                                      ' WDT disabled. SEN is ignored
            BOREN_ON,_                                      ' Brown-out Reset Enabled. SBOREN bit is ignored
            BORV_LO,_                                       ' Brown-out Reset Voltage (VBOR) set to 1.9V
            PPS1WAY_OFF,_                                   ' The PPSLOCKED bit can be set and cleared as needed
            STVREN_ON                                       ' Stack Overflow or Underflow will cause a reset

    Config4 BBSIZE_BB512,_                                  ' 512 words boot block size
            BBEN_OFF,_                                      ' Boot Block is disabled
            SAFEN_OFF,_                                     ' SAF is disabled
            WRTAPP_OFF,_                                    ' Application Block is not write-protected
            WRTB_OFF,_                                      ' Boot Block is not write-protected
            WRTC_OFF,_                                      ' Configuration Registers are not write-protected
            WRTSAF_OFF,_                                    ' Storage Area Flash is not write-protected
            LVP_OFF                                         ' High Voltage on MCLR/Vpp must be used for programming

    Config5 CP_OFF                                          ' User Program Flash Memory code protection is disabled

Then use the same code listing template, and read the pins and transmit the results to a serial terminal. If they signal a 1 when they are brought high, and 0 when they are grounded, then they are digital I/O lines.

Regards
Les

streborc

Master Clear (RA3 / pin 4) is tied high, or is it being used as an input?