Logic Gates
Joltnjoe
Posts: 12
I want to have pins 0 through 9 a logic inputs
using pins 11 through 14 as outputs to a BCD Decoder
If I want pins 0-9 at 000000011
to output 11-14 as 0010
·IF IN0=0,IN1=0,IN2=0,IN3=0,IN4=0,IN5=0,IN6=0,IN7=0,IN8=1.IN9=1
THEN LOW 11,LOW 12,HIGH,13,LOW 14
Is there a different way to do this
I want to go from
000000000·· BCD 0000
to
000000001·· BCD 0001
to
000000011·· BCD 0010
to
000000111·· BCD 0011
Etc
111111111·· BCD 1000
To do this as a constant LOOP
using pins 11 through 14 as outputs to a BCD Decoder
If I want pins 0-9 at 000000011
to output 11-14 as 0010
·IF IN0=0,IN1=0,IN2=0,IN3=0,IN4=0,IN5=0,IN6=0,IN7=0,IN8=1.IN9=1
THEN LOW 11,LOW 12,HIGH,13,LOW 14
Is there a different way to do this
I want to go from
000000000·· BCD 0000
to
000000001·· BCD 0001
to
000000011·· BCD 0010
to
000000111·· BCD 0011
Etc
111111111·· BCD 1000
To do this as a constant LOOP
Comments
Will This program Work?
' EM 805 A/D Converter using Flash
' This Program is using the binary output of a A/D Converter
' using a Flash system
' {$STAMP BS2p}
' {$PBASIC 2.5}
DO
·IF (IN0=0) AND (IN1=0) AND (IN2=0) AND (IN3=0) AND (IN4=0) AND (IN5=0) AND
··· (IN6=0) AND (IN7=0) AND (IN8=0) AND (IN9=0)
··· THEN
··· LOW 11
··· LOW 12
··· LOW 13
··· LOW 14
·ELSEIF (IN0=0) AND (IN1=0) AND (IN2=0) AND (IN3=0) AND (IN4=0) AND (IN5=0)
··· AND (IN6=0) AND (IN7=0) AND (IN8=0) AND (IN9=1)
··· LOW 11
··· LOW 12
··· LOW 13
··· HIGH 14
LOOP
Help!!!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Lee
If you know that you logic inputs will always be %00000001, %00000011,... %11111111, then you can write a routine to read the bits of your 10-bit word from LSB to MSB. A rough example of the decoder would work like this:
N=0 ' This is the decimal number
startread: ' begin subroutine
if input.lowbit=1 then shiftbits ' read the lowest bit, if = 0, then N = 0, if =1, then go to the next bit
debug dec N ' print to screen decimal value of N
shiftbits: ' routine to right shift bits
input=input>>1 ' move the second bit into the lsb
N=N+1 ' update N
if N>9 then done
goto startread
done:
end
hope this helps,
agentile
This returns the bit count and the highest bit set (duplication of NCD operator).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
I had the Input statements on one line (the only way it worked)
but can I have it run like this
' EM 805 A/D Converter using Flash
' This Program is using the binary output of a A/D Converter
' using a Flash system
' {$STAMP BS2p}
' {$PBASIC 2.5}
DO
·IF (IN0=0) AND (IN1=0) AND (IN2=0) AND (IN3=0) AND (IN4=0) AND (IN5=0)
·AND (IN6=0) AND (IN7=0) AND (IN8=0) AND (IN9=0) THEN
··· LOW 11
··· LOW 12
··· LOW 13
··· LOW 14
··· PAUSE 500
·ELSEIF (IN0=0) AND (IN1=0) AND (IN2=0) AND (IN3=0) AND (IN4=0) AND (IN5=0)
·AND (IN6=0) AND (IN7=0) AND (IN8=0) AND (IN9=1) THEN
··· LOW 11
··· LOW 12
··· LOW 13
··· HIGH 14
··· PAUSE 500
·· ELSEIF (IN0=0) AND (IN1=0) AND (IN2=0) AND (IN3=0) AND (IN4=0) AND (IN5=0)
·· AND (IN6=0) AND (IN7=0) AND (IN8=1) AND (IN9=1) THEN
··· LOW 11
··· LOW 12
··· HIGH 13
··· LOW 14
··· PAUSE 500
·· ELSEIF (IN0=0) AND (IN1=0) AND (IN2=0) AND (IN3=0) AND (IN4=0) AND (IN5=0)
·· AND (IN6=0) AND (IN7=1) AND (IN8=1) AND (IN9=1) THEN
··· LOW 11
··· LOW 12
··· HIGH 13
··· HIGH 14
··· PAUSE 500
·· ELSEIF (IN0=0) AND (IN1=0) AND (IN2=0) AND (IN3=0) AND (IN4=0) AND (IN5=0)
·· AND (IN6=1) AND (IN7=1) AND (IN8=1) AND (IN9=1) THEN
··· LOW 11
··· HIGH 12
··· LOW 13
··· LOW 14
··· PAUSE 500
·· ELSEIF (IN0=0) AND (IN1=0) AND (IN2=0) AND (IN3=0) AND (IN4=0) AND (IN5=1)
·· AND (IN6=1) AND (IN7=1) AND (IN8=1) AND (IN9=1) THEN
··· LOW 11
··· HIGH 12
··· LOW 13
··· HIGH 14
··· PAUSE 500
·· ELSEIF (IN0=0) AND (IN1=0) AND (IN2=0) AND (IN3=0) AND (IN4=1) AND (IN5=1)
·· AND (IN6=1) AND (IN7=1) AND (IN8=1) AND (IN9=1) THEN
··· LOW 11
··· HIGH 12
··· HIGH 13
··· LOW 14
··· PAUSE 500
·· ELSEIF (IN0=0) AND (IN1=0) AND (IN2=0) AND (IN3=1) AND (IN4=1) AND (IN5=1)
·· AND (IN6=1) AND (IN7=1) AND (IN8=1) AND (IN9=1) THEN
··· LOW 11
··· HIGH 12
··· HIGH 13
··· HIGH 14
··· PAUSE 500
·· ELSEIF (IN0=0) AND (IN1=0) AND (IN2=1) AND (IN3=1) AND (IN4=1) AND (IN5=1)
·· AND (IN6=1) AND (IN7=1) AND (IN8=1) AND (IN9=1) THEN
··· HIGH 11
··· LOW 12
··· LOW 13
··· LOW 14
··· PAUSE 500
·· ELSEIF (IN0=0) AND (IN1=1) AND (IN2=1) AND (IN3=1) AND (IN4=1) AND (IN5=1)
·· AND (IN6=1) AND (IN7=1) AND (IN8=1) AND (IN9=1) THEN
··· HIGH 11
··· LOW 12
··· LOW 13
··· HIGH 14
··· PAUSE 500
·· ENDIF
·· LOW 11
·· LOW 12
·· LOW 13
·· LOW 14
·· PAUSE 5
LOOP
Thank You
Logically Yours
Joltnjoe
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
How does it work in layman's terms?
I have a hard time programing but I need to learn
I tried PIC's but no support
I built a programable Tank ( Tamaya body ) using the Beo-Bot style design
Thank You
Joltnjoe
Note that this is only a partial listing; its purpose to show you that SELECT-CASE is a better programming option than the gigantic IF-THEN constructs used in an example above.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Post Edited (Jon Williams) : 12/16/2004 3:42:51 PM GMT
·· If I may step in just a moment...Yes, he should definately read the WAM tutorial.· Meanwhile, looking at it from his perspective, I think I know what he wants in the explanation...
JoltnJoe,
·· Jon's code works by reading ALL the pins you are reading at the same time, instead of testing each pin one at a time as you were.· Once you read the WAM tutorial you should have a better understanding of how this works, but it boils down to reading the ALL the pins at once:
This puts the state of ALL the pins into bitsIn.· Minus the pins you don't need.
It's the same as your code:
Except that you don't need that whole block of code for each change in the state of the pins.· Instead Jon's code is checking the state by using:
Which refers to the state of each input you were checking one at a time.· But in your code you're checking the state of each pin, for each pattern.· Jon is checking the state of the pins once, with less code, then comparing those values to the individual patterns you were looking for.
Definately read the "What's A Microcontroller"...It'll help alot down the road (And now!).· Good luck.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Knight Designs
324 West Main Street
P.O. Box 97
Montour Falls, NY 14865
(607) 535-6777
Business Page:·· http://www.knightdesigns.com
Personal Page:··· http://www.lightlink.com/dream/chris
Designs Page:··· http://www.lightlink.com/dream/designs
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
I am a very logical thinking person but trying to get into programing
Like I said I like the product because of the support network
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office