K22 ANSEL query

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Francis
Registered User
Registered User
Posts: 314
Joined: Sun Mar 25, 2007 9:40 am
Location: Devon

K22 ANSEL query

Post by Francis » Thu Feb 27, 2014 12:24 pm

I've been 'away' doing all hardware for a couple of years and have returned to SF. I have discovered I have gone rusty.

Setup: 18F45K22 sitting on a Mikroelektronika EasyPICV7 using their latest programmer.
I have updated to latest SF (thanks David).

My question:-
If I want a 'mixture' of Analogue and Digital inputs on a port (say PORTB) do I have to use the write_sfr() Macro as used in the SetDigitalIO routine?
And call it when setting up ANSEL?

So, in my code, instead of:
ANSELB = $F0 (a random example)
I'd use...
ADCByte=$F0
write_sfr(ANSELB, ADCByte) // the 'write_sfr()' routine would be above somewhere in my code.


Or do I simply Include "SetdigitalIO.bas" and call the Macro from my code?
Or something totally different?
I'm not sure of the proper way of doing this, so I'd appreciate advice.


Thanks.

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: K22 ANSEL query

Post by Jerry Messina » Thu Feb 27, 2014 2:21 pm

You only need to use the 'write_sfr' macro if you're using the SE version compiler. The full version inserts the proper bank select instructions, so you can directly access the ANSELx registers...

ANSELB = $F0

If you're using the SE version, then here's an example of how to use SetDigitalIO and the macro

Code: Select all

device = 18F45K22

// option statement required for setdigitalio V1.6 and SE version
#option SWORDFISH_SE = true
include "setdigitalio.bas"

dim adcbyte as byte

// if using full version, then you can just set register directly
'ANSELB = $55

// if using SE version (no bank instructions), then you need the macro
// you can set the value using a constant...
write_sfr(ANSELB, $55)

// or by using a variable...
adcbyte = $55
write_sfr(ANSELB, adcbyte)
Make sure you update SetDigitalIO to the latest (v1.7): http://www.sfcompiler.co.uk/wiki/pmwiki ... tDigitalIO

Francis
Registered User
Registered User
Posts: 314
Joined: Sun Mar 25, 2007 9:40 am
Location: Devon

Re: K22 ANSEL query

Post by Francis » Thu Feb 27, 2014 2:48 pm

Thanks Jerry, yes I use full version.

And I've downloaded V1.7 as you suggested ... and put it in the library.

I appreciate that.
All is happy now.

Francis.

Post Reply