PDA

View Full Version : PIC18F4620 Write Command



csooi08
- 23rd November 2013, 13:43
Dear all,
Good day!

I use the "WRITE" command in microcode studio plus for PIC18F4620 and I found out during debugging (When I use "DEBUG" command), there is no output is sending out from the PIC18F4620.

Example of my code.

'================================================= ================
step = 0
WRITE $4205, step
.......
.......
goto Checking Step

Checking Step:
READ $ 4205, step
step = step + 1
WRITE $4205, step
DEBUG "step = ",DEC step,10,13 --> (output show on the monitor - use hyperterminal)
if step = 1 then power_on
..........
If step = 14 then multimeter_judge
goto Checking Step

multimeter_judge:
multimeter_string (14) = 0
DEBUGIN timeout,meter_ng, STR multimeter_string\64
WRITE $4210, multimeter_string(0)
WRITE $4211, multimeter_string(1)
WRITE $4212, multimeter_string(2)
WRITE $4213, multimeter_string(3)

if multimeter_string (2)= "H" then judge_ng
goto multimeter_judge

judge_ng:
DEBUG STR multimeter_string(2),10,13 --> No output show on the monitor (I use hyperterminal for
debugging)
'================================================= ================

Any one know what is going on? Why the "DEBUG" command suddenly no function?

TQ and BR

Heckler
- 23rd November 2013, 14:33
I'm not sure if you copied/pasted your code in your question or if you typed it in manually.

But you need a comment delimiter after the Debug statement but before your comment. (you probably know that :))

When you post code enclose it between "code markers"
"it's the "#" button at the top of the posting window. If you don't see it then go "advanced" and it will be at the top of the posing window.

this way if your code is very long it ends up in a scrollable window in the forum.





'================================================= ================
step = 0
WRITE $4205, step
'.......
'.......
goto Checking Step

Checking Step:
READ $ 4205, step
step = step + 1
WRITE $4205, step
DEBUG "step = ",DEC step,10,13 '--> (output show on the monitor - use hyperterminal)
if step = 1 then power_on
'..........
If step = 14 then multimeter_judge
goto Checking Step

multimeter_judge:
multimeter_string (14) = 0
DEBUGIN timeout,meter_ng, STR multimeter_string\64
WRITE $4210, multimeter_string(0)
WRITE $4211, multimeter_string(1)
WRITE $4212, multimeter_string(2)
WRITE $4213, multimeter_string(3)

if multimeter_string (2)= "H" then judge_ng
goto multimeter_judge

judge_ng:
DEBUG STR multimeter_string(2),10,13 '--> No output show on the monitor (I use hyperterminal for debugging)

'================================================= ================

HenrikOlsson
- 23rd November 2013, 19:09
Hi,
WRITE is used to write values to on chip EEPROM, which the 18F4620 has 1024 bytes of.
You're trying to write to location $4205 which is WAY out of range of the available 1024 bytes.

WRITE 0, step ' <---Will write to the first EEPROM location
WRITE 1023, step '<---Will write to the last EEPROM location

/Henrik.

csooi08
- 24th November 2013, 06:36
Dear Heckler,
Good day!
Sorry about the post. Long time no do the posting. Forgot how to post the code format.

Aside Henrik,
I do read the datasheet of PIC18F4620 and know the EEPROM address is 0 to 1023.
I also try your suggestion like below code,




Checking Step:
READ $ 200, step
step = step + 1
WRITE $200, step
DEBUG "step = ",DEC step,10,13

if step = 1 then power_on
'.......... continue step increase until step is 14.
If step = 14 then multimeter_judge
goto Checking Step

multimeter_judge:
multimeter_string (64) = 0
DEBUGIN timeout,meter_ng, STR multimeter_string\64
WRITE $100, multimeter_string(0)
WRITE $101, multimeter_string(1)
WRITE $102, multimeter_string(2)
WRITE $103, multimeter_string(3)

if multimeter_string (2)= "H" then judge_ng
goto multimeter_judge

judge_ng:
DEBUG STR multimeter_string(2),10,13
' Sorry I must highlight here for other step is NG, the result can show in hyperterminal except step = 14, the program can run but no output shown in hyperterminal through comport

HenrikOlsson
- 24th November 2013, 08:04
Hi,

I do read the datasheet of PIC18F4620 and know the EEPROM address is 0 to 1023.
So why did you try writing to $4205 then?

Anyway,
What version of PBP are you using? Step is a reserved a word and has been for as long as I can remember, I'm surprised that code even compiles.

I don't have a 4620 to test with but I do have a 4520 so I tried the following code:

i VAR WORD
Char VAR BYTE

Boot:
HSEROUT ["Program start",13,13]
HSEROUT ["Writing EEPROM, starting at location $0000..."]

