Quote Originally Posted by richard View Post
for one
your volup: subroutine
has a goto main in it , this will eat up the stack , pic18 subs can only nest 22 levels deep at the most
subroutines aren't re-entrant and must return to where they called from .

VOLUP: ' All variables are set as bytes
'
Z = $01 ' For future functions
DO
IF Leader > DL1 THEN
GOSUB VOLUP1 ' Go to increase volume
ELSE
pattern = 0
GOSUB Out_595
GOTO MAIN
ENDIF
PULSIN INFRA,0,Leader ' Check again for start pulse (autorepeat function) WORKS
LOOP
GOTO VOLUP ' Go back to main routine to check for another button press
'
'================================================= =================================================
'================================ VOLUME INCREASE AND BYTE CALCULATIONS =======================
'================================================= =================================================
'
VOLUP1:

OMG !!!
Thank you Richard, I couldn't see the obvious !!!
I feel I have to post the solution you provided and I ended up with a smaller code that does the same.

Code:
'==================================================================================================
'===================================   VOLUME UP SUBROUTINE    ====================================
'==================================================================================================
'
VOLUP:                                           '
'
Z = $01                                          ' Volume sub command
DO WHILE Leader > DL1                            ' If START pulse increase volume
    GOSUB VOLUP1                              
    PULSIN INFRA,0,Leader                        ' Check for another for auto repeat
LOOP
pattern = 0                                      ' LED OFF
GOSUB out_595
RETURN                                           ' Go Back to Commands and then Main
'
Now I have to fight with the PULSIN command @ 16 MHz.
If someone asks why to go @ 16 MHz if 4 Mhz works OK, the answer is that I need higher serial port speeds.

@ 4 MHz I use DL1 = 800 and DL2 = 110

so @ 16 MHz I have to use DL1 = 3200 and DL2 = 440.

but the above values are not working. I'm sure I'm missing something, I wonder what is it :-)

I don't think is a hardware problem, the HX1838 infrared receiver is connected to PORTD.7 and a pullup resistor of 10K is also used.
I tried also without the pullup and the results are the same and tried to move ports but no luck.

Thanx
Fanias