News:

;) This forum is the property of Proton software developers

Main Menu

Port Configuration on PIC16F15244

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

top204

QuoteLes, 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.

Yes please John. I've had a look, and I do not have one of those devices, or one of its close relatives. So it would be very interesting to find out what is going on in the device to stop digital pins operating.

Best regards
Les

JohnB

They will be in the post Monday morning.
JohnB

top204

#7
Hello John

The devices arrived, and I have one placed on a breadboard, and it is working as expected with standard digital input and output. Using the code listing below:

'
'  /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\    \/\\\                                                /\\\          /\\\
'  \/\\\\\\\\\\\/        /\\\\\    /\\\\\\\\\\    /\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'    \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\    \/\\\        \/\\\        /\\\\\\\\\\
'      \/\\\    \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\    \/\\\ /\\  /\\\/////\\\
'      \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\  \//\\\\\\\\/\\
'        \///        \///    \/////    \//////////    \//////////      \/////        \/////    \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Test Pins for digital Input and Output on a PIC16F15244 device.
' An output pin will be set high when its matching input pin is brought low.
'
' Written by Les Johnson for the Positron8 BASIC Compiler.
'
    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)
    Declare Auto_Variable_Bank_Cross = On                  ' Make sure all multi-byte variables remain within a single RAM bank (for extra efficiency)
'
' Pin assignments - Inputs (Left side of device)
'
$define RC_Ch1_In_Pin PORTB.7                              ' Pin 10 - Channel 1 (input)
$define RC_Ch2_In_Pin PORTC.7                              ' Pin 9  - Channel 2 (input)
$define RC_Ch3_In_Pin PORTC.6                              ' Pin 8  - Channel 3 (input)
$define RC_Ch4_In_Pin PORTC.3                              ' Pin 7  - Channel 4 (input)
$define RC_Ch5_In_Pin PORTC.4                              ' Pin 6  - Channel 5 (input)
$define RC_Ch6_In_Pin PORTC.5                              ' Pin 5  - Channel 6 (input)
$define RC_Ch7_In_Pin PORTA.4                              ' Pin 3  - Channel 7 (input)
$define RC_Ch8_In_Pin PORTA.5                              ' Pin 2  - Channel 8 (input)
'
' Pin assignments - Outputs (Right side of device)
'
$define Switch1_Out_Pin LATB.6                              ' Pin 11 - Channel 1 switch (output)
$define Switch2_Out_Pin LATB.5                              ' Pin 12 - Channel 2 switch (output)
$define Switch3_Out_Pin LATC.2                              ' Pin 14 - Channel 4 switch (output)
$define Switch4_Out_Pin LATB.4                              ' Pin 13 - Channel 3 switch (output)
$define Switch5_Out_Pin LATC.1                              ' Pin 15 - Channel 5 switch (output)
$define Switch6_Out_Pin LATC.0                              ' Pin 16 - Channel 6 switch (output)
$define Switch7_Out_Pin LATA.2                              ' Pin 17 - Channel 7 switch (output)
$define Switch8_Out_Pin LATA.1                              ' Pin 18 - Channel 8 switch (output)

$define LED_Pin LATA.0                                      ' Pin 19 - Status LED

