SX chip - Port B as input
Hi,
I am using a SX 28 chip to supply voltage via the C port and read input via port B.
It is a simple program but still it fail to work properly.
The debug screen shows that port rb changes to values such as FF when I move values to rc.
Can this rb port value change due to changes on other ports or is my SX 28 defective ?
(The program does not do any writing to the rb port but simply waits on an input, using the jb command ).
Please suggest any possible reasons for this since I have tried almost everything possible.)
Thanks.
I am using a SX 28 chip to supply voltage via the C port and read input via port B.
It is a simple program but still it fail to work properly.
The debug screen shows that port rb changes to values such as FF when I move values to rc.
Can this rb port value change due to changes on other ports or is my SX 28 defective ?
(The program does not do any writing to the rb port but simply waits on an input, using the jb command ).
Please suggest any possible reasons for this since I have tried almost everything possible.)
Thanks.
Comments
For example, are all 8 port C pins wired directly to the 8 port B pins? If so then you are correct - if port C is set OUT and port B is set IN, then whatever you write to port C should be read from port B.
I seem to remember a discussion about that there may be a slight delay after writing to C before the data will be read from B, like one instruction clock or so, but I'm not sure about that.
My code looks like this:
start_point
mode $0F
mov !rb #$11111111
mov !rc #$00
mov rc #00
step1 mov rc, #$00000101
check1 nop
jnb rb.0, switch_open
mov rc, #$00000010
jmp check2
switch_open nop
jmp step1
check2 nop
sleep
I reduced my program to these simple steps, so that port c changes if there is an input voltage at port b pin 1. However port b goes to a value of 11111111
and pin 1 is always set to 1, with or without applied voltage.
The entire program uses all 8 pins of port b as input, and all 8 pins of port c as output and is based on this concept, but I cannot go any further if I cannot even get this correct.
I'm stuck and wondering if it could be my SX chip. Will greatly appreciate any assistance. Thanks again.
If you hit the sleep, you can't trust your debug -- all pins go to inputs and if C pins are connected to B pins, they'd all be floating.
If you want to read that value from port B then you need to connect a wire from each port C pin to the same bit of the port B pin.
It would be a good experiment to start by connecting just one bit of port C to port B, and see that bit change in the program.
When you're experimenting, it would be good practice to use a resistor of about 1000 ohms instead of a wire so if you accidently set both ports OUT then not much current will flow. Since an IN port is so much higher impedance than 1000 ohms, the correct program should still work properly.
Is there a simple test I can do using the IF statement? I tried using the statement " if rb.0 = 0" but did not get the required result.
Try something like this:
In the above, I would expect all RC pins to go high if RB.0 is tied LOW, and all RC to go low if RB.0 is tied HIGH. The @ symbols on the jumps are to ensure page boundaries are crossed properly (in your short program, probably not needed, but I'm playing it safe).
your programs works fine with all of RC set low. However if I change the bit configuration so that some of the pins are high and some are low I run into problems.
In the code below:
With RB,0 set low I get the one led on "0000_0010". However with RB.0 set high I get all 3 leds on "0000_0111", instead of just 2 "0000_0101".
I am so close yet so far from a solution.
start_point mode $0F mov !rb #%11111111 ' you had a hex indicator here, not binary mov !rc #$00 mov rc, #%0000_0000 ' you had a hex indicator here, not binary check1: nop jnb rb.0, @pin_low pin_high: mov rc, #%0000_0101 jmp @check1 pin_low: mov rc, #%1111_0010 jmp @check1
device turbo,
reset start_point
freq 50000000 ; 50 Mhz
;;;;;;;;;;;;; Definition Of Symbols
count1 equ $08
counter = 9
mnum = $00
port_ra =$00
port_rb =$00
port_rc =$00
temp_reg =$00
two = $00
tre = $00
fou = $00
fiv = $00
six = $00
ffff = $16
delay = $12
work = $0c
h = $00
i = $00
j = $00
watch count1, 16, UDEC
org 0
start_point nop ; I tried each of the 2 modes below with no change
;mode $0D ; set trigger
;mov !rb, #%0000_0000
;mode $0C ; set direction mode
;mov !rb, #%0000_0000
mode $0F ; set direction mode
mov !rb, #%11111111 ; set as input
mov !rc, #%00000000 ; set as output
mov rc, #%00000000 ; set low
step_1 nop
mov rc, #%00000000
check_1 nop
jb rb.0, @switch_close ; pin rb.0 set high by sx Vdd port
jnb rb.0, @switch_open ; connection removed from rb.0 (no voltage applied)
nop
switch_open mov rc, #%0000_0101 ; all 3 led connected rc.0,rc.1,rc.2 lights (should only be 0 & 2)
jmp @check_1
switch_close nop
mov rc, #%0000_0010 ; only led connected to rc.1 lights as expected.
jmp @check_1
Seems like it should work as expected. Have you tried this with a different chip?