Method for encoding and automatically decoding codes in chip OutNvMem in batches

The invention discloses a method for encoding and automatically decoding codes in chip OutNvMem in batches, comprising the following steps: step 1: electrifying a chip and resetting; step 2: inquiring whether a flag bit in InNvMem is set or not, if the flat bit is not set, executing the step 3; if the flat bit is already set, executing an application program; step 3: reading plain text codes in OutNvMem to an on-chip storage; step 4: encrypting the plain text codes read to the on-chip storage in the step 3 into ciphertext codes; step 5: writing the ciphertext codes obtained by encrypting in the step 4 into an off-chip nonvolatile storage; step 6: setting the flag bit in the InNvMem, and executing the application program by the chip. By adopting the method, when products are produced in batches, the same plain text codes are programmed in advance for off-chip slow nonvolatile storages of all chips, and flat bits in on-chip nonvolatile storages of all the chips are not set.