Program misbehaving when Timer3 SFRPAGE is accessed

Feb 16, 2006 2 Replies

Hi All, I am Ravikumar.N, using C8051F130 microcontroller for my application.



I am using SDCC compiler.



My code is as follows.



void main() { char SFRPAGE_SAVE, RESTORE_SFRPAGE;



SFRPAGE_SAVE = SFRPAGE; SFRPAGE = CONFIG_PAGE; ; Do some task



RESTORE_SFRPAGE = SFRPAGE; SFRPAGE = TMR3_PAGE; ; Do something SFRPAGE = RESTORE_SFRPAGE; }



Here the moment I access the SFRPAGE of TIMER3, program starts misbehaving.



If I dont access the SFRPAGE of TIMER3, program works fine.



what could be reason for this. If anybody know the the solution for this plese let me know.



Regards, Ravikumar.N



Hello !

Are you sure the CONFIG_PAGE and TMR3_PAGE variables are properly initialized ?

If my hunch on what you're doing is about re-writing the whole SFR area for a specific task, then you must be exactly sure that you're not doing any "incorrect" changes when switching pages. Such things might be due to the ";Do some task" part, as in, the CONFIG_PAGE contains settings for the crossbar so X, Y and Z options are used, then these options ARE used, and you forget to stop using them when swiching pages, thus leading the program to behave in an undefined manner.

A second, more interesting question, is why do you need to re-write the SFR area in the first place ? Are there any alternatives into doing it ?

- Antti Keskinen

Hey !

After reading through the docs the situation became much clearer. Now I at least have an idea what you're trying to do :)

First, check the header files for the type of SFRPAGE variable. Make sure SFRPAGE_SAVE and RESTORE_SFRPAGE are exactly the same type. Unsigned/signed makes a difference.

Next, make sure your code is not causing interrupts in "Do some task" and "Do something". If it causes an interrupt, the automatic SFR page switch may bring a discord to your reads and writes to the SFRPAGE registry.

Last, check the header files that TMR_PAGE3 is correctly defined. Timer 3 SFR's are found in page 1.

At least some points to try :)

- Antti Keskinen

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required