PDA

View Full Version : testing bits



Darrenmac
- 9th November 2004, 22:13
I have 4 switches connected to port b, I am reading in the state of the switches ok but need some help in exicuting code depending wich switches are pressed. At present I am doing 16 if then statements, ( 1 for each of the possible outputs). Is there an easier more efficiant way of doing this?

Bruce
- 10th November 2004, 02:44
Look at the BRANCH or BRANCHL commands.

Main:
PortVal = PORTB & %00001111 ' Assumes lower 4-bits
' Or
' PortVal = PORTB >> 4 ' Assumes upper 4-bits
BRANCH PortVal, [Nada, itsA, itsB, itsC, etc,,]
GOTO MAIN

Nada: ' PortVal returned 0
GOTO Main

itsA: ' PortVal returned 1
do something
GOTO Main

itsB: ' PortVal returned 2
do something else
GOTO Main

itsC: ' PortVal returned 3
do something else
GOTO Main

Much easier than 16 IF THENs.

Darrenmac
- 12th November 2004, 23:27
Thanks Bruce
I have decided to tackle it a compleatly different way. I have identical circuits and wanted to send serial commands from one to the other depending on which input had changed state to change state on the corresponding output of the other micro. I am now reading the port, checking if it has changed since last checked, if it has I send the value out PortA serialy. The other end just takes the serial information and sends it directly to PortB.
I am learning a great deal from this project and I thank you for your help. My next part in this project I am going to tackle is ack from the receiving unit, and retries on no ackon the Tx end.