PDA

View Full Version : How to read ID locations of PIC 18F4550??



jellis00
- 10th January 2010, 03:09
My application is using a PIC 18F4550, for which the data sheet says:
“25.6 ID Locations
Eight memory locations (200000h-200007h) are
designated as ID locations, where the user can store
checksum or other code identification numbers. These
locations are both readable and writable during normal
execution through the TBLRD and TBLWT instructions
or during program/verify. The ID locations can be read
when the device is code-protected.”

I have been trying to figure out the code for reading the contents of these 8 memory locations so that I can transmit them via BufferOut over USB interface.

Following doesn’t seem to work:
For i = 0 to 8
READ 2097152+I, ID1 ‘Where 2097152d = $200000 as starting address location for ID locations
Next

Can anyone please advise me how this should be coded in PICBASICPro 2.6?

Kamikaze47
- 10th January 2010, 07:24
why not just use the TBLRD and TBLWT instructions?

for example: (note: untested)


VAR i BYTE
VAR ID BYTE[8]

TBLPTRU=$20 ' Address $200000
TBLPTRH=$00
TBLPTRL=$00

FOR i=0 TO 7
@TBLRD*+ ; Get value and increment the address
ID[i]=TABLAT ' Store the ID
NEXT i

*edit* changed so it saves all 8 IDs

jellis00
- 11th January 2010, 17:37
for example: (note: untested)


Thanks so much, Kamikaze47. It works as you wrote it. So you can consider it as tested by virtue of it working in my application.

One caution to any future readers of this thread: Make sure you know whether the ID Locations for your target chip are left or right justified. I am using the PicFlash programmer from mikroElectronika to burn programs to my target 18F4550 because it permits you to edit the ID Locations at burn time. In the case of the 18F4550 the ID Locations are left justified (ID(0) at left ID(7) at far right) as they appear in the window screen on PicFlash. I spent a lot of time discovering this while my code was using ID(7) when I thought I was using ID(0). Just a warning to possibly save you some the time I had to waste. Check your programmer on whether left or right justified!