PortE problems (PIC18F4455)


Closed Thread
Results 1 to 16 of 16
  1. #1
    Join Date
    Mar 2005
    Posts
    15

    Default PortE problems (PIC18F4455)

    Hi there,

    If got a little problem (but strange to me). I'm trying to use portE of my pic18F4455. Now i'm using it as an input, but later I also want to use it as an output.

    The problem is that only pin RE3 look to work fine.

    Here the code I'm using:
    Code:
            Include "modedefs.bas" 
            
            DEFINE OSC 4
            E_0         VAR     WORD
            E_1         VAR     WORD
            E_2         VAR     WORD
            E_3         VAR     WORD
            TestLED     VAR     PORTC.6
            RS232TX     VAR     PORTD.2
           
    Intro:
        ADCON0 = 7
        ADCON1 = 7
        ADCON2 = 7
        CMCON  = 7
        TRISC  = 255
        
        HIGH TestLED
        Pause 100
        LOW TestLED
        PAUSE 100
        HIGH TestLED
        Pause 100
        LOW TestLED
        
        SEROUT RS232TX,N9600, ["Start...",13,10]
        GOTO Main
        
    Main:
          E_0 = PORTe.0
          E_1 = PORTe.1
          E_2 = PORTe.2
          E_3 = PORTe.3
          SEROUT RS232TX,N9600, ["E0=", #E_0, " E1=", #E_1, " E2=", #E_2, " E3=", #E_3 ,13,10]
          Pause 200
    
    GOTO Main

    In the serial output only the RE3-value changes from 1 to 0, when I switch the pin from high to low

    Output:

    E0=0 E1=0 E2=0 E3=1
    E0=0 E1=0 E2=0 E3=0

    What am I doing wrong?

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    adcon1=$0F
    is one of the setting that will work...

    datasheet ....
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Mar 2005
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    Thanks, I thought I'd tried everyting, but it works fine now.

  4. #4
    Join Date
    Mar 2005
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    Now I would like to disable the USB-controller of this pic, because I don't need this feature and I have to use the input pins RC4 and RC5.
    I've read the datasheet and I can disable USB by setting bit3 (USBEN) of the UCON register to zero. The problem is that it looks that PBP doesn't know the commands I want to use. I think i have to use assembly. I tried the following, but I get a warning.

    Code:
    ASM
    MOVLW 0h
    MOVWF UCON
    ENDASM
    Warning:
    Found opcode in collumn 1. (MOVLW)
    Found opcode in collumn 1. (MOVWF)

    I think my assembly knowledge is very bad
    Attached Images Attached Images  

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Reason is that there's no UCON register definition in the PIC18EXT.bas file

    look at the end and add it like this
    Code:
    TXREG2	VAR	BYTE EXT
    TXSTA	VAR	BYTE EXT
    TXSTA1	VAR	BYTE EXT
    TXSTA2	VAR	BYTE EXT
    UCON    VAR	BYTE EXT <= here
    VELRH	VAR	BYTE EXT
    VELRL	VAR	BYTE EXT
    WDTCON	VAR	BYTE EXT
    WREG	VAR	BYTE EXT
    hey!!! don't place the comment to the right
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default

    Hi Steve,

    I also need to add UCON and UCFG for a PIC 18F4550. Adding the variables in the file mentionned above corrects the undefined error at compile time, but how do those variables get linked with the proper registers?

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  7. #7
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default

    Ruben,

    Unless I am mistaken, the USB module is disabled by default. That's why I need to turn it on for USB processing. If you need to use pins C4-5 as IO, you should not have any problems doing so.

    Or did I read the datasheet backwards?

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  8. #8
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default

    I think I found a clue from Steve about where the variable would get linked to the actual register:
    http://www.picbasic.co.uk/forum/show...75&postcount=5

    Now I have to find the right file to edit and the right address.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  9. #9
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default

    Interesting, it's in the USB Descriptor and USB18 files.

    I think it is mainly dependant on whether or not the USB Voltage Regulator is enabled (which I forgot to enable).

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  10. #10
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    257


    Did you find this post helpful? Yes | No

    Default

    I'm going nuts!!!

    Actually it's this 18F4550 that everyone seems to be raving about that is driving me nuts! Or is the 18FXXX series in general.

    Ok I'm getting there.

    1. Downloaded MPASM.
    2. Setup Microcode studio to use MPASM
    3. Figured out how to set the CONFIG fuses... Phewww!

    But now a new problem. (Next in the chain you could say)

    Setting the ADCON0:2 to registers causes compile errors and warnings
    Setting the CMON register causes compile errors and warnings

    I've even tried cut and pasting the ASM code from the data sheet, but to no avail.

    Any help appreciated. Maybe we should setup an 18F forum???

    Squib

  11. #11
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default

    This is all I have along with the Port definitions, variables and constants:

    DEFINE OSC 48 ' 20MHz crystal with HSPLL enabled = 48MHz
    DEFINE I2C_SLOW 1 ' Access I2C device above 8MHz
    DEFINE I2C_HOLD 1 ' Permit I2C device to hold clock line low
    CLEAR

    Maybe just trying with the default values?

    Here's my CONFIG file for 48MHz USB processing, I commented in all values so that I can easily change things around. The base of this setup came from Bruce's post.

    Robert
    Attached Files Attached Files
    Last edited by Demon; - 11th July 2006 at 14:11.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  12. #12
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Squibcakes

    Setting the ADCON0:2 to registers causes compile errors and warnings
    Setting the CMON register causes compile errors and warnings

    I've even tried cut and pasting the ASM code from the data sheet, but to no avail.
    Sounds bad to me, sounds like you have a corrupted INC file OR there's something bad in the PBP-Plugin installation or in the project building process.

    can you post all your files generated in MPLAB (MCW and all other in a zip) and or a COPY/PASTE of the error you got.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  13. #13
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    257


    Did you find this post helpful? Yes | No

    Default

    Ok I found the problem... Sorry for the hassle, but this chip has a few traps man!

    The problem was with the CONFIG statements, I was using Steve's example:
    <b>
    ASM
    CONFIG FOSC=HS ; Use HS oscillator (20MHZ here)
    CONFIG BOR=ON ; Brown out reset ON
    CONFIG BORV=2 ; Brown out detect voltage=4.5 Volt
    CONFIG PWRT=ON ; Power-up timer ON
    CONFIG WDT=ON ; Watch dog timer ON
    <i>....... etc.......</i>
    ENDASM
    </b>

    This would compile ok on its own.

    But as soon as I started to add code (eg CMCON = 7) and the likes I got heaps of Compile errors. (Yes I did delete the _config lines in the 18F4550.inc file!!)

    Anyway I fixed the problem by not using the above asm example but rather this instead. (I found this example in one of Mel's threads not sure where now)

    <b>
    <i>' PRESET FUSES</i>

    _CONFIG_FOSC_HS ; Use HS oscillator (20MHZ here)
    _CONFIG_BOR_ON ; Brown out reset ON
    _CONFIG_BORV_2 ; Brown out detect voltage=4.5 Volt
    _CONFIG_PWRT_ON ; Power-up timer ON
    _CONFIG_WDT_ON ; Watch dog timer ON
    _CONFIG_STVREN_ON ; Stack over/underflow ON
    _CONFIG_LVP_OFF ; Low Voltage programming OFF
    _CONFIG_DEBUG_OFF ; Background debugger OFF
    _CONFIG_VREGEN_OFF ; USB voltage regulator disabled
    ...... etc ......
    </b>

    Hope this info helps others when dealing with the dreaded 18F series. hahaha

    Squib

  14. #14
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    you didn't read the whole post of the config fuse setting. I found the issue later on the same thread. If you want to use the new CONFIG directive, you MUST set them in the pic18F4550.inc file. As now PBP don't support the new directive... this where the Config file (stated in the thread) where born

    NOW being said... if i use the CONFIG stuff bellow.. in wich i did few error for my own pleasure ..
    Code:
            CONFIG PLLDIV = 5          ; Divide by 5 (20 MHz oscillator input)
            CONFIG CPUDIV = OSC2_PLL3  ; [OSC1/OSC2 Src: /2][96 MHz PLL Src: /3]
            CONFIG USBDIV = 1          ; USB clock source comes directly from the primary oscillator block with no postscale
            CONFIG FOSC = HS           ; HS oscillator, HS used by USB
            CONFIG FCMEM = ON          ; Fail-Safe Clock Monitor enabled
            CONFIG IESO = ON           ; Oscillator Switchover mode enabled
            CONFIG PWRT = ON           ; PWRT enabled
            CONFIG BOR = ON            ; Brown-out Reset enabled in hardware only (SBOREN is disabled)
            CONFIG BORV = 2             
            CONFIG VREGEN = ON         ; USB voltage regulator enabled
            CONFIG WDT = ON            ; HW Enabled - SW Disabled
            CONFIG WDTPS = 1           ; 1:1
            CONFIG MCLRE = ON          ; MCLR pin enabled; RE3 input pin disabled
            CONFIG LPT1OSC = OFF       ; Timer1 configured for higher power operation
            CONFIG PBADEN = ON         ; PORTB<4:0> pins are configured as analog input channels on Reset
            CONFIG CCP2MX = ON         ; CCP2 input/output is multiplexed with RC1
            CONFIG STVREN = ON         ; Stack full/underflow will cause Reset
            CONFIG LVP = OFF           ; Single-Supply ICSP disabled
            CONFIG ICPRT = OFF         ; ICPORT disabled
            CONFIG XINST = OFF         ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
            CONFIG DEBUG = OFF         ; Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
            CONFIG CP0 = OFF           ; Block 0 (000800-001FFFh) not code-protected
            CONFIG CP1 = OFF           ; Block 1 (002000-003FFFh) not code-protected
            CONFIG CP2 = OFF           ; Block 2 (004000-005FFFh) not code-protected
            CONFIG CP3 = OFF           ; Block 3 (006000-007FFFh) not code-protected
            CONFIG CPB = OFF           ; Boot block (000000-0007FFh) not code-protected
            CONFIG CPD = OFF           ; Data EEPROM not code-protected
            CONFIG WRT0 = OFF          ; Block 0 (000800-001FFFh) not write-protected
            CONFIG WRT1 = OFF          ; Block 1 (002000-003FFFh) not write-protected
            CONFIG WRT2 = OFF          ; Block 2 (004000-005FFFh) not write-protected
            CONFIG WRT3 = OFF          ; Block 3 (006000-007FFFh) not write-protected
            CONFIG WRTB = OFF          ; Configuration registers (300000-3000FFh) not write-protected
            CONFIG WRTC = OFF          ; Boot block (000000-0007FFh) not write-protected
            CONFIG WRTD = OFF          ; Data EEPROM not write-protected
            CONFIG EBTR0 = OFF         ; Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
            CONFIG EBTR1 = OFF         ; Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
            CONFIG EBTR2 = OFF         ; Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
            CONFIG EBTR3 = OFF         ; Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
            CONFIG EBTRB = OFF         ; Boot block (000000-0007FFh) not protected from table reads executed in other blocks
    and i place it in the 18F4550.inc file like that
    Code:
    ;****************************************************************
    ;*  18F4550.INC                                                 *
    ;*                                                              *
    ;*  By        : Leonard Zerman, Jeff Schmoyer                   *
    ;*  Notice    : Copyright (c) 2004 microEngineering Labs, Inc.  *
    ;*              All Rights Reserved                             *
    ;*  Date      : 12/31/04                                        *
    ;*  Version   : 2.46                                            *
    ;*  Notes     :                                                 *
    ;****************************************************************
            NOLIST
        ifdef PM_USED
            LIST
            "Error: PM does not support this device.  Use MPASM."
            NOLIST
        else
            LIST
            LIST p = 18F4550, r = dec, w = -311, f = inhx32
            INCLUDE "P18F4550.INC"	; MPASM  Header
            CONFIG PLLDIV = 5          ; Divide by 5 (20 MHz oscillator input)
            CONFIG CPUDIV = OSC2_PLL3  ; [OSC1/OSC2 Src: /2][96 MHz PLL Src: /3]
            CONFIG USBDIV = 1          ; USB clock source comes directly from the primary oscillator block with no postscale
            CONFIG FOSC = HS           ; HS oscillator, HS used by USB
            CONFIG FCMEM = ON          ; Fail-Safe Clock Monitor enabled
            CONFIG IESO = ON           ; Oscillator Switchover mode enabled
            CONFIG PWRT = ON           ; PWRT enabled
            CONFIG BOR = ON            ; Brown-out Reset enabled in hardware only (SBOREN is disabled)
            CONFIG BORV = 2             
            CONFIG VREGEN = ON         ; USB voltage regulator enabled
            CONFIG WDT = ON            ; HW Enabled - SW Disabled
            CONFIG WDTPS = 1           ; 1:1
            CONFIG MCLRE = ON          ; MCLR pin enabled; RE3 input pin disabled
            CONFIG LPT1OSC = OFF       ; Timer1 configured for higher power operation
            CONFIG PBADEN = ON         ; PORTB<4:0> pins are configured as analog input channels on Reset
            CONFIG CCP2MX = ON         ; CCP2 input/output is multiplexed with RC1
            CONFIG STVREN = ON         ; Stack full/underflow will cause Reset
            CONFIG LVP = OFF           ; Single-Supply ICSP disabled
            CONFIG ICPRT = OFF         ; ICPORT disabled
            CONFIG XINST = OFF         ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
            CONFIG DEBUG = OFF         ; Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
            CONFIG CP0 = OFF           ; Block 0 (000800-001FFFh) not code-protected
            CONFIG CP1 = OFF           ; Block 1 (002000-003FFFh) not code-protected
            CONFIG CP2 = OFF           ; Block 2 (004000-005FFFh) not code-protected
            CONFIG CP3 = OFF           ; Block 3 (006000-007FFFh) not code-protected
            CONFIG CPB = OFF           ; Boot block (000000-0007FFh) not code-protected
            CONFIG CPD = OFF           ; Data EEPROM not code-protected
            CONFIG WRT0 = OFF          ; Block 0 (000800-001FFFh) not write-protected
            CONFIG WRT1 = OFF          ; Block 1 (002000-003FFFh) not write-protected
            CONFIG WRT2 = OFF          ; Block 2 (004000-005FFFh) not write-protected
            CONFIG WRT3 = OFF          ; Block 3 (006000-007FFFh) not write-protected
            CONFIG WRTB = OFF          ; Configuration registers (300000-3000FFh) not write-protected
            CONFIG WRTC = OFF          ; Boot block (000000-0007FFh) not write-protected
            CONFIG WRTD = OFF          ; Data EEPROM not write-protected
            CONFIG EBTR0 = OFF         ; Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
            CONFIG EBTR1 = OFF         ; Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
            CONFIG EBTR2 = OFF         ; Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
            CONFIG EBTR3 = OFF         ; Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
            CONFIG EBTRB = OFF         ; Boot block (000000-0007FFh) not protected from table reads executed in other blocks          
            NOLIST
        endif
            LIST
    EEPROM_START	EQU	0F00000h
    BLOCK_SIZE	EQU	32
    if i used the kinda unusefull code bellow
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=964&stc=1&d=1152676768 ">

    No error, no nothing.. Config fuses? no problem
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=965&stc=1&d=1152676888 ">

    I've heard somewhere that you should change all config fuse to be sure that all will be considered.

    Using the OLD method is still working.. read the config fuse thread, there's @ errorlevel stuff... read it 'till the end
    Attached Images Attached Images   
    Last edited by mister_e; - 12th July 2006 at 06:12.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  15. #15
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    257


    Did you find this post helpful? Yes | No

    Default

    Ok, now I get it and see it working.

    We modify the 18FXXXX.inc file to set the Config fuses, not in the actual program.

    Cheers Mate

    Squib

  16. #16
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    no problem. i still think about an utility to work around in meantime... when time will really permit
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. LCD Problems
    By gtx15 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 29th September 2007, 04:04
  2. New to PBP and having problems!
    By Lauren Barta in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 12th October 2006, 04:49
  3. 18F6680 and portd problems.
    By jkbh in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 6th June 2005, 11:54
  4. HSEROUT Problems
    By SergioRM in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th April 2005, 00:17
  5. Display problems
    By rossfree in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th November 2004, 00:36

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