Hot!18F14K50 - Help needed for PORTC management

Author
PJC
New Member
  • Total Posts : 8
  • Reward points : 0
  • Joined: 2016/09/18 00:43:56
  • Location: 0
  • Status: offline
2018/06/12 13:31:26 (permalink)
0

18F14K50 - Help needed for PORTC management

Hi everybody,
i'm struggling with what i think is a "basic" problem but i can't find the solution.
I try to use a simple 8 bits databus using PORTC of a 18F14K50.
I wrote a simple program cycling on writing 0x00,0x01,0x02 .... 0x80 to check with an oscilloscope each bit going from 0 to 1 (each port line is loaded with a 1k resistor).
I first had a problem with RC3 but a found the solution by setting "CONFIG LVP=OFF"
Then i'm still stuck on RC2 : on all other pins I can see voltage nicely going from 0 to Vcc (i.e. 3.3v) but on RC2 the signal merly goes to approximately 0.5v !!!! Maybe RC2 is not corrected configurated as an output or does not provide enough current but 1k is quite a high value.
I tried with a second chip but got the same result so there should not be an hardware issue.
Searching through the Internet I found a lot or recommandation for register initialisation. Below is my actual code 
 
   PORTC = 0b00000000; /* clear PORTC output pins (0v) */
   //TRISA = 0b00000110; /* All PORTA I/O set as Output except RA1 et 2 as Inputs */
   //TRISB = 0b00000000; /* All PORTB I/O set as Output */
   TRISC = 0b00000000; /* All PORTC I/O set as Output */
   SSPCON1 = 0;
   CCP1CON = 0;
   T3CON = 0;
   T1CON = 0;
   PSTRCON = 1;
   REFCON1 = 0;
   INTCON = 0;
   INTCON2 = 0;
   INTCON3 = 0;
 
I have no more idea for the moment.
 
Any help would be appreciated.
 
Best regards
#1

