News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Port Configuration on PIC16F12544

Started by JohnB, Oct 31, 2025, 03:17 PM

Previous topic - Next topic

JohnB

I am having problems configuring the ports for the PIC16F12544. 
These are my port assignments:
' Pin assignments - Inputs (Left side - all with IOC)
Symbol RC_Ch1_Pin = PORTB.7     ' Pin 10 - RC Channel 1 PWM input
Symbol RC_Ch2_Pin = PORTC.7     ' Pin 9  - RC Channel 2 PWM input
Symbol RC_Ch3_Pin = PORTC.6     ' Pin 8  - RC Channel 3 PWM input
Symbol RC_Ch4_Pin = PORTC.3     ' Pin 7  - RC Channel 4 PWM input
Symbol RC_Ch5_Pin = PORTC.4     ' Pin 6  - RC Channel 5 PWM input
Symbol RC_Ch6_Pin = PORTC.5     ' Pin 5  - RC Channel 6 PWM input
Symbol RC_Ch7_Pin = PORTA.4     ' Pin 3  - RC Channel 7 PWM input
Symbol RC_Ch8_Pin = PORTA.5     ' Pin 2  - RC Channel 8 PWM input

' Pin assignments - Outputs (Right side)
Symbol LED_Pin = LATA.0         ' Pin 19 - Status LED  Active Low
Symbol Switch1_Pin = LATB.6     ' Pin 11 - Channel 1 switch output
Symbol Switch2_Pin = LATB.5     ' Pin 12 - Channel 2 switch output
Symbol Switch4_Pin = LATB.4     ' Pin 13 - Channel 3 switch output
Symbol Switch3_Pin = LATC.2     ' Pin 14 - Channel 4 switch output
Symbol Switch5_Pin = LATC.1     ' Pin 15 - Channel 5 switch output
Symbol Switch6_Pin = LATC.0     ' Pin 16 - Channel 6 switch output
Symbol Switch7_Pin = LATA.2     ' Pin 17 - Channel 7 switch output
Symbol Switch8_Pin = LATA.1     ' Pin 18 - Channel 8 switch output

and this is my initialisation code:
Proc Initialise()
    ' 8MHz internal oscillator (HFINTOSC)
    OSCCON = %01100000  ' HFINTOSC
    OSCFRQ = %00000011   ' 8 MHz

    ' Configure analog/digital
    ANSELA = 0  ' All digital
    ANSELB = 0
    ANSELC = 0
    ADCON0 = 0

    INLVLA = %11111111  ' Set all to ST (Schmitt Trigger)
    INLVLB = %11111111
    INLVLC = %11111111

     ' Disable other peripherals that might claim pins
    SSP1CON1 = 0   ' Disable I2C/SPI
    RC1STA = 0     ' Disable UART Receive
    TX1STA = 0     ' Disable UART Transmit

    ' Disable all peripheral outputs via PPS
    RA0PPS = 0
    RA1PPS = 0
    RA2PPS = 0
    RA4PPS = 0
    RA5PPS = 0
    RB4PPS = 0
    RB5PPS = 0
    RB6PPS = 0
    RB7PPS = 0
    RC0PPS = 0
    RC1PPS = 0
    RC2PPS = 0
    RC3PPS = 0
    RC4PPS = 0
    RC5PPS = 0
    RC6PPS = 0
    RC7PPS = 0

    RXPPS = 0
    CKPPS = 0
    T1GPPS = 0

    ' Configure weak pull-ups
    WPUA = %00110000  ' RA4, RA5 (Ch7, Ch8)
    WPUB = %10000000  ' RB7 (Ch1)
    WPUC = %11111000  ' RC3-RC7 (Ch2-Ch6)

    ' Configure I/O directions
    TRISA = %00110000  ' RA4, RA5 inputs
    TRISB = %10000000  ' RB7 input
    TRISC = %11111000  ' RC3-RC7 inputs

    DelayMS 10  ' Allow pins to settle

    ' Disable interrupts
    INTCON = 0   
    PIE0 = 0
    PIE1 = 0
    PIE2 = 0

    ' Timer1 setup
    T1CON = %11110101  ' TMR1ON=1, prescaler 1:8, Fosc/4
    T1GCON = 0

    ' IOC setup for PORTA (RA4, RA5)
    IOCAP.4 = 1
    IOCAN.4 = 1
    IOCAP.5 = 1
    IOCAN.5 = 1

    ' IOC setup for PORTB (RB7)
    IOCBP.7 = 1
    IOCBN.7 = 1

    ' IOC setup for PORTC (RC3-RC7)
    IOCCP.3 = 1
    IOCCN.3 = 1
    IOCCP.4 = 1
    IOCCN.4 = 1
    IOCCP.5 = 1
    IOCCN.5 = 1
    IOCCP.6 = 1
    IOCCN.6 = 1
    IOCCP.7 = 1
    IOCCN.7 = 1

    IOCAF = 0
    IOCBF = 0
    IOCCF = 0

    PIR0 = 0
    PIR1 = 0
    PIR2 = 0

