Serial Number in PIC Basic Pro


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2011
    Posts
    3

    Default Serial Number in PIC Basic Pro

    Hello All,

    I have been lurking about this forum for some time. I really enjoy the ideas and assistance that you all have offered here. I have a project that I am unable to figure out or find anywhere so I joined the club to see if anyone else may have an idea.

    I have a PIC-based device that I am using PIC Basic Pro on. I have a serial number stored in EEPROM on a 16F876A device. This serial number is currently programmed by a serial command and stored in the EEPROM after the device firmware is programmed. This is an extra step that is somewhat error-prone and the serial number can be deleted or changed after the board ships.

    So, I had an idea to put a dummy pattern in the code space (flash memory) and use a shell script (BAT file) to locate the pattern in the HEX file and replace it with a real serial number right before the firmware is written to the device.

    I am using a very customized build environment on a Linux computer. I have a custom build scripting system for revisioning, automatic back ups of builds and running PBPW.exe, etc...

    My question is not how to write the shell script nor am I expecting anyone to understand how my build environment works. I just am looking for ideas that I can use to store a dummy pattern in the code space of the PIC device from PIC Basic Pro and be able to locate these bytes in the resulting HEX file. Simple right? LOL

    My serial number is eleven ASCII characters. Basically, just the date followed by three digits (i.e. 20110713001). I was thinking of using a pattern like $A5 repeated eleven times.

    Thank you in advance if anyone has done anything like this before and/or has any ideas. I will keep plugging away at it.

    Thank you for bearing with me on this long description.

    Best regards All,
    Keith

  2. #2
    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.

  3. #3
    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

  4. #4
    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

  5. #5
    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!!!

  6. #6
    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.

  7. #7
    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

  8. #8
    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.

  9. #9
    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 : 1

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