4mhz! You don't believe in making things easy do you. 
but I'm still curious to see if this can be done without the HPWM module
I believe it can be done on any pin, without any hardware modules, CCP or Timer, and no Interrupts.
Last time, we used the CCP module to create the 120khz, then used XOUT to turn that output on and off. But during that 1ms period that it's sending a "1", the XOUT command is just spinning it's wheels in a PAUSEUS 1000.
Instead of just sitting there letting the hardware do all the work, why not just create the frequency in software for 1ms and be done with it.
Once again, I've never done this, but maybe I can get lucky twice in a row.
For a 120khz signal of 1ms in duration, we need to create 120 cycles.
Each cycle is 8.3333 us (1/120,000).
@ 4mhz it doesn't divide perfectly, so the closest we can get is an 8us cycle which ends up at 125khz. I hope that's close enough.
First off, in your main program, make a variable like this to use for counting the cycles
Code:
LoopCounter VAR BYTE $20 SYSTEM
Now let's go back to the PBPPIC14.lib file. Un-Comment the LOWT line that we had commented previously. This gives back control of the TRIS register to the XOUT command.
Code:
ifdef XOUT_USED
LIST
XOUT2 movlw 2 ; Default to 2 cycles
XOUT movwf R2 ; Save number of cycles
movf RR1, W ; Get data port
movwf FSR ; Put it into FSR
movf RM1, W ; Get data bit mask
call LOWT ; Set data to low, output
And, change the xout1loop that we modified before, to this ...
Code:
xout1loop
movlw 120 ; 120khz for 1ms = 120 cycles
movwf LoopCounter
xout120loop
; ---- 1 cycle of the 120khz ---------------------
movf RM1, W ; 1 Get data bit mask
iorwf INDF, F ; 2 Set the bit
nop ; 3 waist some time
comf RM1, W ; 4 Get inverted data bit mask
andwf INDF, F ; 5 Clear the bit
decfsz LoopCounter, F ; 6 Are we done yet?
goto xout120loop ; 8 NO. Do it again.
Then, using it should be like normal again ...
Code:
XOUT PORTB.3,PORTA.0,[house\lightsOff]
Once again, Fingers crossed 
<br>
Bookmarks