'variable initialisation
......

    ' Enable IOC interrupt
    PIE0.4 = 1  ' IOCIE
EndProc

I am finding I cannot read Ports A or B.  e.g. if I put a pulse on PORTB.7 or PORTA.5 and echo that to PORTA.0 (which has an LED attached to it) the led is full on.  If I put a pulse on PORTC.7 the LED flashes and putting a scope on the LED pin I am getting 1 mS pulses reflecting  the input.

Finally these are my config settings:
'-------------------------------------------------------------------------------
'**** Added by Fuse Configurator ****
' Use the Fuses Tab to change these settings

Config1 FEXTOSC_OFF, RSTOSC_HFINTOSC_32MHZ, CLKOUTEN_OFF, VDDAR_HI
Config2 MCLRE_EXTMCLR, PWRTS_PWRT_OFF, WDTE_OFF, BOREN_OFF, BORV_LO, PPS1WAY_ON, STVREN_ON
Config4 BBSIZE_BB512, BBEN_OFF, SAFEN_OFF, WRTAPP_OFF, WRTB_OFF, WRTC_OFF, WRTSAF_OFF, LVP_OFF
Config5 CP_OFF

'**** End of Fuse Configurator Settings ****

Any suggestions as to where I am goiong wrong?
JohnB

GDeSantis

Please confirm the device part number and I cannot find PIC16F12544 on the Microchip website.

JohnB

appolgies my tendency to swap numbers around is really annoting it should read pic 16F15244
JohnB

top204

#3
I do the same John, but I guessed it was a PIC16F15244 device, so I created the code template below for you to test the input and output pins, without using IOC yet. The USART will not be enabled until it is set up, so at power-up, the pins are digital I/O.

'
' Test Pins for digital Input and Output on a PIC16F15244 device.
'
    Device = 16F15244                                       ' Tell the compiler what device to compile for
    Declare Xtal = 32                                       ' Tell the compiler what frequency the device is operating at (in MHz)
'
' Pin assignments - Inputs (Left side - all with IOC)
'
    Symbol RC_Ch1_Pin = PORTB.7                             ' Pin 10 - RC Channel 1 PWM input
    Symbol RC_Ch2_Pin = PORTC.7                             ' Pin 9  - RC Channel 2 PWM input
    Symbol RC_Ch3_Pin = PORTC.6                             ' Pin 8  - RC Channel 3 PWM input
    Symbol RC_Ch4_Pin = PORTC.3                             ' Pin 7  - RC Channel 4 PWM input
    Symbol RC_Ch5_Pin = PORTC.4                             ' Pin 6  - RC Channel 5 PWM input
    Symbol RC_Ch6_Pin = PORTC.5                             ' Pin 5  - RC Channel 6 PWM input
    Symbol RC_Ch7_Pin = PORTA.4                             ' Pin 3  - RC Channel 7 PWM input
    Symbol RC_Ch8_Pin = PORTA.5                             ' Pin 2  - RC Channel 8 PWM input
'
' Pin assignments - Outputs (Right side)
'
    Symbol LED_Pin = LATA.0                                 ' Pin 19 - Status LED  Active Low
    Symbol Switch1_Pin = LATB.6                             ' Pin 11 - Channel 1 switch output
    Symbol Switch2_Pin = LATB.5                             ' Pin 12 - Channel 2 switch output
    Symbol Switch4_Pin = LATB.4                             ' Pin 13 - Channel 3 switch output
    Symbol Switch3_Pin = LATC.2                             ' Pin 14 - Channel 4 switch output
    Symbol Switch5_Pin = LATC.1                             ' Pin 15 - Channel 5 switch output
    Symbol Switch6_Pin = LATC.0                             ' Pin 16 - Channel 6 switch output
    Symbol Switch7_Pin = LATA.2                             ' Pin 17 - Channel 7 switch output
    Symbol Switch8_Pin = LATA.1                             ' Pin 18 - Channel 8 switch output

'-----------------------------------------------------------------------------------------
' The main program starts here
' Transfer the state of the input pins to the output pins to see if they are acting correctly as digital inputs and outputs
'
Main:
    Setup()                                                 ' Setup the program and any peripherals

    Do                                                      ' Create a loop
        Switch1_Pin = RC_Ch1_Pin                            ' \
        Switch2_Pin = RC_Ch2_Pin                            ' |
        Switch3_Pin = RC_Ch3_Pin                            ' |
        Switch4_Pin = RC_Ch4_Pin                            ' | Transfer the state of the input pins to the output pins
        Switch5_Pin = RC_Ch5_Pin                            ' |
        Switch6_Pin = RC_Ch6_Pin                            ' |
        Switch7_Pin = RC_Ch7_Pin                            ' |
        Switch8_Pin = RC_Ch8_Pin                            ' /
        DelayMs 100                                         ' A small delay for debounce
    Loop                                                    ' Do it forever

