| ||||||||
Technical Support Support Resources Product Information | C51: SBIT MODIFICATIONS NOT CORRECTLY WRITTEN TO MEMORYInformation in this article applies to:
QUESTIONI have declared a bdata variable and created bits (using sbit). When I change the bits in my program, the changes are not written back into memory. What's going on? ANSWERYou should use the volatile keyword to define bdata variables that are modified with sbit's. volatile is an ANSI standard keyword that disables access optimization and is required to prevent the compiler from re-using the unmodified variable content. For example:
volatile unsigned char bdata var; // use volatile keyword here
sbit var_0 = var^0;
sbit var_1 = var^1;
unsigned char xdata values[10];
void main (void) {
unsigned char i;
for (i = 0; i < sizeof (values); i++) {
var = values[i];
if (var_0) {
var_1 = 1;
values[i] = var; // without the volatile keyword, the compiler
// assumes that 'var' is unmodified and does not
// reload the variable content.
}
}
}
MORE INFORMATION
SEE ALSOFORUM THREADSThe following Discussion Forum threads may provide information related to this topic.
Last Reviewed: Friday, July 15, 2005 | |||||||
| ||||||||