We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello,
Below is a sample code for main.c, which writes 3 different SFR locations with various values. What I noticed, and don't have explanation for, is that when the data is >7Fh, the _rbyte reads it as double, not char.
main.c
#include <REG51XC.H> sfr SFR_REG1 = 0xF8; sfr SFR_REG2 = 0xF9; sfr SFR_REG3 = 0x91; void main (void) { SFR_REG1 = 0x01; SFR_REG1 = 0x11; SFR_REG1 = 0x20; SFR_REG1 = 0x30; SFR_REG1 = 0x40; SFR_REG1 = 0x50; SFR_REG1 = 0x60; SFR_REG1 = 0x70; SFR_REG1 = 0x77; SFR_REG1 = 0x80; SFR_REG1 = 0x81; SFR_REG1 = 0xF1; SFR_REG1 = 0xFF; SFR_REG1 = 0x27; SFR_REG2 = 0x01; SFR_REG2 = 0x11; SFR_REG2 = 0x20; SFR_REG2 = 0x30; SFR_REG2 = 0x40; SFR_REG2 = 0x50; SFR_REG2 = 0x60; SFR_REG2 = 0x70; SFR_REG2 = 0x77; SFR_REG2 = 0x80; SFR_REG2 = 0x81; SFR_REG2 = 0xF1; SFR_REG2 = 0xFF; SFR_REG2 = 0x27; SFR_REG3 = 0x01; SFR_REG3 = 0x11; SFR_REG3 = 0x20; SFR_REG3 = 0x30; SFR_REG3 = 0x40; SFR_REG3 = 0x50; SFR_REG3 = 0x60; SFR_REG3 = 0x70; SFR_REG3 = 0x77; SFR_REG3 = 0x80; SFR_REG3 = 0x81; SFR_REG3 = 0xF1; SFR_REG3 = 0xFF; SFR_REG3 = 0x27; while (1) { } }
functions.ini
signal void rbyte_test1 (void) { char mydata; while (1) { wwatch(D:0xF8); mydata = _RBYTE(D:0xF8); printf("0xF8 Read : %x\n",mydata); } } signal void rbyte_test2 (void) { char mydata; while (1) { wwatch(D:0xF9); mydata = _RBYTE(D:0xF9); printf("0xF9 Read : %x\n",mydata); } } signal void rbyte_test3 (void) { char mydata; while (1) { wwatch(D:0x91); mydata = _RBYTE(D:0x91); printf("0x91 Read : %x\n",mydata); } } rbyte_test1(); rbyte_test2(); rbyte_test3();
Here is the output after executing the code :
0xF8 Read : 1 0xF8 Read : 11 0xF8 Read : 20 0xF8 Read : 30 0xF8 Read : 40 0xF8 Read : 50 0xF8 Read : 60 0xF8 Read : 70 0xF8 Read : 77 0xF8 Read : ffffff80 0xF8 Read : ffffff81 0xF8 Read : fffffff1 0xF8 Read : ffffffff 0xF8 Read : 27 0xF9 Read : 1 0xF9 Read : 11 0xF9 Read : 20 0xF9 Read : 30 0xF9 Read : 40 0xF9 Read : 50 0xF9 Read : 60 0xF9 Read : 70 0xF9 Read : 77 0xF9 Read : ffffff80 0xF9 Read : ffffff81 0xF9 Read : fffffff1 0xF9 Read : ffffffff 0xF9 Read : 27 0x91 Read : 1 0x91 Read : 11 0x91 Read : 20 0x91 Read : 30 0x91 Read : 40 0x91 Read : 50 0x91 Read : 60 0x91 Read : 70 0x91 Read : 77 0x91 Read : ffffff80 0x91 Read : ffffff81 0x91 Read : fffffff1 0x91 Read : ffffffff 0x91 Read : 27
Any suggestions ?
Thanks in advance.
Thank you very much for the explanation. Changing the type helped.