'-----------------------------------------------------------------------------------------
' Setup the program and any peripherals
' Input     : None
' Output    : None
' Notes     : None
'
Proc Setup()
    Osc_Int32MHz()                                          ' Setup the device's internal oscillator to operate at 32MHz

    PinMode(RC_Ch1_Pin, Input_Pullup)                       ' Pin 10 - RC Channel 1 PWM input, with internal pull-up resistor enabled
    PinMode(RC_Ch2_Pin, Input_Pullup)                       ' Pin 9  - RC Channel 2 PWM input, with internal pull-up resistor enabled
    PinMode(RC_Ch3_Pin, Input_Pullup)                       ' Pin 8  - RC Channel 3 PWM input, with internal pull-up resistor enabled
    PinMode(RC_Ch4_Pin, Input_Pullup)                       ' Pin 7  - RC Channel 4 PWM input, with internal pull-up resistor enabled
    PinMode(RC_Ch5_Pin, Input_Pullup)                       ' Pin 6  - RC Channel 5 PWM input, with internal pull-up resistor enabled
    PinMode(RC_Ch6_Pin, Input_Pullup)                       ' Pin 5  - RC Channel 6 PWM input, with internal pull-up resistor enabled
    PinMode(RC_Ch7_Pin, Input_Pullup)                       ' Pin 3  - RC Channel 7 PWM input, with internal pull-up resistor enabled
    PinMode(RC_Ch8_Pin, Input_Pullup)                       ' Pin 2  - RC Channel 8 PWM input, with internal pull-up resistor enabled
'
' Pin assignments - Outputs (Right side)
'
    PinHigh LED_Pin                                         ' Pin 19 - Status LED (Active Low)
    PinLow Switch1_Pin                                      ' Pin 11 - Channel 1 switch output low
    PinLow Switch2_Pin                                      ' Pin 12 - Channel 2 switch output low
    PinLow Switch4_Pin                                      ' Pin 13 - Channel 3 switch output low
    PinLow Switch3_Pin                                      ' Pin 14 - Channel 4 switch output low
    PinLow Switch5_Pin                                      ' Pin 15 - Channel 5 switch output low
    PinLow Switch6_Pin                                      ' Pin 16 - Channel 6 switch output low
    PinLow Switch7_Pin                                      ' Pin 17 - Channel 7 switch output low
    PinLow Switch8_Pin                                      ' Pin 18 - Channel 8 switch output low
EndProc

'-----------------------------------------------------------------------------------------
' Setup the device's internal oscillator to operate at 32MHz
' Input     : None
' Output    : None
' Notes     : For a PIC16F15244 device
'
Proc Osc_Int32MHz()
    OSCEN = $00
    OSCFRQ = $05                                            ' FRQ is 32MHz
    OSCTUNE = $00
EndProc

'-----------------------------------------------------------------------------------------
' Setup the config fuses for internal oscillator on a PIC16F15244 device.
' With the OSC pins set as I/O pins.
'
    Config1 FEXTOSC_OFF,_                                   ' External Oscillator not enabled
            RSTOSC_HFINTOSC_32MHZ,_                         ' Power-up Default is HFINTOSC at 32MHz
            CLKOUTEN_OFF,_                                  ' CLKOUT function is disabled. I/O function on RA4
            VDDAR_HI                                        ' Internal analogue systems are calibrated for operation between VDD = 2.3V to 5.5V

    Config2 MCLRE_EXTMCLR,_                                 ' If LVP = 0, MCLR pin is MCLR. If LVP = 1, RA3 pin function is MCLR
            PWRTS_PWRT_OFF,_                                ' Power-Up Timer is disabled
            WDTE_OFF,_                                      ' Watchdog Timer 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 cleared and set multiple times
            STVREN_ON                                       ' Stack Overflow or Underflow will cause a reset

    Config4 BBSIZE_BB512,_                                  ' Boot Block Size is 512 words
            BBEN_OFF,_                                      ' Boot Block is disabled
            SAFEN_OFF,_                                     ' Storage Area Flash 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   

Try the code above, and the outputs should respond to the input states, and with the internal pull-up resistors enabled in Setup(), they will default to high. If not, there is a peripheral in the device that is not acting as it should when powered-up. I do not have a PIC16F15244 device, so the code listing above is written as an educated guess with data from the device's datasheet.

If it operates correctly, then add the IOC step by step (pin by pin), because you will know that the pins are operating as they should be. However, I noticed in your code listing that you had the IOC set for any state to trigger it. Was that deliberate, so that any state will cause an IOC trigger?

Note that the compiler sets the pins to digital and disables standard peripherals etc, before a user's program starts, so there is no need to add them to your code. See the BASIC code block at the end of a device's .def file:

'-----------------------------------------------------------------------------------
' 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

Regards
Les

JohnB

#4
Thanks Les.

I have tried that.
I have 2 real pullups on RB7 and RC7 but all the other input pins have no connection.
The input pins all measure low except RB7 and RC7
The output pins are all low except RB5 and RC2

Forcing inputs high does not change the state of the corresponding outout pin.

I thought I had a duff device initially so I replaced it but the results are the same.

PS: Les, I'm happy to send you a couple of PIC16F15244 for testing.  They are surface mount but I know that is not normally an issue for you.
JohnB