13. Firmware internals: first Ghidra pass (Harmony 700 2.8)¶
Ghidra 12.1.2, language PIC-18:LE:24:PIC-18, base 0x9000. Result: 28974
instructions covering 66640 of the 76672 code bytes, about 87%, in 521 functions.
Two practical notes on the setup:
analyzeHeadlessrejects a relative project path withPath element starting with '.' is not permitted. Use an absolute path.- Auto-analysis on a raw binary finds almost nothing on its own, because there is no
entry point and no relocations. Seeding it works far better: feed it the
CALL,RCALLandGOTOtargets extracted independently (501 function seeds and 99 code-only seeds here), create functions at each, then run analysis. That is what produced the 87%. - The PIC processor module ships a single generic
PIC-18variant, so SFRs come out assfrF80style names. The peripheral map below was worked out separately and has to be applied by hand.
Working command:
analyzeHeadless <abs-project-dir> harmony \
-import harmony700_2.8.bin \
-processor "PIC-18:LE:24:PIC-18" \
-loader BinaryLoader -loader-baseAddr 0x9000
Peripheral map¶
Derived from access-bank SFR usage counts across the image.
Corrected since this section was written. It said the addresses followed the standard PIC18 high-end map and should be confirmed against the PIC18F67J50 datasheet. They were confirmed, and eight of 93 names were wrong; the table below is the corrected one, and section 18 has the argument and the provenance. Nothing here rests on the generic map any more.
| Address | Name | Uses | Role |
|---|---|---|---|
0xF82 |
PORTC | 50 | bit 2 is the IR LED output |
0xF8A |
LATB | 160 | display driver, block at 0x0D412 |
0xF8E |
LATF | 135 | second heavy peripheral |
0xF80 0xF83 0xF84 |
PORTA PORTD PORTE | 6 / 15 / 6 | keypad row drive |
0xF81 |
PORTB | 27 | keypad column read, bits 4-7 |
0xFD5-0xFD7 |
T0CON TMR0L/H | 19 | IR receive (learning) timebase |
0xFE9/0xFEA/0xFEF |
FSR0L/H, INDF0 | 272 / 204 / 193 | main pointer register, as expected from compiled C |
0x10D00: cycle-accurate delay, the most-used primitive¶
10d00: f9 24 ADDWF PCL,W
10d02: f9 6e MOVWF PCL
10d04: 00 00 NOP <- long NOP sled follows
A computed jump into a run of NOPs, so the delay is W-proportional and
cycle-exact. 28 direct callers. Note it appears at the same address 0x010D00 in both
the 600 0.2 and the 700 2.8 images.
0x194A4: software IR carrier modulator¶
Not a hardware PWM. The carrier is generated in software, fully unrolled over 8 half-cycles:
194b4: 82 84 BSF PORTC,2 ; IR LED on
194b6: bc 51 MOVF 0xbc,B,W ; on-time
194b8: 80 ec 86 f0 CALL 0x10d00 ; delay
194bc: 82 94 BCF PORTC,2 ; IR LED off
194be: bd 51 MOVF 0xbd,B,W ; off-time
194c0: 80 ec 86 f0 CALL 0x10d00 ; delay
194c4: be a1 BTFSS 0xbe,B,0 ; bit n of mask selects whether this
194c6: 82 84 BSF PORTC,2 ; half-cycle drives the LED
... ; repeats for bits 0 through 7
Bank-13 variables: 0xBC = on-time, 0xBD = off-time, 0xBE = an 8-bit mask selecting
which half-cycles drive the LED. The mask is active low: the test is BTFSS, which skips
the guarded BSF PORTC,2 when the bit is set, so a clear bit turns the LED on. All three are loaded at 0x194A8-0x194B0 via
MOVFF from 0x08D, 0x08E and 0x3BF. A programmable on/off time plus a per-half-
cycle enable mask is exactly what you need to synthesise arbitrary carrier frequencies
and duty cycles (36, 38, 40, 56 kHz) as well as carrier-less protocols. Single caller,
0x195F0.
Tracing where 0x08D, 0x08E and 0x3BF are filled from is the direct route to how
the config's IR timing data is interpreted.
The full IR chain, from config pointer to waveform¶
Traced end to end by following every write to 0x08D, 0x08E and 0x3BF.
Step 1, the action dispatcher at 0x12F08. A compiler switch (the PIC18 XORLW
cumulative-compare idiom) reads a selector from data 0x08B and routes a 16-bit pointer
held in 0x095/0x096 into one of four subsystem pointer slots:
selector at 0x08B |
pointer copied to | handler |
|---|---|---|
| 1 | 0x3CA/0x3CB |
0x1AF2C |
| 2 | 0x3BD/0x3BE |
0x193CE, the IR path traced below |
| 3 | 0x3AF/0x3B0 |
0x1973C |
| 4 | none | 0x1A8A6 |
All four handlers write the same low-level variables (0xDB8 timer preload, 0x08D
on-time, 0xDBB pattern byte), so all four are IR output renderers, not unrelated
peripherals. The selector therefore looks like an IR encoding class carried in the
config, with four distinct renderers. It is written at four sites: 0x17F4C, 0x18006,
0x1809E, 0x180F0, and cleared at 0x12F8A and 0x13C00.
0x3BD/0x3BE is written exactly once in the whole image, at 0x12F2C, which makes the
dispatcher the only way into the IR path.
Step 2, the IR parameter block at 0x193CE. The handler parses the block that
pointer refers to:
193d0: bd c3 e9 ff MOVFF 0x3bd,FSR0L ; FSR0 = parameter block
193d8: ee cf 00 fd MOVFF POSTINC0,0xd00 ; u16 LE at offset 0
193dc: ed cf 01 fd MOVFF POSTDEC0,0xd01
193e4: d8 90 BCF STATUS,0 ; x 4 (16-bit shift left twice)
193ee: 0a 0e MOVLW 0x0a ; / 10 via the divide at 0x1BAF6
193fc: 7b ec dd f0 CALL 0x1baf6
1940c: 13 08 SUBLW 0x13 ; if q > 19 then q -= 19 else q = 0
19418: 00 cd 8e f0 MOVFF 0xd00,0x08e ; 0x08E = carrier period, in cycles
1941c: ... FSR0 = block + 2
1942c: ef 50 MOVF INDF0,W ; u8 at offset 2
... same x4/10, then "if q > 8 then q -= 8 else q = 0"
19468: 00 cd 8d f0 MOVFF 0xd00,0x08d ; 0x08D = carrier ON time, in cycles
19470: 8e 5f SUBWF 0x8e,B,F ; 0x08E = period - on = OFF time
So the block is:
| Offset | Type | Meaning |
|---|---|---|
| 0 | u16 LE | carrier period |
| 2 | u8 | carrier on-time (duty) |
Both are converted with value * 4 / 10 and then have a fixed loop overhead subtracted
(19 cycles for the period, 8 for the on-time), clamped at zero.
Step 3, conversion to the delay parameter.
19472: 65 0e MOVLW 0x65
19474: d8 80 BSF STATUS,0
19476: 8d 55 SUBFWB 0x8d,B,W ; W = 0x65 - value
19482: 8d 9f BCF 0x8d,B,7 ; (value & 0x7F) << 1
19484: 8d 47 RLNCF 0x8d,B,F
The delay routine at 0x10D00 has exactly 100 NOPs followed by RETURN, and
0x65 = 101, so a parameter of (101 - x) * 2 lands x NOPs from the end and burns
exactly x cycles. The inversion is just sled indexing.
Numeric check. value * 4 / 10 cycles means 4 instruction cycles per unit of 0.1 µs,
so the core runs at 4 MIPS (16 MHz). Testing that against a real carrier: 38 kHz is a
26.3 µs period, so the config would store 263, giving 263 * 4 / 10 = 105 cycles, which
at 4 MIPS is 26.25 µs. That closes, and it confirms both the 0.1 µs storage unit and the
16 MHz clock. The 19-cycle subtraction is the measured overhead of the unrolled
modulator block.
The test behind this paragraph was arithmetic on its own literals until 13 August 2026, and the
correction is recorded because this closure is the one CLAUDE.md cites as the project's model of an
independent numeric check. It asserted 263 * 4 // 10 == 105 and 105 / 4.0 == 26.25, which needs no
firmware, no config and no library: it passed with no lab and would have passed whatever the image
said. All three constants are decoded out of it now, and none of them is a plain literal 4: the
multiplier is a shift count in WREG, MOVLW 0x02 at 0x193E0, consumed by the RLCF pair at
0x193E4; the divisor is the 0x0A at 0x193EE staged into the divide helper; and the overhead is
the SUBLW 0x13 at 0x1940C, with the CLRF after it as the clamp.
The slack is worth stating too, since the paragraph above says "exactly". 26.25 µs is 38095 Hz, not 38000, because a 26.3 µs period cannot be represented in whole units of 0.1 µs and the field carries 263 rather than 263.15. The error is 0.2506%. So the closure is tight to a quarter of a percent rather than exact, and the quantisation is itself part of the evidence for the 0.1 µs unit.
Step 4, the transmit loop at 0x195C6.
195c6: d5 9e BCF T0CON,7 ; stop TMR0
195c8: f2 94 BCF INTCON,2 ; clear TMR0IF
195ca: b9 cd d7 ff MOVFF 0xdb9,TMR0H ; preload = this burst's duration
195ce: b8 cd d6 ff MOVFF 0xdb8,TMR0L
195d2: d5 8e BSF T0CON,7 ; start TMR0
195d6: c1 51 MOVF 0xc1,B,W ; index++
195e2: 05 0e MOVLW 0x05 ; FSR0 = 0x0500 + index
195e4: ef cf bb fd MOVFF INDF0,0xdbb ; fetch pattern byte
195ec: bb cd bf f3 MOVFF 0xdbb,0x3bf ; -> the modulator's enable mask
195f0: 59 df RCALL 0x194a4 ; emit 8 half-cycles
195f2: f2 a4 BTFSS INTCON,2 ; wait for TMR0 overflow
195f4: fe d7 BRA 0x195f2
195f8: ba 07 DECF 0xba,B,F ; repeat 0xDBA times
195fa: e5 e1 BNZ 0x195c6
So the firmware pre-renders the IR signal into a RAM bitmap at data address 0x0500,
one byte per 8 carrier half-cycles, then plays it back timer-paced with TMR0. That
design is why the remote can emit essentially any protocol: the carrier shape is
parameterised (period, duty, per-half-cycle mask) and the envelope is just a bit buffer.
Step 5, the 0x0500 buffer is a ring FIFO. Found by locating every code path that
builds an FSR pointing into RAM page 0x05xx. There are no LFSR FSRn,0x05xx and no
MOVLB 0x5 anywhere; every access is CLRF FSR0H / ADDLW index / MOVWF FSR0L /
MOVLW 0x05 / ADDWFC FSR0H,F.
State variables, all in bank 3:
| Variable | Role |
|---|---|
0x3C1 |
read index (consumer, 0x195D6 and 0x1958A) |
0x3C2 |
write index (producer, 0x131A0) |
0x3C0 |
pending byte count, += 2 by the producer, DECF per byte consumed |
Producer, 0x13194, enqueues two bytes per call:
13196: 8a a1 BTFSS 0x8a,B,0
1319a: 21 ec dd f0 CALL 0x1ba42 ; enter critical section
131a0: c2 51 MOVF 0xc2,B,W ; write index
131a2: c2 2b INCF 0xc2,B,F ; post-increment
131aa: 05 0e MOVLW 0x05 ; FSR0 = 0x0500 + index
131ae: a5 c0 ef ff MOVFF 0x0a5,INDF0 ; store byte 1
131c0: a6 c0 ef ff MOVFF 0x0a6,INDF0 ; store byte 2
131c8: c0 27 ADDWF 0xc0,B,F ; pending += 2
131d0: 1e ec dd f0 CALL 0x1ba3c ; leave critical section
0x1BA42 is BCF INTCON,6 + BCF INTCON,7 (clear PEIE and GIE) and 0x1BA3C is the
matching pair of BSFs, so those are interrupt disable and enable. 0x08A bit 0 is a
"caller already holds the lock" flag, so the guard nests safely.
The two bytes come from 0x0A5/0x0A6, written from the 16-bit argument 0xD00/0xD01
at exactly three sites: 0x18240, 0x18304 and 0x18334. All three sit in the same
0x17E00-0x18400 region that writes the encoding selector 0x08B, so that region is
the IR encoder.
Step 6, the stream format. The consumer at 0x19560 reads a command byte, then
decides how much follows:
1956a: ef cf ba fd MOVFF INDF0,0xdba ; command byte
19570: c0 07 DECF 0xc0,B,F ; pending--
19572: 80 0e MOVLW 0x80
19576: ba 15 ANDWF 0xba,B,W
1957a: 57 e0 BZ 0x1962a ; bit 7 selects a second command form
1957c: 04 0e MOVLW 0x04
1957e: ba 25 ADDWF 0xba,B,W ; required = command + 4
19582: c0 5d SUBWF 0xc0,B,W
19584: 01 e2 BC 0x19588 ; enough buffered? else wait at 0x19712
19598: ef 1c COMF INDF0,W ; TMR0 preload, stored complemented
1959c: b8 6f MOVWF 0xb8,B
So each record is a command byte whose bit 7 picks one of two forms, whose low bits give
the number of pattern bytes that follow (the same 0xDBA that the play loop at 0x195F8
counts down), followed by a 16-bit TMR0 preload stored complemented, because TMR0
counts up to overflow so the preload is the negated duration.
Step 7, and this is the surprise: on arch 14 the config is not memory-mapped.
The encoder gets its data through two accessors, 0x10A46 (one byte, 95 references) and
0x10A5E (two bytes, 45 references). Both begin CALL 0x18DBC and then TBLRD*+. But
0x18DBC is GOTO 0x1B9AC, and:
1b9ac: c9 68 SETF SSP1BUF ; clock out 0xFF to clock a byte in
1b9ae: c7 a0 BTFSS SSP1STAT,0 ; BF, so wait for the byte to arrive
1b9b0: fe d7 BRA 0x1b9ae
1b9b2: c9 50 MOVF SSP1BUF,W ; the byte
and the matching output primitive 0x1B984:
1b984: 9e 96 BCF PIR1,3 ; SSPIF
1b986: c6 9e BCF SSP1CON1,7 ; WCOL
1b988: c6 c3 c9 ff MOVFF 0x3c6,SSP1BUF ; start transfer
1b98c: c6 be BTFSC SSP1CON1,7 ; and check WCOL again afterwards
These listings said SSPBUF, SSPSTAT and SSPCON1 when first published. The registers
and the addresses are unchanged; the part has two synchronous serial ports and the
disassembler now numbers them, so the config flash reads over port 1. See section 18 for
why the register table was rebuilt.
That is the PIC18 hardware MSSP in SPI mode. 0x18CEC is BSF LATF,7 then
BCF LATF,7, so LATF bit 7 is the flash chip select. 0x18D98 shifts
TBLPTRU, TBLPTRH, TBLPTRL out as the three address bytes. And the surrounding code
sends recognisable SPI NOR opcodes: 0x18DC6 sends 0xD8 (64 KiB block erase) and
0x18DD2 sends 0x05 (read status register) followed by a loop polling bit 0, the
write-in-progress bit.
So TBLPTR here is not doing a real program-memory table read. It is being used as a
convenient 24-bit address counter, and TBLRD*+ is used purely because it increments
TBLPTR in one instruction. The value read into TABLAT is discarded.
This independently confirms the arch 12 versus arch 14 split derived in section 3:
| arch 12 (One) | arch 14 (600 / 700) | |
|---|---|---|
| Flash part | Atmel AT49BV322A, parallel NOR | EON F16-100HIP, SPI serial |
| concordance flash ID | 0x1F:0xC8 (manufacturer:device) |
0x15:0x1C (capacity:manufacturer, JEDEC SPI order) |
| Config access | memory-mapped into program space via the external memory bus | byte at a time over hardware SPI |
| Firmware execution | in place from external flash at 0x020000 |
must be copied to internal flash at 0x009000 |
An SPI flash is not executable, so on arch 14 the firmware has to be copied into
internal flash. That is exactly the conclusion the 0x9000 load base forced, arrived at
from a completely different direction. The two agree.
It also explains the accessor design: with no memory mapping, every config byte costs an
SPI transaction, so the firmware streams records through a byte-at-a-time reader and
pre-renders the IR waveform into the 0x0500 ring buffer rather than reading it on
demand during transmission.
0x19486: IR receive timebase¶
19492: d7 68 SETF TMR0H
19494: d6 68 SETF TMR0L
19496: d5 8e BSF T0CON,7 ; start timer
0x1949A (BCF T0CON,7, BCF INTCON,5). This is the
learning-mode edge timing capture.
0x190A6: keypad scan¶
The matrix is 14 rows by 4 columns, rows active low, and the MULLW 0x04 below is what makes
that a reading of the code rather than an inference from a table size. Section 17 records an
attempt to overturn this from an upstream analogy, and why the code wins.
Three row-driver helpers do read-modify-write on a port, preserving the non-matrix bits:
| Helper | Port | Mask | Row lines |
|---|---|---|---|
0x1907E |
PORTE | 0x80 |
bits 0-6, 7 rows |
0x19052 |
PORTA | 0xC7 |
bits 3-5, 3 rows |
0x19068 |
PORTD | 0xF0 |
bits 0-3, 4 rows |
7 + 3 + 4 = 14 row lines. 0x19094 reads the columns and returns 1 to 4. The tests are
BTFSS, which skips the RETLW when the bit is set, so a code is returned for the first
column line found low, consistent with the active-low row drive:
19094: 81 a8 BTFSS PORTB,4
19096: 01 0c RETLW 0x01
19098: 81 aa BTFSS PORTB,5
1909a: 02 0c RETLW 0x02
1909c: 81 ac BTFSS PORTB,6
1909e: 03 0c RETLW 0x03
190a0: 81 ae BTFSS PORTB,7
190a2: 04 0c RETLW 0x04
190a4: 00 0c RETLW 0x00 ; no column active
The row walk builds a one-hot mask by shifting, inverts it, and drives one row low at a
time (group 1 shown, 0x1914E-0x1918C):
19156: 01 0e MOVLW 0x01 ; group 2 uses 0x08 here (PORTA bit 3)
19160: e8 46 RLNCF WREG,F ; shift left `row` times
19162: fe 0b ANDLW 0xfe
19168: e8 1c COMF WREG,W ; invert: active low
1916a: 7f 0b ANDLW 0x7f
1916e: a1 6f MOVWF 0xa1,B
19170: 86 df RCALL 0x1907e ; drive PORTE
19172: 90 df RCALL 0x19094 ; read column
Final code assembly at 0x19274:
19274: 81 50 MOVF PORTB,W ; read to clear the mismatch condition
19278: f2 90 BCF INTCON,0 ; clear RBIF (PORTB interrupt-on-change)
1927c: 01 51 MOVF 0x01,B,W ; row+1, 0 means nothing pressed
1927e: 0d e0 BZ 0x1929a
19282: 01 07 DECF 0x01,B,F ; to 0-based row
19288: 04 0d MULLW 0x04 ; row * 4
1928e: 00 25 ADDWF 0x00,B,W ; + column (1..4)
...
1929a: 00 0e MOVLW 0x00 ; no key
So the scanner returns row * 4 + column, a linear index from 1 to 56, with 0
meaning no key. Columns are detected via PORTB interrupt-on-change, which is how the
remote wakes from sleep on a keypress.
0x19120: hardwired reset key combination¶
Before the normal scan, three specific intersections are probed directly, and one of
them executes the PIC18 RESET instruction. BTFSS skips the RESET when the bit is set,
so the reset fires when PORTB,6 reads low, which in an active-low matrix means the key
is being held:
1911e: 83 94 BCF PORTD,2
19120: 81 ac BTFSS PORTB,6
19122: ff 00 RESET
That is a hardware-level recovery combination, independent of any config. The two
probes before it (PORTE,1 with PORTB,5, and PORTE,4 with PORTB,7) gate whether
the check runs.
0x1B8CE: port initialisation¶
Touches TRISA through TRISG and PORTA through PORTG in one block, near the entry point
at 0x1BB38. This is the pin direction setup, and it is where the definitive pin
assignment can be read off.
This settles the LWJL question¶
It did not, and the conclusion below is wrong. See section 17. The half that holds is the
scanner's native code being a linear 1 to 56 index rather than 0x80 | (row << 3) | col. That
was the right observation, and the mistake was to conclude the config must therefore be using a
different namespace, instead of asking whether the config's codes were being read correctly. They
were not. Under the corrected reading the 600's 162 entries are 54 scan codes from exactly that 1
to 56 range, in three event classes, and no translation layer needs to exist. The original text
follows.
The physical matrix on arch 14 is 14 by 4, so 56 physical key positions, and the
scanner's native code is a linear 1 to 56 index, not 0x80 | (row << 3) | col. The
600's LWJL section lists 108 matrix-style codes and 162 entries in total. Those
cannot both be describing the same thing, so the 600's LWJL is definitively not that
remote's physical key matrix. It is more likely an event-code namespace shared across
the whole arch 14 family.
By contrast the One's LWJL has 52 matrix entries over 7 rows by 8 columns, which is also 56 positions, and does plausibly correspond to real hardware. So the arch 12 and arch 14 LWJL sections genuinely differ in meaning, and there must be a translation somewhere between the scanner's linear index and the event codes the config uses. Finding that translation is now the concrete next step for the button mapping problem.
Section 12 | the archive | section 14. Section 13 of the findings archive, which is frozen; the reference holds the current answer. The archive on GitHub.