i = 0
For Char = "A" to "Z"
WRITE i, Char
i = i + 1
NEXT

HSEROUT ["Done.",13]
HSEROUT ["Writing EEPROM, starting at location $0200..."]

i = $200
For Char = "A" to "Z"
WRITE i, Char
i = i + 1
NEXT
HSEROUT ["Done.",13]

PAUSE 1000

HSEROUT ["Reading EEPROM, starting at $0000: "]

For i = 0 to 25
Read i, Char
HSEROUT[Char]
NEXT
HSEROUT[13]

HSEROUT ["Reading EEPROM, starting at $0200: "]
For i = 512 to 537
Read i, Char
HSEROUT[Char]
NEXT
HSEROUT[13,13, "Program end.",13]

PAUSE 10

END
And it produces the following output

Program start

Writing EEPROM, starting at location $0000...Done.
Writing EEPROM, starting at location $0200...Done.
Reading EEPROM, starting at $0000: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Reading EEPROM, starting at $0200: ABCDEFGHIJKLMNOPQRSTUVWXYZ

Program end.
Which shows that, at least at this end, both WRITE and READ works as expected.

I can't really tell what's going on in your case and I don't really understand what exactly the problem is. Can you try and explain it a little better?
If you contunue to have issues you need to boil the code down to a short example that shows the problem and post that code.

/Henrik.

csooi08
- 26th November 2013, 03:55
Hi! Good day! Henrik,

So why did you try writing to $4205 then?

I am using the program which my senior written and him already left the company. So, i not sure what is going to be happen using that command. Now, i understand from your explaination.

Sorry for making you confuse.

Let me show u the exact code that found error part.



'Extract part of the code that have an error
STEP_SELECT:

read $101,STEP_ADDRESS
STEP_ADDRESS = STEP_ADDRESS + 1
WRITE $101,STEP_ADDRESS

NG_COUNTER = 0
write $103,NG_COUNTER

DEBUG "CHECKING STEP_ADDRESS = ",DEC STEP_ADDRESS,10,13
'Here, the result still can see at hyperterminal screen

if STEP_ADDRESS = 1 then MULTIMETER_JUDGE
if STEP_ADDRESS = 2 then ADDR_30
if STEP_ADDRESS = 3 then ADDR_31
if STEP_ADDRESS = 4 then ADDR_32
if STEP_ADDRESS = 5 then ADDR_33
if STEP_ADDRESS = 6 then ADDR_34
if STEP_ADDRESS = 7 then ADDR_35
if STEP_ADDRESS = 8 then ADDR_36
if STEP_ADDRESS = 9 then ADDR_37
if STEP_ADDRESS = 10 then ADDR_38
if STEP_ADDRESS = 11 then ADDR_39
if STEP_ADDRESS = 12 then ADDR_40
if STEP_ADDRESS = 13 then ADDR_41
if STEP_ADDRESS = 14 then CHARGING_CHECK
if STEP_ADDRESS = 15 then CHARGING_CHANGE_DC
if STEP_ADDRESS = 16 then END_PROCESS

goto STEP_SELECT

CHARGING_CHECK:
HIGH RLY5_1_CHARGING_SUPPLY
PAUSE 1000
LOW RLY5_1_CHARGING_SUPPLY
goto MULTIMETER_JUDGE
goto STEP_SELECT

MULTIMETER_JUDGE:
READ $101,STEP_ADDRESS:WRITE $101,STEP_ADDRESS

IF STEP_ADDRESS = 0 then
DEBUG "STEP_ADDRESS = ",DEC STEP_ADDRESS,10,13
'Here, the result still can see at hyperterminal screen
serOut GPIB_TX,N9600,["F5,R5,PR2,CO1,HI+00.200E-3,LO-01.000E-3",13]
pause 500
GOTO CONT_CURRENT_CHECK
endif

IF STEP_ADDRESS = 1 and VERSION_SW = 1 then
DEBUG "(J4) STEP_ADDRESS = ",DEC STEP_ADDRESS,10,13
'Here, the result still can see at hyperterminal screen
SerOut GPIB_TX,N9600,["F5,R7,PR2,CO1,HI+090.00E-3,LO+070.00E-3",13]
pause 500
GOTO CONT_CURRENT_CHECK
ENDIF

IF STEP_ADDRESS = 14 THEN
DEBUG "STEP_ADDRESS = ",DEC STEP_ADDRESS,10,13
'At here, the result can't see at hyperterminal screen...i wonder why this happen?
SerOut GPIB_TX,N9600,["F5,R7,PR2,CO1,HI+420.00E-3,LO+380.00E-3",13]
pause 500
GOTO CONT_CURRENT_CHECK
ENDIF

CONT_CURRENT_CHECK:


I only show the part of the program that error occurred. Hopefully u can understand that.
TQ and BR