PIC and project info programmatically

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
mrk89
Posts: 19
Joined: 10 Jan 2015 01:05

PIC and project info programmatically

#1 Post by mrk89 » 23 Apr 2022 11:31

Hi Guys,
is there the possibility to read programmatically the MCU family, the MCU type, the MCU ID and so on, with some functions inside the firmware?

I'm writing a "standard" firmware that will works with PIC18F2550 and PIC18F4550, so I would like to know how to automatic recognize the pic used.
Something like this:

Code: Select all

short PIC_ID;
PIC_ID=READ_PIC_TYPE();
if(PIC_ID==0)//18F2550
{...}
elseif(PIC_ID==1)//18F4550
{...}
elseif
{//ERROR}
Can anyone help me?

Thank you in advance

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: PIC and project info programmatically

#2 Post by janni » 23 Apr 2022 15:47

In processors you mentioned there is two-byte device ID placed at address 0x3FFFFE that can be reached with TBLRD assembly instruction. Reading it should should be possible with function like

Code: Select all

unsigned int devID() {
 unsigned short lower;
 TBLPTR=0x3FFFFE;
 asm TBLRD*+;
 lower=TABLAT;
 asm TBLRD*+;
 return lower | TABLAT<<8;
}
Formally, highest 11 bits of the result form device ID number, 5 lowest bits - its revision, but in case of discussed processors it's simpler:
bit 15-8 DEV10:DEV3: Device ID bits = 0001 0010
bit 7-5 DEV2:DEV0: Device ID bits
011 = PIC18F2455
010 = PIC18F2550
001 = PIC18F4455
000 = PIC18F4550
bit 4-0 REV3:REV0: Revision ID bits
so to differentiate between 2550 and 4550 just one bit of the lower byte is sufficient.

Post Reply

Return to “mikroC PRO for PIC General”