CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Serial num in EEPROM & FLASH
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kmp84



Joined: 02 Feb 2010
Posts: 354

View user's profile Send private message

Serial num in EEPROM & FLASH
PostPosted: Mon Dec 17, 2018 8:19 am     Reply with quote

Hello All,

I have one project with pic12F1840 mcu. I'm searching easy method to store int32 serial number in EEPROM, when program MCU. I saw this one : #SERIALIZE(....). Can be used, or something else?


Thanks for your attention!


Last edited by kmp84 on Fri Dec 28, 2018 4:34 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Mon Dec 17, 2018 8:39 am     Reply with quote

It really depends what programmer you are using?.

#SERIALIZE, works with the CCS programmers, and their CCSLoad/ICD units.
It allows you to write a number that extracted from a file that you create.

If you are not using the CCS programmers, then you would have to look to
see if your unit offered any similar sort of ability...
kmp84



Joined: 02 Feb 2010
Posts: 354

View user's profile Send private message

PostPosted: Mon Dec 17, 2018 9:58 am     Reply with quote

Hi mr.Ttelmah,

I'm using CCS ICD64. How to use this option with auto increment serial number?
newguy



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

PostPosted: Mon Dec 17, 2018 10:42 am     Reply with quote

Code:
#SERIALIZE(dataee=0, binary=4, file="serial_number.txt", log="serial_number_record.txt")


This tells the programmer software (ccsload.exe) to open a file named "serial_number.txt". That file contains one item: an ascii number. If you create serial_number.txt, and put "1" on the first line, save & exit, then program your PIC using CCSLoad, it will reserve the first 4 bytes of the PIC's EEPROM to contain the serial number, and it will "burn" 1 into that reserved memory area. CCSLoad then erases the "1" in "serial_number.txt", replaces it with "2", and saves the file. Everything is logged in a separate text file, "serial_number_record.txt".

The next PIC you program with that same hex file will automatically get a serial number of 2.

The serial number is burned into the EEPROM LSB first. That is, the LSB of the int32 serial number will be at EEPROM address 0, and the MSB will be at EEPROM address 3.
PrinceNai



Joined: 31 Oct 2016
Posts: 480
Location: Montenegro

View user's profile Send private message

PostPosted: Mon Dec 17, 2018 2:49 pm     Reply with quote

I know it was asked a million times before. Any way to do it directly from CCS IDE? My tool chain is CCS IDE, import to MPLAB (hex or coff), program or debug with ICD3. What was required in one project was a different seed for a random generator for every unit. The goal was to delay startup and wait for the light show to end after a very frequent power outage and to do the same after a badly synchronized generator switches back to mains. And than turn on every one of the 200+ slot machines at a different time, with zero crossing to prevent the fuses (or 500+$ monitors) from blowing. It would be nice to have a feature in CCS to generate some kind of number after every build and burn it to EEPROM at program time. It is not hard to do it manually for 200 units, but it is boring. And computers are made to do the boring stuff quickly :-)
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Mon Dec 17, 2018 2:53 pm     Reply with quote

The IDE uses CCSLoad to do the actual programming, so will accept the
SERIALIZE command.
PrinceNai



Joined: 31 Oct 2016
Posts: 480
Location: Montenegro

View user's profile Send private message

PostPosted: Mon Dec 17, 2018 3:23 pm     Reply with quote

Unfortunately I don't own any CCS supported programmer (not expensive, but too expensive for a one-off project). I was "raised" on Microchip tools and one of the main reasons for choosing CCS was the level of integration between the CCS and Mplab. I believe I'm not the only one doing the programming in CCS and using ICD or Pickit to do the actual programming and debugging. That is why I have a semi secret wish for CCS to support something like this directly from the IDE, regardless of the programmer.
newguy



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

PostPosted: Mon Dec 17, 2018 3:24 pm     Reply with quote

PrinceNai wrote:
I know it was asked a million times before. Any way to do it directly from CCS IDE? My tool chain is CCS IDE, import to MPLAB (hex or coff), program or debug with ICD3. What was required in one project was a different seed for a random generator for every unit. The goal was to delay startup and wait for the light show to end after a very frequent power outage and to do the same after a badly synchronized generator switches back to mains. And than turn on every one of the 200+ slot machines at a different time, with zero crossing to prevent the fuses (or 500+$ monitors) from blowing. It would be nice to have a feature in CCS to generate some kind of number after every build and burn it to EEPROM at program time. It is not hard to do it manually for 200 units, but it is boring. And computers are made to do the boring stuff quickly :-)


Easy.
1. Shelve your ICD3.
2. Purchase an ICD-U64.

Done. Wink
PrinceNai



Joined: 31 Oct 2016
Posts: 480
Location: Montenegro

View user's profile Send private message

PostPosted: Mon Dec 17, 2018 3:27 pm     Reply with quote

Very likely a much faster way to have what I want. Laughing
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Tue Dec 18, 2018 12:17 am     Reply with quote

Yes.
If you think about it, making serialize work, requires the programmer
code to do this. For the MicroChip programmer, the code is MicroChip's
so it'd require them to add support for this.
kmp84



Joined: 02 Feb 2010
Posts: 354

View user's profile Send private message

PostPosted: Tue Dec 18, 2018 5:53 am     Reply with quote

Thank you All and mr.newguy! You saved my time for test and check!

Best Wishes!
40inD



Joined: 30 Jul 2007
Posts: 112
Location: Moscow, Russia

View user's profile Send private message

PostPosted: Tue Dec 18, 2018 6:16 am     Reply with quote

Is this possible with PICKIT3?
kmp84



Joined: 02 Feb 2010
Posts: 354

View user's profile Send private message

PostPosted: Tue Dec 18, 2018 8:31 am     Reply with quote

P.S this is function to get back serial num from EEPROM:
Code:


#include <12F1840.h>
#device *=16
#device WRITE_EEPROM = NOINT
#fuses INTRC_IO,PROTECT,MCLR,PUT,BROWNOUT,NOWDT,CPD
#use delay(clock=32MHz)

#use rs232(baud=9600, xmit=PIN_A4, rcv=PIN_A5, errors)

#SERIALIZE(dataee=0, binary=2, file="serial_number.txt", log="serial_number_record.txt")

unsigned int16 SnNumU16;

unsigned int16 READ_U16_EEPROM(unsigned int8 n) {
   int i;
   unsigned int16 data;

   for (i = 0; i < 2; i++)
      *((int8*)&data + i) =  read_eeprom(i + n);

   return(data);
}

void main(void){

   delay_ms(100);
 
   SnNumU16 = READ_U16_EEPROM(0);
   
   printf("\r\n Sn:%LU", SnNumU16);
   
   for(;;){
       ; // User Code
   }
}
mdemuth



Joined: 16 Apr 2007
Posts: 71
Location: Stuttgart, Germany

View user's profile Send private message Visit poster's website

PostPosted: Tue Dec 18, 2018 8:33 am     Reply with quote

It might be an option to use the command line interface with the PICKIT2/3+
https://www.microchip.com/forums/m1047644.aspx
But: this one also costs money Rolling Eyes
kmp84



Joined: 02 Feb 2010
Posts: 354

View user's profile Send private message

PostPosted: Thu Dec 27, 2018 6:36 am     Reply with quote

Hello,
I want to ask you is it possible to use "#serialize" directive with mcu without eeprom? Also can be stored serial number with format like this: "ABCD0000001" and auto increment? (ABCD const string + string number)
Thanks!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group