PDA

View Full Version : I thought PORTA.0[33] was the same as PORTE.1 ?!?



blainecf
- 19th July 2006, 19:12
Any Ideas???


SERIN2 PORTE.1, 49236, [Commbyte]

SERIN2 PORTA.0[33], 49236, [Commbyte]

The first line works perfectly, the second line doesn't work at all.

I have multiple lines that I'm getting comm signals from, and I need to select them with an index variable. Everywhere else in the program I'm able to use these two concepts interchangeably, except with SERIN2 (and, SEROUT2, I think). I've tried brackets and parenthesis - no help.

My alternative is to write 8 separate sets of code, one for each I/O line

Any brilliance would be appropriately lavished.

Darrel Taylor
- 19th July 2006, 20:57
Hi blaine,

Confusing, isn't it?

With the PORTA.0[33], it's actually doing an array operation.

It will Read PORTE.1 which is either a 0 or 1, then it will SERIN from either PORTB.0 or PORTB.1, depending on the PORTE.1 value.

There is a way to do what you're after, but it depends on 1 thing.

Have you used any "Numbered Ports" anywhere else in your program?

Numbered Ports would be anything like...

LOW 1
HIGH 7
SERIN2, 15, ...

P = 6
LOW P

etc. etc.

blainecf
- 19th July 2006, 21:23
I'm really hoping you have a solution. Please enlighten...

Darrel Taylor
- 19th July 2006, 21:43
It depends on what pins the serial data is coming in on too, hopefully they are all on only 2 PORTS.

Here's the idea.

In your PBP folder, open the .BAS file associated with the chip you are using. You'll see these variables.

PORTL VAR PORTB
PORTH VAR PORTC
TRISL VAR TRISB
TRISH VAR TRISC

They are the Starting locations for the Numbered Ports.

For 0-7 it uses PORTL and TRISL
for 8-15 it uses PORTH and TRISH

These can actually be assigned 2 different ports. You could have PORTL on PORTA, and PORTH on PORTE. Then 0-7 would be PORTA, and 8-15 would be PORTE.

DO NOT just edit the file. Comment out the lines, and declare the PORTs in your main program. This way when you write another program for that chip, the compiler will remind you that the file has been changed.

After that there are many ways to handle the numbers. But it's something like this.

PORTH VAR PORTE
TRISH VAR TRISE

P = 9 ; PORTE.1
SERIN2 P, 49236, [Commbyte]
<br>

blainecf
- 19th July 2006, 22:49
D:

Thanks for the info, but I'll need another solution for my application. I'm using pins scattered across B, C, D, and E ports. For now I've hard-coded individual SELECT CASE statements for each comm group for both SERIN2 and SEROUT2 commands... yuk!

Too bad you can't alias individual array elements to user-defined pins. That would be sweet.

Any other suggestions out there??????????

Darrel Taylor
- 20th July 2006, 00:39
Ok, then one more question.

16F or 18F?
<br>

blainecf
- 20th July 2006, 01:11
18F458 - 44pin plcc

Darrel Taylor
- 20th July 2006, 12:38
blaine,

I think this might work for you.

It uses the same numbers that you were expecting before.
PORTA.0 = 0
PORTB.0 = 8
PORTE.1 = 33


P = 33 : gosub SetSerinPin
GOSUB SerinP2
SerinP2 will return 1 byte from the selected PIN. Received data will be in Commbyte.


;-----------------------------------------------------------------------
@P_A = PORTA ; Find address for PORTA
P_A CON EXT
PinPort VAR WORD ; Address of selected Port
PinBit VAR Byte ; Bit Mask of selected port

SetSerinPin:
PinPort = P_A + (P >> 3) ; PORTA + P/8 Find selected PORT
PinBit = DCD (P & %111) ; create BIT mask
return

SerinP2: ; Get a BYTE from the specified PORT
RM1 = PinBit
RR1 = PinPort.LowByte
RS1 = PinPort.HighByte
@ SERIN2MODE?C 49236
@ SERIN2?B _Commbyte
RETURN

@ ifdef doesnotcompile ; Force PBP to include SERIN2 library
SERIN2 1, 1, [Commbyte]
@ endif
;-----------------------------------------------------------------------

blainecf
- 24th July 2006, 19:02
I'll have to study this, and will probably try it tonight or tomorrow; but, initially it looks exactly like what I'm looking for.

Elegant, clean, versatile, sweet!

Thanks D.

bcf

Darrel Taylor
- 25th July 2006, 04:14
I don't know about elegant, but versatile, yup. Hope you can use it.

Let me know if you need the Serout side of it too.
<br>