My ROM usage is less than 60%, my RAM usage is less than 40%, but as soon as I put the call in, I can no longer compile!
The procedure I'm calling is :
Code: Select all
procedure WriteWordValue(var TextString : string[20]; Dval : word);
var
DWS : String[5];
begin
Write(TextString);
WordToStr(DVal, DWS);
WriteLn(DWS);
end;
Code: Select all
function ReadADCChannel(Channel : byte) : word;
begin
// Configure the ADC again.
if (Channel = 0) then ADCON0 := $81
else ADCON0 := $81 or (Channel shl 3); // enable the ADC, with slowest ADC clock prescaler possible (Fosc/64).
ADCON1 := $C2; // Right justified, Fosc/64, A0..A4 analogue, A5..A7 digital
// Unconfigure the interrupt
INTCON.PEIE := 0;
INTCON.GIE := 0;
PIR1.ADIF := 0;
// wait a while (Tad minimum is 12 uS) - in our case that's 5 milliseconds. It's not that critical, but has to be done.
Delay_ms(ADC_DELAY);
// start conversion
ADCON0.GO := 1;
repeat until ((ADCON0.GO) <> 0);
// clear ADIF
PIR1.ADIF := 0;
// read the register pair
Result := (ADRESH shl 8) + ADRESL;
///WriteWordValue('RADCC: Result is',Result);
end;
It compiles fine until I uncomment the last line, then no matter what I do, I can't get the linker to work.
Can anyone suggest a workaround or should I log this as a formal linker bug?
I guess it's not easy to be really clever with a compiler/linker in such a crippled architecture, but I thought I was doing the right thing, and I'm completely snookered.
My workaround is to call the routine from an inline ASM block in the ReadADCChannel() procedure, but this is not helpful if I have to manually insert inline assembler every time I want to debug legal and valid pascal code. So I must be misinterpreting something really obvious, but I can't see what it is!