Hi WB,You aren't giving enough information to really answer.
Is 1800 in decimal? In hex?
Is CAP2BUFL the low-order byte of CAP2BUF which is, presumable, a two-byte value?
If 1800 is in decimal, then in hex it would be 0x0708, right? That would certainly look like the high-order byte is 0x07 and the low-order byte is 0x08.
Hi John,You can do this, but it would make for an easier program to read, and less likely to have errors, if you declared the variable as a 16-bit quantity, and then loaded your value in a single statement.
You may or may not be able to do that. It's worth looking into as it makes your code a lot more readable and maintainable. But many assemblers don't support stuff like that.Hi John,
I didn't know I could do that. The program was written for me, and I think it will have been done correctly, perhaps for the simulator?
Anyway, I could see WBs suggestion was correct, once I saw the variable in the SIM.
C.
Come on, no despair man. Almost 69 here and still enjoying all this.Hi A,
I can't do Assembler, I wish I was a bit younger and smarter.
C.
Hi A,
I can't do Assembler, I wish I was a bit younger and smarter.
I have the answer to my question now, thanks.
C.
The question really cannot be answered given the information you have provided.I need to load CAP2BUFL = 0xXX CAP2BUFH = 0xXX into a program with 1800. Can someone tell me what values to enter please?
CAP2BUFL = 0x0f 'POSCNT from quad signals, preload 3599
CAP2BUFH = 0x0e
CAP3BUFL = 0x0f 'MAXCNT, preload with 3599 degrees
CAP3BUFH = 0x0e
Hi Eric,hi C,
This is a clip from the programs I posted for you, sometime ago.
Why would you want to load 1800.?Code:CAP2BUFL = 0x0f 'POSCNT from quad signals, preload 3599 CAP2BUFH = 0x0e CAP3BUFL = 0x0f 'MAXCNT, preload with 3599 degrees CAP3BUFH = 0x0e
CAP2BUFL = 0x08
CAP3BUFH = 0x07
E
That was me, and I believe I did it once, but I can't find the program I did it in. The way I handled it was to set up a union placed in memory at the location of the registers I wanted to set as a 16-bit quantity, so it would look like this:BTW: Can it be done in 16 bit as suggested in post #4?
union c2buf {
unsigned cap2_16bit;
} cap2buf @CAP2BUFL;
// You would access it like this:
cap2buf.cap2_16bit = 1500;
If the two (CAP2BUFL and CAP2BUFH) are continuous in memory and you know the endianness of your compiler, you can define CAP2BUF as a pointer to 16-bit type and reference CAP2BUF instead of CAP2BUFH/L separately.it wouldn't accept the <cap2buf @CAP2BUFL;> construction.
CAP2BUFL = (1800 & 0xFF);
CAP2BUFH = (1800 >> 8);
// or even better, define it first, so you can change it in one place if you need to
#define CAP2LOAD 1800
CAP2BUFL = (CAP2LOAD & 0xFF);
CAP2BUFH = (CAP2LOAD >> 8);
Easy, assuming 1) adjacent memory location and 2) little endian compiler:I wish there were some easy way to make a pair or registers act like a single 16-bit variable.
//approach 1
//#define myCCPBUF ((uint16_t *) &CCPBUFL)
//approach 2
uint16_t *myCCPBUF_ptr = (uint16_t *) &CCPBUFL;
#define myCCPBUF *myCCPBUF_ptr
//in your code
myCCPBUF = 1800; //set CCPBUFH..L to 0x0708
We know that it doesn't.we know that it takes extra program space and execution time.
by Aaron Carman
by Jeff Child
by Jake Hertz
by Jake Hertz