I would be most grateful for some guidance from the experienced forum experts with this project. I intend linking two PICAXE 40X2s via a serial link over XBee transceivers. My aim is to map PORT D as inputs on one unit to PORT B as outputs on the other. This arrangement to apply both ways; i.e. Press-buttons on PORT D on unit one map to PORT B on unit two and the buttons on PORT D on unit two map to PORT B on unit one. The rate of switching is very low - indeed almost occasional. I think that this can be achieved using the hardware serial ports on the 40X2 devices, but, although I am very familiar with the use of SERIN and SEROUT and PICAXE in general, I am having some trouble understanding the depths of the hardware serial commands.
The problem is that I cannot use the simulator to check the operation of the program because the hardware serial function is not simulated. So before I commit a soldering iron to a stripboard, could I request comments on the viability of this concept and my proposed code?
The problem is that I cannot use the simulator to check the operation of the program because the hardware serial function is not simulated. So before I commit a soldering iron to a stripboard, could I request comments on the viability of this concept and my proposed code?
Code:
'Serial transceiver switching using XBee and 40X2
'Hardware serial output on pin C.6
'Hardware serial input on pin C.7
#picaxe 40X2
#no_data
setfreq m16
SYMBOL REQUESTED_OUTPUT = b0 'reserve w0 and w1 for handling incoming serial data sent to PORT D
symbol port_switches = b4 'reserve w2 and w3 for handling local switch data from PORT B
SYMBOL last_switches = b5
hsersetup b2400_16,%001 '2400 Baud - True IN & True OUT - Background Receive On -
setintflags %00100000,%00100000 'Interrupt on background serial input
let dirsb = $FF ' set Port B as outputs
let pinsb = $00 ' initialise Port B outputs low
let dirsd = $00 ' set Port D as inputs
#macro send_switches
hserout 0,(PORT_SWITCHES) 'transmit value to XBee transceiver
Last_switches=port_switches 'record last switch change
do until pinsd=$00
pause 100 'pause to debounce switch return
loop
#endmacro
interrupt:
pause 50 'Is this needed?
let ptr=0
get ptr, REQUESTED_OUTPUT
let pinsb = REQUESTED_OUTPUT
flags = 0 'Clear interrupt flags
hserptr = 0 'Reset pointer
setintflags %00100000,%00100000 'Reset interrupt on background serial
return
MAIN:
DO
do
let port_SWITCHES = pinsD
pause 100 'Debounce switches
if port_switches>0 then EXIT
loop
send_switches
LOOP