port bits

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
User avatar
goldwingers
Posts: 118
Joined: Wed Sep 06, 2006 1:22 pm
Location: London
Been thanked: 1 time
Contact:

port bits

Post by goldwingers »

Hi All,
Can you help me out, i need to extrapolate each bit of port B into its current state ie if the 8 bits were 11110001 how can i extract each bit into an 8 bit array?.

I am working on a VB2008 project and this would be an easy way of collecting a single variable for my project
Basically the Gui will send an output to the pic, the pic will return the 8 bits, this would then used to indicate each portbit on the gui
Many thanks

Ian

User avatar
Steve
Matrix Staff
Posts: 3424
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: port bits

Post by Steve »

It may be a better idea to transmit the whole port byte using Flowcode and then use logic in the VB program to check the state of each bit.

I've not used VB2008, but I presume you can have something similar to the following:

Code: Select all

  If (portVal And 20h) Then
    'bit 5 is high
  Else
    'bit 5 is low
  End If
If you wanted to do the same thing in Flowcode, you could do somthing like the attached program.
Attachments
port to bits.fcf
(6 KiB) Downloaded 254 times

User avatar
goldwingers
Posts: 118
Joined: Wed Sep 06, 2006 1:22 pm
Location: London
Been thanked: 1 time
Contact:

Re: port bits

Post by goldwingers »

Hi Steve,
OK ditched that idea, I have done some trolling through the forum and found your num to hex file, I have built that into a fcd file, this now allows me to send all of ports a,b,c,d,e as a series of hex numbers (using 877a), the hex numbers are stripped from the string sent to the PC giving 5 seperate hex number. These are then translated back to an integer in VB ie 0xFF comes up in a text box as 255. I have checked my conversion from 0x00 to 0xff and that works OK. I can use these as analog inputs no problem.

What i cant work out is how to convert that to say 8 led components ( made up from bitmaps). I know its not your line of work but do you have any ideas

Does anyone have any ideas on this one ??????.
Losing my hair pretty quick on this one

Ian

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: port bits

Post by Benj »

Hello Ian

Does Steve's code above not work to detect the logic of individual bits in VB.
If (portVal And 20h) Then
'bit 5 is high
Else
'bit 5 is low
End If

User avatar
goldwingers
Posts: 118
Joined: Wed Sep 06, 2006 1:22 pm
Location: London
Been thanked: 1 time
Contact:

Re: port bits

Post by goldwingers »

Hi Benj,

No, not in VB2008. As soon as it sees the 20h it kicks it out. It does not recognise the "h".

is there a way of mathmatically doing this?.
There is a "dec2bin" calculation in Excel, maybe i could go down this route and extrapolate the bit info that way.

Ian

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: port bits

Post by Benj »

Ok instead of 20h try using 32 this is the same numeric binary value but using the decimal method instead. Alternativly you could try 0x20 but I dont know if this is supported in VB either.

Post Reply