|
|
View previous topic :: View next topic |
Author |
Message |
freesat
Joined: 08 Feb 2011 Posts: 32
|
PIC16F1459 getenv("SFR:SPBRG") ERROR 28 |
Posted: Mon Jul 14, 2014 2:24 pm |
|
|
Hi guys,
I'm trying to replace older pic I'm using with PIC16F1459, using same code that uses getenv, but getenv does not work with this ( Error 28: Expecting an identifier, Bad SRF name ), works on almost pics i have tried, if it does not have SPBRG simple return is 0 ( Not Detected in this case ).
Code: | #if getenv("SFR:SPBRG") == 0
#error SBPRG: Not Detected!
#else
#byte SPBRG = GETENV("SFR:SPBRG")
#endif |
Using CCS 5.025.
Page 30 from datasheet says that pic have SPBRG ( 19Bh SPBRG ), but Page 37 from datasheet says ( 19Bh SPBRGL )
So what I'm doing wrong? how can i check if SPBRG or SPBRGL exists, using getenv without raise error? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19477
|
|
Posted: Mon Jul 14, 2014 2:36 pm |
|
|
The 'SPBRG', is a 16bit register, made up of two halves 'SPBRGL', and 'SPBRGH' (low and high bytes). The compiler only knows the names of the halves. If you want to access the whole register (which is what you should be doing to write a value), use:
Code: |
#if getenv("SFR:SPBRGL") == 0
#error SBPRG: Not Detected!
#else
#word SPBRG = GETENV("SFR:SPBRGL")
#endif
|
Then you can just write the 16bit value to SPBRG.
Why try to access it?. set_uart_speed(), directly writes to these registers, and knows how to convert a baud rate to the required values (done at compile time, so no overhead...). |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 14, 2014 2:55 pm |
|
|
It's a little bit confusing, because if you look in the Memory Map section
of the 16F1459 data sheet, it uses the traditional Microchip terms of
SPBRG and SPBRGH. See Table 3-6.
But then if you go down to Table 3-12, Microchip switches terminology to
SPBRGL and SPBRGH.
This is a bug in the PIC's data sheet.
http://ww1.microchip.com/downloads/en/DeviceDoc/40001639B.pdf
You can use the SFR_VALID function to see if the SFR exists:
Quote: | >>> Warning 224 "pcm_test.c" Line 7(1,2): #warning 0
>>> Warning 224 "pcm_test.c" Line 8(1,2): #warning 1
>>> Warning 224 "pcm_test.c" Line 10(1,2): #warning 1 |
Test program:
Code: |
#include <16F1459.h>
#fuses INTRC_IO, NOWDT
#use delay(clock = 32M)
#use rs232(baud=9600, UART1, ERRORS)
#warning getenv("SFR_VALID:SPBRG")
#warning getenv("SFR_VALID:SPBRGL")
#warning getenv("SFR_VALID:SPBRGH")
void main()
{
while(1);
} |
Last edited by PCM programmer on Mon Jul 14, 2014 2:56 pm; edited 1 time in total |
|
|
freesat
Joined: 08 Feb 2011 Posts: 32
|
|
Posted: Mon Jul 14, 2014 2:55 pm |
|
|
Hi Ttelmah,
Thanks for answer, it is for use with DMX protocol, because my code ( derived from Mark's code ) need it in that way, works perfectly in any device i have used, except this one.
I have write a code, that compile and works in any pic, without any changes on code or defines ( full automatic ) and is like universal, but now i get this trouble with that pic, i like to maintain the code universal, but now including the SPBRGL.
if i use ( getenv("SFR:SPBRGL") , it raise same Error 28, with chips that does not have SPBRGL like 16F628
So there other way to check if exists SPBRGL or SPBRG without raise an error? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 14, 2014 2:57 pm |
|
|
Yes, see the edit to my post that I made at the same time you posted. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19477
|
|
Posted: Tue Jul 15, 2014 12:42 am |
|
|
Yes.
It is a case of CCS following a data sheet 'bug', without thinking about compatibility.
If SPBRGL is not valid, then test SPBRG and it should be OK.
Code: |
#if ((!getenv("SFR_VALID:SPBRGL")) && (!getenv("SFR_VALID:SPBRG")))
#error SBPRG: Not Detected!
#else
|
Fun little annoyance.... |
|
|
|
|
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
|