I think I am missing something easy here. I made a function to wait a variable amount of time. My problem is that the D accumulator starts at zero after I tell it to load the ClockCycles variable. I believe the problem is that I need to do direct addressing. To do that I would perform LDD #ClockCycles, but Codewarrior doesn't accept that, and instead loads the address, which puts 0000 in the D accumulator.
The code is below:
// ---------------------------------------------
// VariableWaitAmount -- Pass in the amount of ns to delay, 40 ns min
// ---------------------------------------------
void VarWait(long int nsToWait) {
long int ClockCycles;
ClockCycles = nsToWait / 40;
asm START: LDD ClockCycles
asm LOOP1: DBNE D, LOOP1
return;
}
Thanks!
Solved! Go to Solution.
Can you show the disassembly?
Without having tried it out (no CW here), I would think your problem is the type long.
Long is a 4 byte type and a "LDD ClockCycles" loads the two most significant bytes.
Try to make ClockCycles a unsigned long or use LDD ClockCycles:2 to read the 2 least significant bytes.
>I believe the problem is that I need to do direct addressing.
Direct addressing is for variables in the zero page. Accessing variables on the stack is done with IDX (or IDX1/IDX2) with the SP used as index register. I think the syntax LDD ClockCycles is fine, probably just reads the wrong part of the variable.
Daniel
Can you show the disassembly?
Without having tried it out (no CW here), I would think your problem is the type long.
Long is a 4 byte type and a "LDD ClockCycles" loads the two most significant bytes.
Try to make ClockCycles a unsigned long or use LDD ClockCycles:2 to read the 2 least significant bytes.
>I believe the problem is that I need to do direct addressing.
Direct addressing is for variables in the zero page. Accessing variables on the stack is done with IDX (or IDX1/IDX2) with the SP used as index register. I think the syntax LDD ClockCycles is fine, probably just reads the wrong part of the variable.
Daniel