PDA

View Full Version : 18F4550 - Does strange things on D ports



NL2TTL
- 22nd October 2009, 08:53
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:




'************************************************* ***************
'* 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:

Darrel Taylor
- 23rd October 2009, 03:09
You aren't using PORTD in your program, so they are floating.
Leakage currents could make them vary when other pins transition.

Try adding...
PORTD = 0
TRISD = 0

NL2TTL
- 23rd October 2009, 08:28
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?

NL2TTL
- 23rd October 2009, 11:06
To exclude the PIC I changed to a 18F4455 because this one i have in stock:

When programming the following 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.

ScaleRobotics
- 23rd October 2009, 14:46
This might not be the only problem, but you define DigiData as an array of 74 bytes.

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:

For i = 0 to 73 with that variable define, or define as BYTE[75] so you can use for i = 0 to 74

mackrackit
- 23rd October 2009, 15:21
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

NL2TTL
- 23rd October 2009, 21:44
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


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


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.

Darrel Taylor
- 23rd October 2009, 21:50
Dang, I should have seen that. :o

Thanks for the update.
<br>