转自:http://coopermaa2nd.blogspot.com/2010/01/nec-ir-protocol.html
和http://www.sbprojects.com/knowledge/ir/nec.php
紅外線遙控原理
紅外線是目前最常見的一種無線通訊,普遍使用在家電以及玩具產品,如電視、音響、錄放影機、冷氣機、DVD、MP3 Player、遙控車等。紅外線遙控之所以被大量採使用,主要是因為紅外線裝置體積小、成本低、耗電少及硬體設計容易。下圖是紅外線發射器 (Transmitter 或稱 IR LED) 和接收器 (Receiver) 常見外觀,一般來說,紅外線遙控系統由發射器和接收器這兩部份組成。
紅外線是不可見光,其實生活中充滿了紅外線,只是我們看不到。紅外線主要來自太陽,不過很多物體也會發射紅外線,例如燈泡、蠟燭、中央空調等,甚至人體也會散發紅外線。人體所發出的紅外線的量是可以偵測的,耳溫槍就是利用這個道理測量人的體溫。有這麼多紅外線光源,當然會對遙控造成干擾,所以得做一些預防措施確保通訊正確。
避免干擾的解藥是 Modulation。我們講話速度若適當,不徐不急,聽得舒服,聽者自然不漏接。相同的道理,利用 Modulation 讓 IR LED 以特定的頻率閃爍,Receiver 端也調整到同樣的頻率,便可以忽略干擾。在上圖中,可以看到調變訊號 (Modulated signal)在驅動 IR LED 發射訊號,而偵測到的訊號則從右手邊的 receiver 跑出來。
在 Serial 通訊中常會提到 mark 和 space 狀態。space 是紅外線的預設訊號,Transmitter 處於 off 狀態,這時 IR LED 不會發射光亮;而在 mark 狀態 IR LED 會以特定的頻率送出 on/off 脈衝 (Pulse)。消費電子一般使用 30kHz 到 60kHz 的頻率。
兩點注意事項:
- 因為 Receiver 會把訊號反向,所以從 Receiver 這端來看,space 意味著 high level 訊號輸出,而 mark 則是 low level 訊號輸出。
- 要特別注意 mark 跟 space 並非我們要傳輸的 1 與 0 數位訊號。mark 跟 space 以及 1 與 0 之間的關係是由所用的 protocol 決定的。目前 IR Protocol 有相當多種,如 NEC, Phlips RC5, RC6, RC-MM, Toshiba, Sharp, JVC, Sony SIRC 等。
NEC IR Protocol
Features
NEC format 特點摘要如下,詳細後述:
- 8-bit Custom Code 與 8-bit Data Code
- 38kHz 的 Carrier freqeuncy
- 使用 PPM (Pulse Position Modulation)
- Bit time 為 1.125ms 和 2.25ms
Protocol
如下圖,NEC format 由 Leader code, 8-bit Custom Code, 8-bit Data Code 組成。Leader code 包含 9ms 載波 (carrier waveform) 和 4.5ms 的 OFF waveform。Custom Code 和 Data Code 各傳輸兩次,第二次是反向後的結果,目的是讓 Receiver 驗證資料。如果不在乎可靠性,可以不要做反相,Custom Code 和 Data Code 便可以擴展成為 16-bit。
Bit data format:
- 560us 的 Pulse 加上 1690us 的 space 共計 2.25ms 的波形代表 1
- 560us 的 Pulse 加上 560us 的 space 共計 1.12ms 的波形代表 0
Pulse 係由很多 on/off 交替的訊號所組成:
- Carrier frequency = 38kHz
- duty factor = 1/3
- period = 26.5us
按著遙控器按鈕不放,會發出連發指令。連發指令有兩種形式,一種是每次都發射送同樣的 code,好處是可以避免干擾,缺點是耗電。另一種是在送出正常指令的 code 後緊接著只傳送簡短的 Repeat code:
Repeat code 由 9ms 載波 (carrier waveform) 和 2.25ms 的 space 以及一個 560us Pulse 組成:
NEC Protocol
To my knowledge the protocol I describe here was developed by NEC. I've seen very similar protocol descriptions on the internet, and there the protocol is called Japanese Format.
I do admit that I don't know exactly who developed it. What I do know is that it is used in my late VCR produced by Sanyo and was marketed under the name of Fisher. NEC manufactured the remote control IC.
This description was taken from the VCR's service manual. Those were the days, when service manuals were fulled with useful information!
Features
- 8 bit address and 8 bit command length
- Address and command are transmitted twice for reliability
- Pulse distance modulation
- Carrier frequency of 38kHz
- Bit time of 1.125ms or 2.25ms
Modulation
The NEC protocol uses pulse distance encoding of the bits. Each pulse is a 560µs long 38kHz carrier burst (about 21 cycles). A logical "1" takes 2.25ms to transmit, while a logical "0" is only half of that, being 1.125ms. The recommended carrier duty-cycle is 1/4 or 1/3.
Protocol

The picture above shows a typical pulse train of the NEC protocol. With this protocol the LSB is transmitted first. In this case Address $59 and Command $16 is transmitted. A message is started by a 9ms AGC burst, which was used to set the gain of the earlier IR receivers. This AGC burst is then followed by a 4.5ms space, which is then followed by the Address and Command. Address and Command are transmitted twice. The second time all bits are inverted and can be used for verification of the received message. The total transmission time is constant because every bit is repeated with its inverted length. If you're not interested in this reliability you can ignore the inverted values, or you can expand the Address and Command to 16 bits each!

A command is transmitted only once, even when the key on the remote control remains pressed. Every 110ms a repeat code is transmitted for as long as the key remains down. This repeat code is simply a 9ms AGC pulse followed by a 2.25ms space and a 560µs burst.

Extended NEC protocol
The NEC protocol is so widely used that soon all possible addresses were used up. By sacrificing the address redundancy the address range was extended from 256 possible values to approximately 65000 different values. This way the address range was extended from 8 bits to 16 bits without changing any other property of the protocol.
By extending the address range this way the total message time is no longer constant. It now depends on the total number of 1's and 0's in the message. If you want to keep the total message time constant you'll have to make sure the number 1's in the address field is 8 (it automatically means that the number of 0's is also 8). This will reduce the maximum number of different addresses to just about 13000.
The command redundancy is still preserved. Therefore each address can still handle 256 different commands.

Keep in mind that 256 address values of the extended protocol are invalid because they are in fact normal NEC protocol addresses. Whenever the low byte is the exact inverse of the high byte it is not a valid extended address.
External Links
Example Commands
The table below lists the messages sent by the remote control of my late Fisher 530 VCR (it served us well during its 20 years long life).
| NEC Message | Key Function |
| $68-$00 | Play |
| $68-$01 | Rec |
| $68-$02 | Audio Dub |
| $68-$03 | Frame Adv |
| $68-$04 | Slow |
| $68-$05 | Quick |
| $68-$06 | Cue |
| $68-$07 | Review |
| $68-$08 | FF |
| $68-$09 | Rew |
| $68-$0A | Stop |
| $68-$0B | Pause/Still |
| $68-$0C | Up key |
| $68-$1E | Down key |
1813

被折叠的 条评论
为什么被折叠?



