Serial Number in PIC Basic Pro


Closed Thread
Results 1 to 9 of 9

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: Serial Number in PIC Basic Pro

    There's MPASM __idlocs who allow to do it like so, for 16F you can have an ID from 0 to 0xFFFF, just use this simple line in your code
    Code:
    @   __idlocs  0xffff
    However, you can't read it at run time, only 18F can

    You could still use a data table
    Code:
        GOTO OverSerial
        ASM
    SERIALNUMBER
        DT "123456789ab",0
        ENDASM
    OverSerial:
         SERIALNUMBER CON EXT
    this will be stored in your code space and you can read it anytime with a READCODE loop using SERIALNUMBER constant as your start address.

    hth
    Steve

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

  2. #2
    Join Date
    Jul 2011
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: Serial Number in PIC Basic Pro

    Thank you! I will give it a shot. This is an excellent idea!

    I was just investigating where constant HSerOut strings are stored. It looks like a dead end though. I would have to parse the HEX file and rewite it or parse/replace the ASM file and create a whole bunch or HEX files. Yuk!

    Cheers!
    Keith

  3. #3
    Join Date
    Jul 2011
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: Serial Number in PIC Basic Pro

    RESULT:

    Slightly modified, I got your solution to work! I am so grateful for your help! This is exactly what I was looking for. I was able to find the pattern in the HEX file (with a regular expression).

    Now the real hard part. I will need to locate the pattern and replace it just prior to programming the device. It tends to span lines in the HEX file and there are checksums to contend with. I am going to look and see if there is a way to tell the assembler to split out this line(s) in the HEX file. Then I just have to parse part of the file. Regardless, I can parse and rewrite the whole thing if I need to.

    Thanks again! I am truely amazed. Now that I am a member, I will check back periodically and see if I can help others in their endeavors.

    Regards to All,
    Keith

  4. #4
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default Re: Serial Number in PIC Basic Pro

    Exactly the reason why many modern MCU's have a built-in unique 64-128 bit ID. These IDs can be read during programmming and/or runtime (but cannot be overwritten/erased) giving you total control over your part.
    Why pay for overpriced toys when you can have
    professional grade tools for FREE!!!

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


    Did you find this post helpful? Yes | No

    Default Re: Serial Number in PIC Basic Pro

    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: Serial Number in PIC Basic Pro

    And yet *ANOTHER* reason to use only 18F chips. Using them, it is relatively easy to put a serial number in codespace, (above MCLoader, if you use that program) or in the userID section.
    Charles Linquist

  7. #7
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default Re: Serial Number in PIC Basic Pro

    Quote Originally Posted by mister_e View Post
    There's MPASM __idlocs who allow to do it like so, for 16F you can have an ID from 0 to 0xFFFF, just use this simple line in your code
    Code:
    @ __idlocs 0xffff
    However, you can't read it at run time, only 18F can
    [code]
    Steve, I would appreciate an explanation of how this works...does @_idlocs XXXXXX automatically read the TBLPTRx addresses from addresses 200000-20000h in an 18F MCU and put it into EEPROM or what? I have been doing this by the use of below code. If they are equivalent, your ASM single line of code is definitely preferable!
    Regards and extremely glad to see you back in the forum and contributing, John Ellis

    'Read MCU Serial Number from device ID Locations
    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 byte as ID(i)
    Next
    deviceID1 = ID(0) ' MSB of MCU Device Serial Number
    deviceID2 = ID(1) ' LSB of MCU Device Serial Number
    WRITE 240, ID(0) ' Write serial number to EEPROM
    WRITE 241, ID(1)
    Last edited by jellis00; - 20th July 2011 at 00:55.

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


    Did you find this post helpful? Yes | No

    Default Re: Serial Number in PIC Basic Pro

    the idlocs line is an MPASM directive, it does the job at compile time. it store the value in a specific PIC location.. kinda black magic Check the MPASM user guide for all the details.
    Steve

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

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