porta.0 and porta.2 only goes high with HIGH command with PIC18F45K80


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2014
    Posts
    12

    Default porta.0 and porta.2 only goes high with HIGH command with PIC18F45K80

    Hi.

    I have a problem that if I set porta.0 and portb.2 high with porta.0=1 and porta.2=1 then they will not go high, but if I do HIGH porta.0 and HIGH porta.2 then they will.
    porta.1 and porta.3 works as expected.
    Anyone know why?

    In the display the code below gives me:
    00001111
    HIGH

    00000000
    LOW

    00001010
    =1

    00000000
    =0


    Code:
    ' PIC18F45K80 Configuration Bit Settings
    
    
    #CONFIG
        CONFIG RETEN = OFF
        CONFIG INTOSCSEL = HIGH
        CONFIG SOSCSEL = DIG
        CONFIG XINST = OFF
        CONFIG FOSC = EC3
        CONFIG PLLCFG = OFF
        CONFIG FCMEN = OFF
        CONFIG IESO = OFF
        CONFIG PWRTEN = ON
        CONFIG BOREN = OFF
        CONFIG BORV = 3
        CONFIG BORPWR = ZPBORMV
        CONFIG WDTEN = OFF
        CONFIG WDTPS = 1048576
        CONFIG CANMX = PORTB
        CONFIG MSSPMSK = MSK7
        CONFIG MCLRE = ON
        CONFIG STVREN = OFF
        CONFIG BBSIZ = BB2K
        CONFIG CP0 = OFF
        CONFIG CP1 = OFF
        CONFIG CP2 = OFF
        CONFIG CP3 = OFF
        CONFIG CPB = OFF
        CONFIG CPD = OFF
        CONFIG WRT0 = OFF
        CONFIG WRT1 = OFF
        CONFIG WRT2 = OFF
        CONFIG WRT3 = OFF
        CONFIG WRTC = OFF
        CONFIG WRTB = OFF
        CONFIG WRTD = OFF
        CONFIG EBTR0 = OFF
        CONFIG EBTR1 = OFF
        CONFIG EBTR2 = OFF
        CONFIG EBTR3 = OFF
        CONFIG EBTRB = OFF
    #ENDCONFIG
    
    
    
    
    '************************* DEFINES ******************************
    define OSC 64
    
    
    define LCD_DREG PORTC
    define LCD_DBIT 0
    define LCD_RSREG PORTC
    define LCE_RSBIT 4
    define LCD_EREG PORTC
    define LCD_EBIT 5
    define LCD_BITS 4
    define LCD_LINES 2
    define LCD_COMMANDUS 3000
    define LCD_DATAUS 100
    
    
    
    
    '********************** PIN VARIABLES ***************************
    
    
    
    
    '************************ VARIABLES *****************************
    
    
    
    
    '************************ REGISTERS *****************************
    ANCON0 = 000000
    ANCON1 = 000000
    ADCON0 = 000000
    ADCON1 = 000000
    
    
    
    
    '*********************** PORT CONFIG ****************************
    TRISA = 100000                                   'porta direction 0=OUTPUT 1=INPUT
    PORTA = 000000                                   'porta preset
    TRISB = 010111                                   'portb direction 0=OUTPUT 1=INPUT
    PORTB = 000000                                   'portb preset
    TRISC = 000000                                   'portc direction 0=OUTPUT 1=INPUT
    PORTC = 000000                                   'portc preset
    TRISD = 111111                                   'portd direction 0=OUTPUT 1=INPUT
    PORTD = 110000                                   'portd preset
    TRISE = 001111                                   'porte direction 0=OUTPUT 1=INPUT
    PORTE = 000000                                   'porte preset
    
    
    
    
    '*********************** TIMER CONFIG ***************************
    
    
    
    
    '********************* INTERRUPT CONFIG *************************
    
    
    
    
    '****************************************************************
    '*******************    MAIN PROGRAM     ************************
    '****************************************************************
    pause 500
    lcdout $fe, $01                                     
    while 1
        high porta.0
        high porta.1
        high porta.2
        high porta.3
        lcdout $fe, $80, bin8 porta
        lcdout $fe, $c0, "HIGH"
        PAUSE 1000
        low porta.0
        low porta.1
        low porta.2
        low porta.3
        lcdout $fe, $80, bin8 porta
        lcdout $fe, $c0, "LOW "
        PAUSE 1000
        porta.0 = 1
        porta.1 = 1
        porta.2 = 1
        porta.3 = 1
        lcdout $fe, $80, bin8 porta
        lcdout $fe, $c0, "= 1 "
        PAUSE 1000
        porta.0 = 0
        porta.1 = 0
        porta.2 = 0
        porta.3 = 0
        lcdout $fe, $80, bin8 porta
        lcdout $fe, $c0, "= 0 "
        PAUSE 1000
    wend
    
    
    '****************************************************************
    '*******************     SUB ROUTINES      **********************
    '****************************************************************
    
    
    
    
    '****************************************************************
    '*****************     INTERRUPT ROUTINE     ********************
    '****************************************************************
    
    
    end

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: porta.0 and porta.2 only goes high with HIGH command with PIC18F45K80

    Bmoe79, I notice that you are only setting 6 of the 8 bits of each port as well as not setting up the statement as: PORTE = %00000000 The "%" has to proceed the binary representation of the bit values to be valid. I notice you do not use it in any of your statements for setting the TRIS or PORT values.
    Dave Purola,
    N8NTA
    EN82fn

  3. #3
    Join Date
    Dec 2014
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: porta.0 and porta.2 only goes high with HIGH command with PIC18F45K80

    How weird, in the code everything is ok so it must have happened when I pasted the code.
    Here is the code again

    Code:
    ' PIC18F45K80 Configuration Bit Settings
    
    
    #CONFIG
        CONFIG RETEN = OFF
        CONFIG INTOSCSEL = HIGH
        CONFIG SOSCSEL = DIG
        CONFIG XINST = OFF
        CONFIG FOSC = EC3
        CONFIG PLLCFG = OFF
        CONFIG FCMEN = OFF
        CONFIG IESO = OFF
        CONFIG PWRTEN = ON
        CONFIG BOREN = OFF
        CONFIG BORV = 3
        CONFIG BORPWR = ZPBORMV
        CONFIG WDTEN = OFF
        CONFIG WDTPS = 1048576
        CONFIG CANMX = PORTB
        CONFIG MSSPMSK = MSK7
        CONFIG MCLRE = ON
        CONFIG STVREN = OFF
        CONFIG BBSIZ = BB2K
        CONFIG CP0 = OFF
        CONFIG CP1 = OFF
        CONFIG CP2 = OFF
        CONFIG CP3 = OFF
        CONFIG CPB = OFF
        CONFIG CPD = OFF
        CONFIG WRT0 = OFF
        CONFIG WRT1 = OFF
        CONFIG WRT2 = OFF
        CONFIG WRT3 = OFF
        CONFIG WRTC = OFF
        CONFIG WRTB = OFF
        CONFIG WRTD = OFF
        CONFIG EBTR0 = OFF
        CONFIG EBTR1 = OFF
        CONFIG EBTR2 = OFF
        CONFIG EBTR3 = OFF
        CONFIG EBTRB = OFF
    #ENDCONFIG
    
    
    '************************* DEFINES ******************************
    define OSC 64
    
    
    define LCD_DREG PORTC
    define LCD_DBIT 0
    define LCD_RSREG PORTC
    define LCE_RSBIT 4
    define LCD_EREG PORTC
    define LCD_EBIT 5
    define LCD_BITS 4
    define LCD_LINES 2
    define LCD_COMMANDUS 3000
    define LCD_DATAUS 100
    
    
    '************************ REGISTERS *****************************
    ANCON0 = 000000
    ANCON1 = 000000
    ADCON0 = 000000
    ADCON1 = 000000
    
    
    '*********************** PORT CONFIG ****************************
    TRISA = 100000                                   'porta direction 0=OUTPUT 1=INPUT
    PORTA = 000000                                   'porta preset
    TRISB = 010111                                   'portb direction 0=OUTPUT 1=INPUT
    PORTB = 000000                                   'portb preset
    TRISC = 000000                                   'portc direction 0=OUTPUT 1=INPUT
    PORTC = 000000                                   'portc preset
    TRISD = 111111                                   'portd direction 0=OUTPUT 1=INPUT
    PORTD = 110000                                   'portd preset
    TRISE = 001111                                   'porte direction 0=OUTPUT 1=INPUT
    PORTE = 000000                                   'porte preset
    
    
    '****************************************************************
    '*******************    MAIN PROGRAM     ************************
    '****************************************************************
    pause 500
    lcdout $fe, $01                                     
    while 1
        high porta.0
        high porta.1
        high porta.2
        high porta.3
        lcdout $fe, $80, bin8 porta
        lcdout $fe, $c0, "HIGH"
        PAUSE 1000
        low porta.0
        low porta.1
        low porta.2
        low porta.3
        lcdout $fe, $80, bin8 porta
        lcdout $fe, $c0, "LOW "
        PAUSE 1000
        porta.0 = 1
        porta.1 = 1
        porta.2 = 1
        porta.3 = 1
        lcdout $fe, $80, bin8 porta
        lcdout $fe, $c0, "= 1 "
        PAUSE 1000
        porta.0 = 0
        porta.1 = 0
        porta.2 = 0
        porta.3 = 0
        lcdout $fe, $80, bin8 porta
        lcdout $fe, $c0, "= 0 "
        PAUSE 1000
    wend
    
    
    end
    Last edited by bmoe79; - 22nd January 2015 at 16:41.

  4. #4
    Join Date
    Dec 2014
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: porta.0 and porta.2 only goes high with HIGH command with PIC18F45K80

    Same thing again. So weird.
    TRISx, PORTx, ANCONx and ADCONx is like below in my code

    TRISA = %11100000 'porta direction 0=OUTPUT 1=INPUT
    PORTA = %00000000 'porta preset
    TRISB = %11010111 'portb direction 0=OUTPUT 1=INPUT
    PORTB = %00000000 'portb preset
    TRISC = %00000000 'portc direction 0=OUTPUT 1=INPUT
    PORTC = %00000000 'portc preset
    TRISD = %00111111 'portd direction 0=OUTPUT 1=INPUT
    PORTD = %00110000 'portd preset
    TRISE = %00001111 'porte direction 0=OUTPUT 1=INPUT
    PORTE = %00000000 'porte preset

    ANCON0 = %00000000
    ANCON1 = %00000000
    ADCON0 = %00000000
    ADCON1 = %00000000

  5. #5
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: porta.0 and porta.2 only goes high with HIGH command with PIC18F45K80

    This might be a read-modify-write issue.
    The 18FK4580 has Output Latch registers.
    You should try writing to the port via the LATA register instead of the PORTA register.
    Regards,
    TABSoft

  6. #6
    Join Date
    Dec 2014
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: porta.0 and porta.2 only goes high with HIGH command with PIC18F45K80

    After taking a quick look in the datasheet it seems like that coulld be it.
    I will test that tomorrow.
    Thanks.

  7. #7
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: porta.0 and porta.2 only goes high with HIGH command with PIC18F45K80

    You don't say what you've got hooked up to the port pins. Could you post a schematic?

  8. #8
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: porta.0 and porta.2 only goes high with HIGH command with PIC18F45K80

    Make sure to disable comparators & ECCP module. Using HIGH /LOW commands disables all analog (generally) for you. PICs default to Analog inputs and you have to be sure to turn it all off to get digital to work. And it makes sense too, analog inputs are incapable of causing any "unintended" actions downstream, like shorting something out or causing a machine to suddenly start running on power up. It is for THAT reason you should set your port states prior to assigning TRIS to outputs.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  9. #9
    Join Date
    Dec 2014
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: porta.0 and porta.2 only goes high with HIGH command with PIC18F45K80

    Setting the outputs with latx.x instead of portx.x solved the problem.
    Tanks.

  10. #10
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: porta.0 and porta.2 only goes high with HIGH command with PIC18F45K80

    Glad to hear this got you moving ahead.

    There are plenty of posts on this forum regarding read-modify-write as well as a straight internet search on the subject if you want to understand the issue better.
    Regards,
    TABSoft

Similar Threads

  1. PortA Doesn't Work
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 11
    Last Post: - 8th September 2015, 18:41
  2. Replies: 10
    Last Post: - 14th April 2014, 20:47
  3. high voltage high frequency H-Bridge
    By George in forum Off Topic
    Replies: 6
    Last Post: - 27th April 2009, 11:50
  4. AD works in Porta.0 but not in porta.1
    By ruijc in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 19th February 2008, 20:22
  5. turning gpio.0 high after pwm command
    By sirvo in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 21st February 2007, 18:22

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts