IF Then help?

vk6bgn

New Member
Hello All,
Possibly someone can help me rid my program of zillions of "If Then" statements.

I have 8) 5 volt relays (via 2N7000's) connected to output pins B.0 - B.7 on my PICAXE 18M2 chip. I capture DTMF tones (from a key pad ) in byte b0. This is a number between 1 and 8, to determine which of the 8 relays to turn on or off. (only one relay on or off at a time!) In byte b1 is (a key press) either the number 0 or 1. You guessed it, 0 = off, 1 = on.

I currently have it pretty much working but I have 8 IF THEN's to determine which relay to turn on and 8 IF THEN's to determine which relay to turn off.

Example:
If b0 = 4 And b1 = 1 Then High b.3 (turns relay #4 on)

If b0 = 7 And b1 = 0 Then Low b.6 (turns relay #7 off)

Couldn't the 8 IF/THEN statements to turn on relays be reduced to something like HIGH B.b0 or HIGH B.#b0 ??? Wishful thinking ;) Obviously these produce syntax errors. But certainly there is a better way then a zillion IF/THEN's .

And again the same for 8 IF/THEN statements to turn off relays, LOW B.b0 or LOW b.#b0

Famous quote (from me) "I bet it's simple, but sometimes simple is too hard for me".

Thanks in advance.
"Ham Radio Addict"
 

Dippy

Moderator
If you have your relay o/puts on a whole Port can't you bitwise the b1 (on/off) value onto the port value and just output the port value?
Maybe I've got wrong end of stick as I've only given it 20 seconds of thought :(
 

vk6bgn

New Member
Code:
dec b0
if b1 = 1 then
      high b0
else
     low b0
end if
Thanks Technical.... works a treat, spot on as usual. :) But I still don't understand where in your snippet of code the PICAXE chip knows the byte variable b0 is attached to portB? Why not an output on portC? Just curious.
 
Last edited:
Top