Don't use POKE. Just use the register name followed by the value to write to
it like you have with ADCON1 = 15.
Poke $81,$FF is writing $FF to RAM address $81 in bank 0 on this part.
INTCON2.7 controls portb pull-ups, but you don't really need to turn them off
with all of portb set to outputs. And the default value of INTCON2 at POR has
them disabled.
Don't use RETURN mainloop. As Darrel already pointed out, this is causing
stack overflow. Using a specific return address here keeps the compiler from
generating RETFIE, popping the "real" return address from the stack, and
resetting global interrupts on return.
Another potential problem is using a timeout with label allowing exit from your
interrupt handler without clearing RCIF interrupt flag bit first.
Also with address = %00000100 and wait(address) your terminal program ( or
whatever you're sending serial data with ) needs to send this as non ASCII. If
you make address = "4", then it should work when receiving the ASCII value 4.
With the optional terminator stuck on the end, it can terminate reception of
the full 30 byte string too. Then HSEROUT [str buffer\30] will send the whole
30 byte string which may or may not be full of ASCII characters causing
garbage to be output in non ASCII array element positions.
Try this;
Send 4=12345678901234567890123456789 with MCS terminal program to it.Code:DEFINE OSC 20 ' Setup Hardware for UART DEFINE HSER_BAUD 9600 DEFINE HSER_RCSTA 90h DEFINE HSER_TXSTA 24h DEFINE HSER_CLROERR 1 RCIF var PIR1.5 Junk VAR BYTE address var byte sentinal var byte buffer var byte[30] init: Pause 10 'Safe Start Up Delay ADCON1 = 15 ' All pins are digital CMCON = 7 ' Turn off comparators ' Poke $81,$FF ' Turn off PORT B pull ups INTCON2.7=1 ' Turn off PORT B pull ups TRISA = %00000000 TRISB = %00000000 TRISC = %10000000 PORTB = $ff address = "4" ' or %00000100 +"0" sentinal = $FF '%11111111 HSEROUT ["Activated"] HIGH 7 ON Interrupt GOTO inthandle INTCON = %11000000 PIE1.5 = 1 mainloop: @ Nop Goto mainloop DISABLE inthandle: TOGGLE 1 If RCIF Then HSERIN 100, intreturn, [wait(address),str buffer\30\sentinal] HSEROUT [str buffer\30,13,10] Low 7 EndIf If RCIF Then inthandle intreturn: WHILE RCIF Junk = RCREG ' trash leftovers to clear RCIF before return WEND Resume ENABLE END
Then try inserting $FF in the string somewhere to see what happens when it
finds the terminator. 4=123456789012345678$FF9012345678




Bookmarks