• AVR Freaks

AnsweredHot!Put device id and rev in c variables

Author
pajuhesh80
New Users
  • Total Posts : 17
  • Reward points : 0
  • Joined: 2019/12/08 11:23:37
  • Location: Nowshahr, Mazandaran, Iran
  • Status: offline
2020/01/27 07:25:24 (permalink)
0

Put device id and rev in c variables

I want to send device id and rev to PC but I don't know how to read DEVID1 and DEVID2 addresses.
I already tried these (I just put one line for each):
const char * p_idh = (const char *)0x3FFFFF;    //dev_id_p = 0xff
const char far * p_idh = (const char far *)0x3FFFFF;    //compiler error. expected ';' after declaration!

char dev_id_p = * p_idh;

I found a topic here but I didn't find answer there.
I'm using: MPLAB X IDE simulator, PIC18F25K50 (not real hardware), XC8 compiler

Slow and Steady!
#1
NKurzman
A Guy on the Net
  • Total Posts : 18266
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: offline
Re: Put device id and rev in c variables 2020/01/27 08:08:27 (permalink)
+1 (1)
Did you read the data sheet?

The simulator?
What version of MPLabX?
#2
pajuhesh80
New Users
  • Total Posts : 17
  • Reward points : 0
  • Joined: 2019/12/08 11:23:37
  • Location: Nowshahr, Mazandaran, Iran
  • Status: offline
Re: Put device id and rev in c variables 2020/01/27 08:13:47 (permalink)
0
NKurzmanDid you read the data sheet?

Yes. What do you mean?
NKurzmanThe simulator?

Yes. Selected simulator as tool while creating project. Any problem?
NKurzmanWhat version of MPLabX?

MPLAB X IDE v5.30. Is it really needed? I think the compiler (XC8) matters.
 

Slow and Steady!
#3
ric
Super Member
  • Total Posts : 25592
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Put device id and rev in c variables 2020/01/27 12:41:28 (permalink)
+1 (1)
More importantly, which PIC device?
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#4
malaugh
Super Member
  • Total Posts : 407
  • Reward points : 0
  • Joined: 2011/03/31 14:04:42
  • Location: San Diego
  • Status: offline
Re: Put device id and rev in c variables 2020/01/27 12:55:32 (permalink)
0
Check out the response to an earlier question https://www.microchip.com/forums/m959790.aspx
 
 
#5
NKurzman
A Guy on the Net
  • Total Posts : 18266
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: offline
Re: Put device id and rev in c variables 2020/01/27 13:35:32 (permalink)
0
ric
More importantly, which PIC device?



PIC18F25K50 in the bottom of the Post.
#6
NKurzman
A Guy on the Net
  • Total Posts : 18266
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: offline
Re: Put device id and rev in c variables 2020/01/27 13:39:30 (permalink)
0
http://ww1.microchip.com/downloads/en/devicedoc/30000684B.pdf
Page 95 section 7.0
also Note section 7.3.2
#7
pajuhesh80
New Users
  • Total Posts : 17
  • Reward points : 0
  • Joined: 2019/12/08 11:23:37
  • Location: Nowshahr, Mazandaran, Iran
  • Status: offline
Re: Put device id and rev in c variables 2020/01/28 02:52:24 (permalink)
0
Thanks for all replies. But, C code please!

Slow and Steady!
#8
pcbbc
Super Member
  • Total Posts : 1507
  • Reward points : 0
  • Joined: 2014/03/27 07:04:41
  • Location: 0
  • Status: offline
Re: Put device id and rev in c variables 2020/01/28 07:42:49 (permalink) ☼ Best Answerby pajuhesh80 2020/01/28 08:05:14
+1 (1)
Put the address you want to access in the TBLPTR registers.  Read from the TABLAT register.
I haven't coded any PC18 myself, but if you can't work it out from the datasheet then heaven help you!
 
It's something roughly like...
TBLPTR = address;
asm("TBLRD*-");
value = TABLAT;

Edit missed out TBLRD* and you may need to load TBLPTRU/H?l separately.
post edited by pcbbc - 2020/01/28 07:50:22
#9
Jams100001
Junior Member
  • Total Posts : 69
  • Reward points : 0
  • Joined: 2018/04/12 13:37:33
  • Location: MCHP Chandler
  • Status: offline
Re: Put device id and rev in c variables 2020/01/28 10:17:50 (permalink)
+2 (2)
copied from https://www.microchip.com/forums/m959790.aspx
 
To read the Device ID bytes these operations are performed:
 
TBLPTRU = 0x3F
TBLPTRH = 0xFF
TBLPTRL = 0xFE (for DEVID0 - 0xFF for DEVID1)
TBLRD* (TABLAT = DEVID0 or DEVID1)
#10
Jump to:
© 2020 APG vNext Commercial Version 4.5