'-----------------------------------------------------------------------------------------
' The main program starts here
' Transfer the state of the input pins to the output pins.
' An output pin will be set high when its matching input pin is brought low.
'
Main:
    Setup()                                                ' Setup the program and any peripherals

    Do                                                      ' Create a loop
        Switch1_Out_Pin = ~RC_Ch1_In_Pin                    ' \
        Switch2_Out_Pin = ~RC_Ch2_In_Pin                    ' |
        Switch3_Out_Pin = ~RC_Ch3_In_Pin                    ' |
        Switch4_Out_Pin = ~RC_Ch4_In_Pin                    ' | Transfer the inverse state of the input pins to the output pins
        Switch5_Out_Pin = ~RC_Ch5_In_Pin                    ' |
        Switch6_Out_Pin = ~RC_Ch6_In_Pin                    ' |
        Switch7_Out_Pin = ~RC_Ch7_In_Pin                    ' |
        Switch8_Out_Pin = ~RC_Ch8_In_Pin                    ' /
    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_In_Pin, Input_PullUp)                    ' Set Channel 1 pin as input, with internal pull-up resistor enabled
    PinMode(RC_Ch2_In_Pin, Input_PullUp)                    ' Set Channel 2 pin as input, with internal pull-up resistor enabled
    PinMode(RC_Ch3_In_Pin, Input_PullUp)                    ' Set Channel 3 pin as nput, with internal pull-up resistor enabled
    PinMode(RC_Ch4_In_Pin, Input_PullUp)                    ' Set Channel 4 pin as input, with internal pull-up resistor enabled
    PinMode(RC_Ch5_In_Pin, Input_PullUp)                    ' Set Channel 5 pin as input, with internal pull-up resistor enabled
    PinMode(RC_Ch6_In_Pin, Input_PullUp)                    ' Set Channel 6 pin as input, with internal pull-up resistor enabled
    PinMode(RC_Ch7_In_Pin, Input_PullUp)                    ' Set Channel 7 pin as input, with internal pull-up resistor enabled
    PinMode(RC_Ch8_In_Pin, Input_PullUp)                    ' Set Channel 8 pin as input, with internal pull-up resistor enabled

    PinLow LED_Pin                                          ' Set Status LED pin as an output low
    PinLow Switch1_Out_Pin                                  ' Set Channel 1 pin as an output low
    PinLow Switch2_Out_Pin                                  ' Set Channel 2 pin as an output low
    PinLow Switch4_Out_Pin                                  ' Set Channel 3 pin as an output low
    PinLow Switch3_Out_Pin                                  ' Set Channel 4 pin as an output low
    PinLow Switch5_Out_Pin                                  ' Set Channel 5 pin as an output low
    PinLow Switch6_Out_Pin                                  ' Set Channel 6 pin as an output low
    PinLow Switch7_Out_Pin                                  ' Set Channel 7 pin as an output low
    PinLow Switch8_Out_Pin                                  ' Set Channel 8 pin as an 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 (32 MHz)
            CLKOUTEN_OFF,_                                  ' CLKOUT function is disabled. I/O function on RA4
            VDDAR_HI                                        ' Internal analogue 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,_                                ' Power-up Timer 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 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,_                                    ' 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

When one of the input pins is brought low, its relevant output pin is set high, and illuminates an LED, and remain low or high until the connections are made or broken. So they are operating as standard digital I/O pins.

I'll alter each pin to act with IOC, and test them using another program I will create, based upon the code listing above. Making IOC alter by any state, as you have in your code, may cause problems, because they will always toggle on any jitter etc. So with IOC, it is better, in my opinion, to set a state for it to trigger, then once it has triggered, the state can be changed to suit another trigger if required, by using the interrupt to detact a trigger, then changing to the new required state before exiting, and clearing flags.

Regards
Les

JohnB

#8
Thanks, but sadly it doesnt work on my board. 

With the input pullups enabled I would expect to see highs on all inputs. All are low with the exception of RB7 and RC7 which are high because I have external pullups on them.  I am going to try with a new board and only the PIC installed and see what I get.

Good idea on enabling IOC only in the direction in the context of the current state. I will add that to my interrupt code when I get ths wrecthed board to work.

I have a dual port board running well using the same IOC system perfectly happily.
JohnB

top204

#9
Try the loop below in the 'Main' section of the code:

