PDA

View Full Version : Chipselect Var PORTD,Vecto4X Compass



shawn
- 25th January 2005, 04:46
Can a person use the alias for Chipselect Var PORTD and select only 3 bits or pins of PortD. I know you can do the whole PortD or just 1 bit, but how if possible would you assign only the 3 MSB to chipselect.

I could not find it in the PBP manual.


Also has anyone messed around with the vector 4X digital compass, if so a little code would be helpfull.

Thanks A Bunch

Darrel Taylor
- 25th January 2005, 06:38
Hi Shawn,

Yeah, that would be handy. Too bad you can't do it. :(

But there's a way to handle it when Reading/Writing to the port.

Writing to the Port:
Chipselect VAR Byte

Chipselect = 2
PORTD = PORTD & %00011111 | (Chipselect << 5)It first reads the current value of PORTD, then AND's it with a mask %00011111 to leave the unused bits alone, then OR's it with the Chipselect value after it's been shifted left 5 places.

So, the range of Chipselect is 0 to 7, and it gets re-mapped to the 3 MSB of PORTD

Reading from the Port:
Chipselect VAR Byte

Chipselect = PORTD >> 5Reading is easier, just shift the contents of PORTD 5 bits to the right.

HTH,
&nbsp;&nbsp;&nbsp;Darrel

shawn
- 26th January 2005, 04:11
Thanks Darrel

guanerrr
- 13th April 2006, 01:50
Arctan() is a trigonometric function. It is the inverse function of the tangent function, tan(). That is,

tan(x) = y implies arctan(y) = x ; for all x

How to do the arctan operation in picbasic pro?

TQ