Reputation: 41
im producing 100 remote controls using pic16f1823 and i need unique id for each remote but it should be constant over time so i think its better to generate a random before programming in mplab compiler and then compile these 100 remotes i want not to change the remote_id manually
#include "mcc_generated_files/mcc.h"
#define remote_id 33800
char col;
uint24_t data_out;
void Reset_state(void);
int Key(void);
int Key_prime(void);
void main(void)
{...
please help me in this problem
Upvotes: 4
Views: 779
Reputation: 567
Use the SQTP functionality in the MPLAB IPE. You need to enter 'advanced mode' and sign into the IPE first.
In the SQTP tab, set it to save the values in EEPROM, as 'Raw Data', at memory address 0x00. Press 'Generate' and it will write an sqtp file for you.
Select the SQTP file in the 'operate' tab, under the field where you select your .hex file.
Every time you flash a new mcu, the IPE will increment to the next value in the SQTP file, and will even keep track between sessions.
you can use this in your code to retrieve the data:
unsigned char EEPROM_ReadByte(unsigned char eepromAddress)
{
while(RD || WR); // check the WR&RD bit to see if a RD/WR is in progress
EEADR=eepromAddress; // Write the address to EEADR.
RD = 1; // Set the RD bit to trigger the eeprom read operation.
return(EEDATA); // Return the data read form eeprom.
}
Call EEPROM_ReadByte, passing in 0x00, and it will return one char from your data. Increment eepromAddress and it will return the second char, etc.
Note that your data will be in reverse order, I am not sure why, it is perhaps due to the way SQTP files are encoded.
Upvotes: 1
Reputation: 353
Can you have a script in production that alters the ihex file so that your serial number would appear different in EEPROM (EE) as most pics have 1k of internal EE for data storage ? Then the remote would read its unique serial number from EE locations. This would be a simple job for `gawk' say...
Upvotes: 1
Reputation: 1570
It should be possible to use SQTP mode with the IPE as described here.
http://microchipdeveloper.com/ipe:serial-quick-turn-programming-sqtp-settings
Upvotes: 2