Thank you Joe and Steve,
Pins RB1(Rx) and RB2(Tx) are used to service the serial connection with the Xbee module. Xout uses pin RB6; Xin uses pin RB4 and zerocrossing is on pin RB6. Here the code:
Code:INCLUDE "Modedefs.bas" INCLUDE "DT_INTS-14_2.bas" ; Base Interrupt System INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts CMCON = 7 TrisA = %00000000 TrisB = %00110010 PortA = 0 DEFINE OSC 10 DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1 DEFINE HSER_SPBRG 64 ' 9600 Baud @ 10MHz, 0,16% DEFINE HSER_CLROERR 1 ' Clear overflow automatically XbDtr var PortB.0 XbRts var PortB.3 XbSlp var PortA.3 Pwr var PortA.0 Led var PortA.1 Buz var PortA.2 X10Rx var PortB.4 ZCrox var PortB.5 X10Tx var PortB.6 TxEnable var PortB.7 high Pwr high XbSlp low TxEnable low XbRts Low XbDtr A0 var Byte House var byte Unit var Byte Job var Byte Decode var byte Pass var byte Rdata var Byte[10] HouseKey var word '--------------------------- Rx DT interrupt definition ------------------- ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler RX_INT, _Getbytes, PBP, no endm INT_CREATE ; Creates the interrupt processor ENDASM @ INT_ENABLE RX_INT ; enable RX_INT interrupts '------------------------------------------------------------------------- gosub Buzzer Main: pause 1 If Rdata[0]=250 then loop goto main Getbytes: Hserin 100,ErrorFlag,[str Rdata\9] High led If Rdata[0]=36 then House = ((Rdata[4]-48)*10) + (Rdata[5]-49) Unit = ((Rdata[6]-48)*10) + (Rdata[7]-49) Decode = Rdata[8]-48 If decode = 1 then Job = 18 : Pass = 1 If decode = 2 then Job = 26 : Pass = 1 If decode = 50 then Job = 20: Pass = 1 If decode = 51 then Job = 28: Pass = 1 gosub TxCommand endif Pass=0 Low led @ INT_RETURN ErrorFlag: RCSTA.4 = 0 RCSTA.4 = 1 Pass=0 low led @ INT_RETURN TxCommand: If Pass=0 then return High TxEnable pause 1 Xout X10Tx,Zcrox,[House\Unit,House\Job] low TxEnable Buzzer: high buz pause 20 low buz return Loop: xin X10Rx,ZCrox,[Housekey] hSerout ["H: ",#Housekey.byte1,13,10] hserout ["K: ",#Housekey.byte0,13,10] goto loop
Now the code works with the exception of HSEROUT that I was anable to get it to work in the "Main" loop. I had to make the trick to jump in a secondary loop "LOOP" to have it working, but if I re-enter the "LOOP" the second time then HSEROUT doesn't work anymore. There must be something effecting the USART setting using Xin and Xout command.
I should mention once again that pic16F628 is working @ 3.3 Volts. No compilation errors without Modedefs.bas file.
Any tip will be welcome!
Al.




Bookmarks