Did this:

define OSC 20

DEFINE HSER_TXSTA 24H
DEFINE HSER_BAUD 31250

main:

CMCON = 7
TRISA = %00000010


lp1:

hserout [147,100,100]

pause 1000

goto lp1

;---------------------------------------

changed the label to lp1 [I usually get some kind of warning for reserved words], and added a long pause, and everything is fine. This corresponds to a note on message on channel 4 and, sure enough, the analyser shows exactly that, then the leds on the analyser go off according to the pause time [I've tried longer and shorter], and never misses a beat or gives an error.

Tried this, by way of a debug/test:


define OSC 20

DEFINE HSER_TXSTA 24H
DEFINE HSER_BAUD 31250

main:

CMCON = 7
TRISA = %00000010
TRISB = %00000000
OPTION_REG.7 = 0

lp1:

portb.3 = 0
if not porta.1 then
portb.3 = 1
endif

goto lp1

;----------------------------------

Sure enough, the led on pin 9, [portb.3] comes on when I press the switch connected to pin 18 [porta.1] and goes off when I release it, perfectly. The switch is pulled up to 5v via a 10k resistor, with the connection to the pin on the switch side of the resistor. Multimeter shows 5.18v on no press, and .082v on press, so well beyond the logic transition levels. Besides, I'm content with the switches, and have done a lot of playing with them, so I'm sure there's no issue with the hardware.

However, if I put the hserout command in, after the led on command, thus:


portb.3 = 0
if not porta.1 then
portb.3 = 1
hserout [144,100,100]
endif

then the note on message NEVER works, even with a suitable pause after. The analyser shows 'error', 'system reset', and the odd spurious code, like 'song select', which tells me that the timing for the hserout is failing badly.

I've wasted hours on this, and it's extremely frustrating. I've never coded the USART in assembler, but think my time might be best used doing so, instead of trying to work around the obvious problems inherent with this compiled language.

This reminds me of the problems I had with a serial LCD display. If I tried to use any interrupts, the display would go off, or show random characters, so the hserout command, or at least the assembly language behind it, must be using one or more of the timers, and other resources. Can I be bothered to pore over the disassembly? Probably not...

G