There are a number of libraries that pass a Port to allow the library to setup I/O pins. How is that done?
procedure Init(var Port: Byte; Input, Output: Byte);
I have tried several things and none have worked.
1) How do they get the TRIS out of the Port? Is the offset the same for all PICs?
2) How do you get from the passed var Port to what is passed in ClearBit? I am assuming you use the pointer with @Port but everything I have done has failed.
ClearBit(someTRIS, Output);
ClearBit(somePORT, Output);
Thanks,
Jim
BTW is there a library I could download to look at to learn how to do some of these basic things?
Port/TRIS as a parameter
Re: Port/TRIS as a parameter
As you have suggested, by passing port parameter by reference:JimKueneman wrote:There are a number of libraries that pass a Port to allow the library to setup I/O pins. How is that done?
Code: Select all
procedure Init(var Port: Byte; Input, Output: Byte);
var TRISptr: ^byte;
begin
TRISptr:=@Port+$12; // for PIC18s
{TRISptr:=@Port or $80;} // for PIC16s
TRISptr^:=Input and (not Output);
end;
Naturally, you may pass directly TRIS instead of PORT:
Code: Select all
procedure Init(var Tris: Byte; Input, Output: Byte);
begin
Tris:=Input and (not Output);
end;
As above, because TRISx is equidistant from PORTx within processor family.1) How do they get the TRIS out of the Port? Is the offset the same for all PICs?
ClearBit is an inline routine. Hard to say what compiler will need to do to clear the bit. It may just insert one assembly instruction (when both PORT and PIN are explicit), or use indirect addressing (through FSR). ClearBit(port,bit) is equivalent to port.bit:=0;2) How do you get from the passed var Port to what is passed in ClearBit? I am assuming you use the pointer with @Port but everything I have done has failed.