15 Replies Related Threads

    katela
    Super Member
    • Total Posts : 921
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: offline
    Re: 18F14K50 - Help needed for PORTC management 2018/06/12 16:19:56 (permalink)
    +1 (1)
    Try to use LATC instead of PORTC for output.
     

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/user/StudentCompanionSA
    #2
    qɥb
    Monolothic Member
    • Total Posts : 3329
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: 18F14K50 - Help needed for PORTC management 2018/06/12 16:33:16 (permalink)
    +2 (2)
    It's a good habit to only write to LATC rather than PORTC, but it doesn't really matter when you write the entire port in one instruction.
     
    PJC
    ...
    Below is my actual code 
    ...

    No it's not.
    That is just a small section of your main C file. There's no config setting or include statements.
    Please post the ENTIRE test file.
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #3
    PJC
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2016/09/18 00:43:56
    • Location: 0
    • Status: offline
    Re: 18F14K50 - Help needed for PORTC management 2018/06/12 22:51:19 (permalink)
    0
    Hi, thank you for your support. You're right it was just an extract of the code. 
    Below is the entire code (without all comments)
    Best regards
    -----------------------------------------
    #pragma config CPUDIV = NOCLKDIV// CPU System Clock Selection bits (No CPU System Clock divide)
    #pragma config USBDIV = OFF // USB Clock Selection bit (USB clock comes directly from the OSC1/OSC2 oscillator block; no divide)
    #pragma config FOSC = IRC // Oscillator Selection bits (Internal RC oscillator)
    #pragma config PLLEN = OFF // 4 X PLL Enable bit (PLL is under software control)
    #pragma config PCLKEN = ON // Primary Clock Enable bit (Primary clock enabled)
    #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor disabled)
    #pragma config IESO = OFF // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)
    #pragma config PWRTEN = OFF // Power-up Timer Enable bit (PWRT disabled)
    #pragma config BOREN = SBORDIS // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
    #pragma config BORV = 19 // Brown-out Reset Voltage bits (VBOR set to 1.9 V nominal)
    #pragma config WDTEN = ON // Watchdog Timer Enable bit (WDT is always enabled. SWDTEN bit has no effect.)
    #pragma config WDTPS = 32768 // Watchdog Timer Postscale Select bits (1:32768)
    #pragma config HFOFST = ON // HFINTOSC Fast Start-up bit (HFINTOSC starts clocking the CPU without waiting for the oscillator to stablize.)
    #pragma config MCLRE = ON // MCLR Pin Enable bit (MCLR pin enabled; RA3 input pin disabled)
    #pragma config STVREN = ON // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
    #pragma config LVP = OFF // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled)
    #pragma config BBSIZ = OFF // Boot Block Size Select bit (1kW boot block size)
    #pragma config XINST = OFF // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))
    #pragma config CP0 = OFF // Code Protection bit (Block 0 not code-protected)
    #pragma config CP1 = OFF // Code Protection bit (Block 1 not code-protected)
    #pragma config CPB = OFF // Boot Block Code Protection bit (Boot block not code-protected)
    #pragma config CPD = OFF // Data EEPROM Code Protection bit (Data EEPROM not code-protected)
    #pragma config WRT0 = OFF // Table Write Protection bit (Block 0 not write-protected)
    #pragma config WRT1 = OFF // Table Write Protection bit (Block 1 not write-protected)
    #pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration registers not write-protected)
    #pragma config WRTB = OFF // Boot Block Write Protection bit (Boot block not write-protected)
    #pragma config WRTD = OFF // Data EEPROM Write Protection bit (Data EEPROM not write-protected)
    #pragma config EBTR0 = OFF // Table Read Protection bit (Block 0 not protected from table reads executed in other blocks)
    #pragma config EBTR1 = OFF // Table Read Protection bit (Block 1 not protected from table reads executed in other blocks)
    #pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot block not protected from table reads executed in other blocks)


    #include <xc.h>
    #include <stdlib.h>
    #include <stdint.h>
    #include <stddef.h>
    #include "Routines_OLED.h"
    #define OSC 4 /* tells PBP we use a 8 MHZ clock */
    #define _XTAL_FREQ 4000000 //required for _delay() function
    void main()
    {
    OSCCONbits.IRCF=5;
    PORTC = 0b00000000; /* clear PORTC output pins (0v) */
    TRISC = 0b00000000; /* All PORTC I/O set as Output */
    SSPCON1 = 0;
    CCP1CON = 0;
    T3CON = 0;
    T1CON = 0;
    PSTRCON = 1;
    REFCON1 = 0;
    INTCON = 0;
    INTCON2 = 0;
    INTCON3 = 0;
    while (0==0)
    {
      Write_OLED_Command (0x00);
      __delay_ms(50);
      Write_OLED_Command (0x01);
      __delay_ms(50);
      Write_OLED_Command (0x02);
      __delay_ms(50);
      Write_OLED_Command (0x04);
      __delay_ms(50);
      Write_OLED_Command (0x08);
      __delay_ms(50);
      Write_OLED_Command (0x10);
      __delay_ms(50);
      Write_OLED_Command (0x20);
      __delay_ms(50);
      Write_OLED_Command (0x40);
      __delay_ms(50);
      Write_OLED_Command (0x80);
      __delay_ms(50);
    }
    }
    ----------------------------
    void Write_OLED_Command (uint8_t value)
    {
    DC_LOW(); /* RS = 0 COMMAND */
    RW_LOW(); /* RW = 0 WRITE */
    LATC = value;
    ENABLE();
    RW_HIGH(); /* RW = 1 READ */
    }
    ---------------------------------------
    void DC_LOW (void)
    {
    PORTBbits.RB4 = 0;
    }
    ----------------------------------------
    void RW_LOW (void)
    {
    PORTBbits.RB7 = 0;
    }
    ---------------------------------------
    void ENABLE (void)
    {
    PORTBbits.RB6 = 1;
    #asm
    //_asm
    nop;
    nop;
    //_endasm
    #endasm
    PORTBbits.RB6 = 0;
    }
    -------------------------------------
    void RW_HIGH (void)
    {
    PORTBbits.RB7 = 1;
    }
    #4
    PJC
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2016/09/18 00:43:56
    • Location: 0
    • Status: offline
    Re: 18F14K50 - Help needed for PORTC management 2018/06/12 22:53:09 (permalink)
    0
    Hi, thank you for your support.
    I do already use LATC. See below the final routine code writing to the PORTC
     
    void Write_OLED_Command (uint8_t value)
    {
    DC_LOW(); /* RS = 0 COMMAND */
    RW_LOW(); /* RW = 0 WRITE */
    LATC = value;
    ENABLE();
    RW_HIGH(); /* RW = 1 READ */
    }
    #5
    qɥb
    Monolothic Member
    • Total Posts : 3329
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: 18F14K50 - Help needed for PORTC management 2018/06/13 13:09:03 (permalink)
    +2 (2)
    Am still not sure what the problem is with RC2, but all your accesses to PORTB are wrong.
    Change every instance of PORTBbits to LATBbits.
    (e.g. PORTBbits.RB6 = 0; to LATBbits.LATB6=0;)
    That is where is DOES matter if you use the PORTx or the LATx register.
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #6
    jack@kksound
    code tags!
    • Total Posts : 2736
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: 18F14K50 - Help needed for PORTC management 2018/06/13 14:01:35 (permalink)
    +1 (1)
    I tried with a second chip but got the same result so there should not be an hardware issue.

    You should check for a wiring error on that pin.
    #7
    1and0
    Access is Denied
    • Total Posts : 8337
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: 18F14K50 - Help needed for PORTC management 2018/06/13 14:17:09 (permalink)
    0
    Take a look to Table 9-14: PORTC I/O SUMMARY. RC2 is shared with AN6, comparator input, voltage reference output, PWM output; so make sure all these are disabled or turned off. 
     
    Notice that enabling voltage reference disables digital I/O and PWM output takes priority over port data.
     
    <edit> … which you did disable or is off by default.
    post edited by 1and0 - 2018/06/13 14:37:43
    #8
    1and0
    Access is Denied
    • Total Posts : 8337
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: 18F14K50 - Help needed for PORTC management 2018/06/13 14:42:32 (permalink)
    +2 (2)
    I don't see TRISB being set to output.
    #9
    PJC
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2016/09/18 00:43:56
    • Location: 0
    • Status: offline
    Re: 18F14K50 - Help needed for PORTC management 2018/06/14 11:49:56 (permalink)
    0
    You're right, I will change that for PORTB but my initial issue on PORTC is still there
    Thank you
    #10
    PJC
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2016/09/18 00:43:56
    • Location: 0
    • Status: offline
    Re: 18F14K50 - Help needed for PORTC management 2018/06/14 11:55:19 (permalink)
    0
    Thank you.
     
    I will have a second look to my breadboard.
     
    #11
    1and0
    Access is Denied
    • Total Posts : 8337
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: 18F14K50 - Help needed for PORTC management 2018/06/14 12:01:22 (permalink)
    0
    Your code looks okay regarding RC2. Have you tried what Jack said in Post #7?
     
    #12
    PJC
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2016/09/18 00:43:56
    • Location: 0
    • Status: offline
    Re: 18F14K50 - Help needed for PORTC management 2018/06/14 12:02:29 (permalink)
    0
    Yes i think i have disable all alternate functions. Thank you
     
    #13
    PJC
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2016/09/18 00:43:56
    • Location: 0
    • Status: offline
    Re: 18F14K50 - Help needed for PORTC management 2018/06/14 12:10:05 (permalink)
    +1 (1)
    I have a TRISB=0 in my code by i forget to copy it in my copy / paste operation
    Thank you
     
    #14
    PJC
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2016/09/18 00:43:56
    • Location: 0
    • Status: offline
    Re: 18F14K50 - Help needed for PORTC management 2018/06/14 12:56:28 (permalink)
    +2 (2)
    Hi everyone
     
    following Jack's advice, I checked the wiring and my breadboard. I saw an issue (resistor pin badly connected). Fixing it, PORTC (and especially RC2) works well ! So it was not a configuration issue.
     
    Thank you for your support.
    #15
    jack@kksound
    code tags!
    • Total Posts : 2736
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: 18F14K50 - Help needed for PORTC management 2018/06/14 15:19:09 (permalink)
    0
    Smile: Smile
    #16
    Jump to:
    © 2018 APG vNext Commercial Version 4.5