Main:
    Setup()                                                 ' Setup the program and any peripherals  
    Do                                                      ' Create a loop
        Switch1_Out_Pin = ~Switch1_Out_Pin                  ' \
        Switch2_Out_Pin = ~Switch2_Out_Pin                  ' |
        Switch3_Out_Pin = ~Switch3_Out_Pin                  ' |
        Switch4_Out_Pin = ~Switch4_Out_Pin                  ' | Toggle the state of all of the output pins
        Switch5_Out_Pin = ~Switch5_Out_Pin                  ' |
        Switch6_Out_Pin = ~Switch6_Out_Pin                  ' |
        Switch7_Out_Pin = ~Switch7_Out_Pin                  ' |                    
        Switch8_Out_Pin = ~Switch8_Out_Pin                  ' /
        DelayMs 500                                         ' Delay for half a second
    Loop                                                    ' Do it forever

This will toggle all the output pins every half a second, and if you connect LEDs to them, you should see them all illuminate then extinguish. If not, then there is something not right on your board. I have it working now, as I type, and they are all flashing. Sometimes in life, there is nothing better than a flashing LED. :-)

Then when I place the code:

    Do                                                      ' Create a loop
        Switch1_Out_Pin = ~RC_Ch1_In_Pin                    ' \
        Switch2_Out_Pin = ~RC_Ch2_In_Pin                    ' |
        Switch3_Out_Pin = ~RC_Ch3_In_Pin                    ' |
        Switch4_Out_Pin = ~RC_Ch4_In_Pin                    ' | Transfer the inverse state of the input pins to the output pins
        Switch5_Out_Pin = ~RC_Ch5_In_Pin                    ' |
        Switch6_Out_Pin = ~RC_Ch6_In_Pin                    ' |
        Switch7_Out_Pin = ~RC_Ch7_In_Pin                    ' |
        Switch8_Out_Pin = ~RC_Ch8_In_Pin                    ' /
    Loop                                                    ' Do it forever

The relevant LED illuminates when its input is connected to ground.

I did have to swap two output pins used to get them sequential on the device. So the pin defines are now:

$define Switch1_Out_Pin LATB.6                              ' Pin 11 - Channel 1 switch (output)
$define Switch2_Out_Pin LATB.5                              ' Pin 12 - Channel 2 switch (output)
$define Switch3_Out_Pin LATB.4                              ' Pin 13 - Channel 3 switch (output)
$define Switch4_Out_Pin LATC.2                              ' Pin 14 - Channel 4 switch (output) (swapped)
$define Switch5_Out_Pin LATC.1                              ' Pin 15 - Channel 5 switch (output) (swapped)
$define Switch6_Out_Pin LATC.0                              ' Pin 16 - Channel 6 switch (output)
$define Switch7_Out_Pin LATA.2                              ' Pin 17 - Channel 7 switch (output)
$define Switch8_Out_Pin LATA.1                              ' Pin 18 - Channel 8 switch (output)

Regards
Les

JohnB

#10
The outputs are all toggling correctly but the input lines are still all low, I assume they should measure high after the progamm has initalised.  Will try on a breadboard next.

Now tried on Jig I use for programing.  I am still seeing the input lines as low.  I am programming it using the PICKit3   with Venns PICkit3+ UI program.  Could that explain what I am seeing?

SUCCESS - Just updated to the latest compiler ( I was only 1 behind I think) and it now all works.
JohnB

top204

I've just compiled the code listing I posted with an older compiler version. i.e. Version 4.0.5.6, and they still work as expected on the breadboard.

A pin that is made an input will not be free from resistance, because the device has internal components on them, and I have had inputs cause loads when they are joined in parallel with other devices. However, they are not large loads.

Pull-down resistors will cause a lower resistance, but a pin left floating will not be too low. One way of easing this is to make the high, then immediately set it to an input. Or make it low, then immediately set it to an input, if the reverse is required. This will jiggle the internal components and can ease some problems with external peripherals, especially sleep currents.

Regards
Les

JohnB

Just to say I now have my full code working including alternating IOC polarity.  Thanks for you help.
JohnB