Luciano, thank you for your extensive reply. The corrections were made, ok.

As for the main problem, it has nothing to do with the external device. It's something related to the sub handling from PBP. Look at the following response taken from the Terminal program suggested earlier:

ATE0
ATV0 <-- at this point I am sending a 0 from the terminal
ats0=2 <-- response is as expected from the program
ATX3 <-- again as expected
AT<00> <-- upto this point, were the command freezes!
<-- then after a minute the <00> appears and execution
continues normally!

AT+CMGF=1
ATS37=9
ATS40=2

So the problem is inside the UART of the PIC as it may look...

Ioannis