Setting bit3 of the PMR5 register sets pin 3 as a Wakeup(when pin goes low) interrupt instead of a normal I/O. The WKPINT_3 is the Wakeup3 interrupt. Ther are 6 possible wakeup ints(0-5). I used WKPINT_3 because Jim has the signal from the IRPD wired to pin 3 and I didn’t want to change his wireing since he’s making an assembly guide for this as well.
Also, TMA=4 is setting the TimerA timer to increment every 256 osc pulses(osc runs at 16000000 hz) so TimerA increments 62.5 times ever millisecond. I’m using TimerA to time the pulse widths coming from the Sony remote(technically it’s a universal set to a Sony model).
The Sony singal format is a 2.4ms start pulse(low at the AtomPro’s pin) followed by .6ms idle(high), then 12 data pulses(1=1.2ms low folled by .6ms high, 0=.6ms low folled by .6ms high).
So given that, there are three possible times between any two lows. Either 3ms,1.8ms or 1.2ms.
In TimerA time that is 187.5, 112.5 and 75.
I calculate the time from one low to the next by subtracting the last value of TimerA from the next value of TimerA. I then determine if a bit is either a start or data bit. If it’s a start I initialize the handler. If it’s a databit I load it(0 or 1) into my data variable(irpd_data). When I’ve received 12 bits I copy the command(low 7 bits) into the Command variable and the Address(high 4 bits) into the Address variable.
Note that Sony’s system actually sends out 13 pulses(1start 7command and 5address) but I only read 12(1start 7command and 4address) because this way I use very little time in the interrupt. In order to get that last bit I would have to actually wait inside the interrupt for the length of all pulses(minimum of 16.2ms).
Since the 5th bit of the address bit is almost never used I’m not going to worry about it. Just so you know the only loss is that the address is only good for 16 devices(addresses) instead of Sony’s full spec which supports 18 devices(assuming you found a remote that supported all 18 possible devices).
Nathan