Quote Originally Posted by macinug View Post
Hi,
I have my PIC reading from the PC (VB6 program). ...... ....
My question is: can I use the timeout loop of the HSERIN as I have, if so where am I going wrong? Or do I need to use an interrupt?


Code:
loop: 
vbin = 0                                   ' reset VBIn
hserin 10,loop,[wait("XX-"),vbin]   ' loops until XX- is read, then waits for rest
pause 10

select case vbin
    case "a"
    sound mybuzzer,[60,10]
    case "b"
    sound mybuzzer,[60,10,70,10]
    case "c"
    sound mybuzzer,[60,10,0,15,70,10,0,15,80,10]
end select

goto loop
END
You may like to try this change as suggested in red. It might work, but might cough a little at higher repetitions. You may actually want to do away with the pause 10 altogether.

You need to think interrupts only if your code is doing lots of things and you have the probability of losing data. If the receive register is not read soon enough, it would overflow due to the next character coming in. If you cannot read the register fast enough, you should consider using interrupts on UART receive.