PDA

View Full Version : Reading multiple ports



Rob Martin
- 17th May 2004, 23:22
I have a project where i need read several inputs in one hit and as quick as possible. 16f648

Ideally I'd like to read PORTB and display the results on an LCD.
This could be in binary e.g.0000001 when button one is pressed or 00001001 when one and four are pressed.
( I was thinking I could assign TRISB to a VAR?)

I then need to access each byte of PORTB to display some text e.g
if PORTB.0 = 1 then do something.
if PORTB.1 = 1 then do something else.

I've been playing but can't seem to read the ports without usung the button commands and lots of IFs.

Rob

Squibcakes
- 18th May 2004, 00:27
Rob,

I would read the entire PortB, and then do a CASE senario based on the values at the Port so that if two buttons are pressed at the same time you can detect it.

For example:
<table border="1" padding="3" spacing="3"><tr><td>
B0 var byte
TRISB = %11111111 'MAKE PORT B INPUT
B0 = PORTB

START:
SELECT CASE B0

CASE 0
' NO SWITCHED PRESSED
CASE 1
' SWITCH ONE PRESSED
CASE 2
' SWITCH TWO PRESSED
CASE 3
' SWITCH'S ONE AND TWO
CASE N
' WHAT EVER
END SELECT

GOTO START
<br></td></tr></table>

Rob Martin
- 20th May 2004, 17:22
Squibcakes

This seems like an easy way of reading the ports.

Thanks for the reply.


Rob