Serial

by Martin Clausen (mc AT rotgradpsi DOT de)

Serial adds serial number, date and time to hex-files

Many modern devices contain a microcontroller with a communication interface. This can be used without extra cost to improve the software version management. Therefor the software must provide a possibility to read out serial number, production date and time. This data can easily embedded into the program with Serial. Other applications are the usage of the serial number for bus arbitration and device identification in a network.

Table of contents:

Features

System Requirements

8086, some RAM, about 39kb harddiskspace, DOS or WIN

Usage

serial [/h] [/read] [/pic] [/date] [/time] [/w:FILENAME]

Parameter definition:

/hhelp
/readtry to read serial number, date and time from file
/piclimits serial number to 14 bits
/dateadd date
/timeadd time
/w:hex-file to be modified, extension will be ignored and set to .hex

To support the batch mode, feedback can be received via error levels:

Error
level
Message
0operation successful
1start target address not found
2error in hex-file
3nothing to do
4fatal error

For every byte that should be insert, a dummy byte must exist in the original hex-file.

Serial number, date and time are written to the hex-file as follows:

Startaddress
Offset
Value
0serial number low byte
1serial number high byte
2day
3month
4year (last two digits)
5hour
6minute
7second

The serial number is stored in a file named "hex-file name".ser. The format of this file is:

LineValue
1start target address
2serial number

Examples

If you use code protection for the program memory, make sure that the data is accessible through the MCU program. For example the data can be shown on a LCD during power-up. An alternative solution is to include a command into the communication interface, which makes the MCU dump all data via serial port.

Example for PIC

Task: Program several PIC16F874 with an unique serial number, programming date and time.

Solution: Employ Serial and PICProg in the following way:

  1. Write your program and perform all tests.
  2. Make sure you include dummy values:
    org     0x0FFC
    dw      0x0000, 0x0000, 0x0000, 0x0000
  3. Generate a file for the serial number named "hex-file name".ser with the following content:
    &h01FF8
    0
    The first line will let Serial search for the address 0x0FFC. Pay attention the factor of two, which is caused by the need of two bytes in the hex-file for every 14 bit word of the PIC's flash memory.
    The second line will set the start serial number to zero.
  4. Connect the PICProg hardware to lpt1 of your computer, insert a chip and apply power to the programmer.
  5. Execute ppserial.bat:
    ppserial lpt1 "hex-file name"
    and follow the instructions.
Note: The serial number will not fit into the ID locations at 0x2000, because only the 4 last significant bits of the ID locations can be written.

Example for 8051

Task: Program several AT89C51 with an unique serial number, programming date and time.

Solution: Employ Serial and Peter Dannegger's Atmel MCU Programmer in the following way:

  1. Write your program and perform all tests.
  2. Make sure you include dummy values:
       ORG 0FF8H
    PGMSNR:
       DB  0      ;0 serial number low byte
       DB  0      ;1 serial number high byte
    PGMDate:
       DB  0      ;2 day
       DB  0      ;3 month
       DB  0      ;4 year (last two digits)
    PGMTime:
       DB  0      ;5 hour
       DB  0      ;6 minute
       DB  0      ;7 second
    
  3. Generate a file for the serial number named "hex-file name".ser with the following content:
    &h0FF8
    0
    The first line will let Serial search for the address 0x0FF8.
    The second line will set the start serial number to zero.
  4. Connect the programmer hardware to your computer, insert a chip and apply power to the programmer.
  5. Execute unibatch.bat:
    unibatch "hex-file name"
    and follow the instructions.

Possible Causes of Errors

Download of Program

Disclaimer: No warranty at all!
Copyright by Martin Clausen, Germany.
Contact the author: mc AT rotgradpsi DOT de
Impressum