18F4550 - Does strange things on D ports


Closed Thread
Results 1 to 8 of 8
  1. #1

    Default 18F4550 - Does strange things on D ports

    I have the following code written.

    When the debug code is send, the D6 & D7 port will also become HIGH.
    Why is this happening?

    code:

    Code:
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2009 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 20-10-2009                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    Include     "modedefs.bas"
    
    Define  OSC             20
    
    DEFINE  DEBUG_REG       PORTB
    DEFINE  DEBUG_BIT       6
    DEFINE  DEBUG_BAUD      9600
    DEFINE  DEBUG_MODE      1
    
    
    DEFINE  LCD_DREG        PORTB
    DEFINE  LCD_RSREG       PORTC
    DEFINE  LCD_RSBIT       6
    DEFINE  LCD_EREG        PORTC
    DEFINE  LCD_EBIT        7
    DEFINE  LCD_BITS        4
    DEFINE  LCD_LINES       2
    DEFINE  LCD_COMMANDUS   2000
    
    
    RS232_In VAR         PORTB.5
    
    StatusLED   VAR         PORTB.7
    
    
    DigiData            VAR     BYTE[74]
    
    x var byte
    i VAR Byte
    
    
    adcon1 = $0F
    
    
    Init:
    
        debug "Startup Alarm systeem V1.01",13,10
        
        Lcdout $FE, $01, "Rekavo"
        Lcdout $FE, $C0, "Bericht systeem" 
        
        PAUSE 500
        
        FOR x = 0 to 4
            High Statusled
            PAUSE 500
            LOW Statusled
            PAUSE 500
        NEXT x
             
    Goto Main
    
    Main:
    
        SERIN RS232_In,N9600,10,Main,DigiData[0]
        
        for i = 1 to 74
         SERIN RS232_In,N9600,1,Main,DigiData[i]
        next i
        
        For i = 0 to 74
            DEBUG DigiData[i]
        NEXT i
    
        DEBUG 13,10
      
        IF (DigiData[0] = $02) AND (DigiData[74] = $03) Then
            Debug "Juiste string ontvangen",13,10  
      
            Lcdout $FE, $01, DigiData[4],DigiData[5],DigiData[6],DigiData[7],DigiData[8],DigiData[9],DigiData[10],DigiData[11],DigiData[12],DigiData[13],DigiData[14],DigiData[15],DigiData[16],DigiData[17],DigiData[18],DigiData[19]
            Lcdout $FE, $C0, "Tijd: ", DigiData[70],DigiData[71],":",DigiData[72],DigiData[73]  
            
            PAUSE 2000
            
            Lcdout $FE, $01, " "
            Lcdout $FE, $C0, " "
                                            
        ELSE
        
            Debug "Onjuiste string ontvangen",13,10
       
        endif
    
    Goto Main
    
    end
    See the attachment for the configuration bits:
    Attached Images Attached Images  

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    You aren't using PORTD in your program, so they are floating.
    Leakage currents could make them vary when other pins transition.

    Try adding...
    Code:
    PORTD = 0
    TRISD = 0
    DT

  3. #3


    Did you find this post helpful? Yes | No

    Default

    I have some more problems with the microprocessor.
    I only use the 18F4550 because of the memory 32KB memory and 2048 SRAM.

    I don't use any USB functions and only control a LCD and a few inputs and outputs for RS232 data.

    It looks like my include file is wrong or does some stramge settings.
    Can somebody please tell me how to configure the INCLUDE file so I disable all the USB functions and set the OSC to 20 MHz?

  4. #4


    Did you find this post helpful? Yes | No

    Default

    To exclude the PIC I changed to a 18F4455 because this one i have in stock:

    When programming the following code:

    Code:
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2009 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 20-10-2009                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    Include     "modedefs.bas"
    
    Define  OSC             20
    
    DEFINE  DEBUG_REG       PORTB
    DEFINE  DEBUG_BIT       6
    DEFINE  DEBUG_BAUD      9600
    DEFINE  DEBUG_MODE      1
    
    
    DEFINE  LCD_DREG        PORTB
    DEFINE  LCD_RSREG       PORTC
    DEFINE  LCD_RSBIT       6
    DEFINE  LCD_EREG        PORTC
    DEFINE  LCD_EBIT        7
    DEFINE  LCD_BITS        4
    DEFINE  LCD_LINES       2
    DEFINE  LCD_COMMANDUS   2000
    
    
    StatusLED           VAR         PORTB.7    ' Status LEDs
    
    
    
    RS232_In            VAR         PORTB.5    ' RS232 From DIGI-ME Module
    
    DigiData            VAR         BYTE[74]   ' Array for rrecieved RS232 Data
    
    nt_1     VAR     BYTE[74]
    
    Aantal_Berichten    VAR         BYTE       ' Aantal aanwezige berichten
    Data_available      VAR         BIT        ' Nieuw bericht aanwezig  
    Update_Debug        VAR         BIT        ' ververs de debug data           
    Button_Temp1        VAR         BIT                
    Button_Temp2        VAR         BIT                
    
    x                   var         byte       ' Algemeen te gebruiken teller 
    i                   VAR         Byte       ' Teller binnenkomende karakters
    
    Button1             VAR         PORTC.0
    Button2             VAR         PORTC.1
    
    Show_Bericht        VAR         BYTE
    
    TRISD = 0
    PORTD = 0
    
    PAUSE 500                                  ' Opstart pauze
    
    Init:
        
        Aantal_Berichten = 0
        Data_available   = 0
        Update_Debug     = 0
        x                = 0
        i                = 0
    
        debug "Startup Alarm systeem V1.01",13,10
        
        Lcdout $FE, $01, "Rekavo"
        Lcdout $FE, $C0, "Bericht systeem" 
        
        PAUSE 500
        
        FOR x = 0 to 4
            High Statusled
            PAUSE 50
            LOW Statusled
            PAUSE 50
        NEXT x
             
    Goto Main
    
    Main:
        
        If Update_Debug = 1 Then  
            
            Debug "Aantal berichten in geheugen: ", DEC2 Aantal_Berichten,13,10 
            
            Debug "Ontvangen bericht: ", DEC2 Aantal_Berichten,13,10 
            
            For i = 0 to 74
                DEBUG DigiData[i]
            NEXT i
            
            DEBUG 13,10,13,10
            
            Update_Debug = 0
            
        ENDIF
        
        GOSUB Check_RS232
    
    Goto Main
    
    
    
    '===============================================================================
    ' Check RS232 Port for data
    '===============================================================================
    Check_RS232:
    
        SERIN RS232_In,N9600,10,Main,DigiData[0]
        
        for i = 1 to 74
         SERIN RS232_In,N9600,1,Main,DigiData[i]
        next i
      
        IF (DigiData[0] = $02) AND (DigiData[74] = $03) Then
            Debug "Juiste string ontvangen",13,10  
            Data_available = 1
            Aantal_Berichten = Aantal_Berichten + 1
            Update_Debug = 1
            
            ' Zet het ontvangen bericht in de juiste vrije plaats
            
            'GOSUB Plaats_In_Geheugen   
            
        ELSE
            Debug "Onjuiste string ontvangen",13,10
        endif
    
    Return
    
    END
    The microprocessor starts up sends the INIT text 2 times and hangs.
    In the attachment you find the configuration settings.
    Attached Images Attached Images  

  5. #5
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    This might not be the only problem, but you define DigiData as an array of 74 bytes.
    Code:
    DigiData            VAR         BYTE[74]   ' Array for rrecieved RS232 Data
    But then later you do an i = 0 to 74 (that's 75 bytes), and after that you do a for i = 1 to 74.

    you should use:
    Code:
    For i = 0 to 73
    with that variable define, or define as BYTE[75] so you can use for i = 0 to 74
    http://www.scalerobotics.com

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by NL2TTL View Post
    I have some more problems with the microprocessor.
    I only use the 18F4550 because of the memory 32KB memory and 2048 SRAM.

    I don't use any USB functions and only control a LCD and a few inputs and outputs for RS232 data.

    It looks like my include file is wrong or does some stramge settings.
    Can somebody please tell me how to configure the INCLUDE file so I disable all the USB functions and set the OSC to 20 MHz?
    Being I do not see the configs in your code I will assume you are changing the *.inc file.
    I may be wrong but I think you think the configs can be changed in MPLAB...Nope.

    Please post the inc.

    This is also helpful.
    http://www.picbasic.co.uk/forum/showthread.php?t=543
    Dave
    Always wear safety glasses while programming.

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Thank you very much for the feedback from all of you.

    The Byte[74] I changed to [80] already but the biggest problem was the following:

    In the main routine I call the SUBROUTINE Check_RS232

    Code:
    GOSUB Check_RS232
    In the subroutine when the 10ms counter ends and there is no data I don't do a Return but a hard goto Main. So I get unfinished GOSUBS

    Code:
    SERIN RS232_In,N9600,10,Main,DigiData[0]
    After changing the code to check for serial data in the main routine and don't use the GOSUB the problem was solved.

  8. #8
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Dang, I should have seen that.

    Thanks for the update.
    <br>
    DT

Similar Threads

  1. Replies: 4
    Last Post: - 17th April 2009, 08:56
  2. Replies: 1
    Last Post: - 29th September 2007, 18:05
  3. 18F4550 to 18F2550
    By mpardinho in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th September 2007, 23:13
  4. USB Programmer for 18F4550 PICs
    By Kamikaze47 in forum USB
    Replies: 8
    Last Post: - 21st August 2007, 16:29
  5. How many serial ports can 1 PIC handle?
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd March 2005, 04:34

Members who have read this thread : 0

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