Addressing Pins on the BS2P-40
Gerry Shand
Posts: 45
Hi Folks:
I am trying to program a BS2P-40 and not having a whole lot of luck despite reading the manuals and some posts.
What I am trying to do is assign nicknames to each individual pin so if I have to make a change, I only need to do this once. This is what I have come up with so far, but it does not work:
' {$STAMP BS2p}
' {$PBASIC 2.5}
'Define pins
IOTERM 0 'P0-P15
hundred PIN 0
one PIN 1
two PIN 2
four PIN 3
eight PIN 4
thousand PIN 5
halt PIN 6
start PIN 7
reset PIN 8
zero PIN 9
load0 PIN 10
chip0 PIN 11
data0 PIN 12
sda PIN 13
scl PIN 14
clk PIN 15
IOTERM 1 'X0-X15
running PIN 0
trip PIN 1
alarm PIN 2
zeroout PIN 3
buzz PIN 4
cont1 PIN 5
data1 PIN 14
chip1 PIN 15
PAUSE 500 'wait for things to settle down
Main:
IOTERM 0
IF start=1 THEN relay1· 'if a button is pushed, execute test program
GOTO main
relay1: 'test program to turn on outputs sequentially
IOTERM 1
running=1
PAUSE 500
running=0
PAUSE 50
trip=1
PAUSE 500
trip=0
PAUSE 50
alarm=1
PAUSE 500
alarm=0
PAUSE 50
zeroout=1
PAUSE 500
zeroout=0
PAUSE 50
buzz=1
PAUSE 500
buzz=0
PAUSE 50
cont1=1
PAUSE 500
cont1=0
PAUSE 500
GOTO main
Any suggestions? Thanks and regards,
Gerry Shand
I am trying to program a BS2P-40 and not having a whole lot of luck despite reading the manuals and some posts.
What I am trying to do is assign nicknames to each individual pin so if I have to make a change, I only need to do this once. This is what I have come up with so far, but it does not work:
' {$STAMP BS2p}
' {$PBASIC 2.5}
'Define pins
IOTERM 0 'P0-P15
hundred PIN 0
one PIN 1
two PIN 2
four PIN 3
eight PIN 4
thousand PIN 5
halt PIN 6
start PIN 7
reset PIN 8
zero PIN 9
load0 PIN 10
chip0 PIN 11
data0 PIN 12
sda PIN 13
scl PIN 14
clk PIN 15
IOTERM 1 'X0-X15
running PIN 0
trip PIN 1
alarm PIN 2
zeroout PIN 3
buzz PIN 4
cont1 PIN 5
data1 PIN 14
chip1 PIN 15
PAUSE 500 'wait for things to settle down
Main:
IOTERM 0
IF start=1 THEN relay1· 'if a button is pushed, execute test program
GOTO main
relay1: 'test program to turn on outputs sequentially
IOTERM 1
running=1
PAUSE 500
running=0
PAUSE 50
trip=1
PAUSE 500
trip=0
PAUSE 50
alarm=1
PAUSE 500
alarm=0
PAUSE 50
zeroout=1
PAUSE 500
zeroout=0
PAUSE 50
buzz=1
PAUSE 500
buzz=0
PAUSE 50
cont1=1
PAUSE 500
cont1=0
PAUSE 500
GOTO main
Any suggestions? Thanks and regards,
Gerry Shand
Comments
you can do this:
In your program, the output bit is being set to one, but the DDR (DIRS) bit for that pin is still zero so the pin is configured as an input -- the output driver is disconnected from the physical pin. Using HIGH and LOW sets the pin to an output and puts the output driver in the desired state. If you need to reset the pin to a hi-z state you can do this:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Thanks for the information. I modified the program as follows and I am still drawing a blank. I will admit that while I have done a lot of BS2IC programming, the DIRS has always given me grief. Ha ha.
Any other pointers?
Thanks.
Gerry
' {$STAMP BS2p}
' {$PBASIC 2.5}
'Define pins
IOTERM 0 'P0-P15
hundred PIN 0
one PIN 1
two PIN 2
four PIN 3
eight PIN 4
thousand PIN 5
halt PIN 6
start PIN 7
reset PIN 8
zero PIN 9
load0 PIN 10
chip0 PIN 11
data0 PIN 12
sda PIN 13
scl PIN 14
clk PIN 15
IOTERM 1 'X0-X15
running PIN 0
trip PIN 1
alarm PIN 2
zeroout PIN 3
buzz PIN 4
cont1 PIN 5
data1 PIN 14
chip1 PIN 15
PAUSE 500 'Wait for things to settle down
Main:
IOTERM 0
INPUT start
IF start=1 THEN relay1
GOTO main
relay1:
IOTERM 1
HIGH running
PAUSE 500
LOW running
PAUSE 50
HIGH trip
PAUSE 500
LOW trip
PAUSE 50
HIGH alarm
PAUSE 500
LOW alarm
PAUSE 50
HIGH zeroout
PAUSE 500
LOW zeroout
PAUSE 50
HIGH buzz
PAUSE 500
LOW buzz
PAUSE 50
HIGH cont1
PAUSE 500
LOW cont1
PAUSE 500
GOTO main
I don't know if your statement still works in PBASIC 2.5
Reagards,
Klaus
Problem solved. Jon's idea did work. The problem was with the pin assignment. Looking at the hardware layout, I thought X0 was X15 and X15 was X0, etc. After changing a few variables and making a declaration in the IO statements, the system now works fine.
BTW Klaus, the IF start=1 THEN GOTO relay1 does work in PBASIC 2.5.
Thanks for all your help so far. I will probably be back with a few other questions but so far so good.
Cheers,
Gerry Shand