NEC红外传输协议(中英文)

NEC Protocol

The NEC IR transmission protocol uses pulse distance encoding of the message bits. Each pulse burst (mark – RC transmitter ON) is 562.5µs in length, at a carrier frequency of 38kHz (26.3µs). Logical bits are transmitted as follows:
Logical ‘0’ – a 562.5µs pulse burst followed by a 562.5µs space, with a total transmit time of 1.125ms
Logical ‘1’ – a 562.5µs pulse burst followed by a 1.6875ms space, with a total transmit time of 2.25ms

翻译:
NEC 红外传输协议是通过控制脉冲宽度实现信息位传送,每个脉冲高电平(标注:RC发射器开启)的宽度为562.5微秒,通过38KHz的负载波发送出去。各个逻辑位按如下方式传送:
逻辑“0”–一个562.5微秒高电平脉冲后紧跟一个562.5微秒低电平脉冲,总传输时间为1.125毫秒。
逻辑“1”–一个562.5微秒高电平脉冲后紧跟一个1.6875毫秒低电平脉冲,总传输时间为2.25毫秒。
在这里插入图片描述

When transmitting or receiving remote control codes using the NEC IR transmission protocol, the WB_IRRC performs optimally when the carrier frequency (used for modulation/demodulation) is set to 38.222kHz.

When a key is pressed on the remote controller, the message transmitted consists of the following, in order:
■ a 9ms leading pulse burst (16 times the pulse burst length used for a logical data bit)
■ a 4.5ms space
■ the 8-bit address for the receiving device
■ the 8-bit logical inverse of the address
■ the 8-bit command
■ the 8-bit logical inverse of the command
■ a final 562.5µs pulse burst to signify the end of message transmission.

The four bytes of data bits are each sent least significant bit first. Figure 1 illustrates the format of an NEC IR transmission frame, for an address of 00h (00000000b) and a command of ADh (10101101b).

翻译:
当使用NEC IR传输协议发送或接收远程控制代码时,当载波频率(用于调制/解调)被设置为38.222kHz时,使用WB_IRRC效果最佳。

当在遥控器上按下一个键时,发送的消息由以下部分组成,顺序如下:
■ 一个9ms的高电平引导脉冲(脉冲宽度为逻辑数据位的16倍)
■ 一个4.5ms的低电平
■ 8位设备地址
■ 8位设备地址反码
■ 8位命令
■ 8位命令反码
■ 最后以一个562.5微秒高电平脉冲表示信息传输结束。

这四个字节的数据位都是先发送最低有效位,图1说明了地址为00h (00000000b)和命令为ADh (10101101b)的NEC IR传输帧的格式。
在这里插入图片描述

Figure 1. Example message frame using the NEC IR transmission protocol.
Notice from Figure 1 that it takes:
■ 27ms to transmit both the 16 bits for the address (address + inverse) and the 16 bits for the command (command + inverse). This comes from each of the 16 bit blocks ultimately containing eight '0’s and eight '1’s - giving (8 * 1.125ms) + (8 * 2.25ms).
■ 67.5ms to fully transmit the message frame (discounting the final 562.5µs pulse burst that signifies the end of message).

翻译:
图1所示,例子中的信息帧使用NEC IR传输协议。
从图1中可以注意到:
■ 27毫秒内传输了16位地址(地址码+地址反码)和16位命令(命令码+命令反码)。这样可以知道每个16位信息块最终包含8个 '0’位和8个 '1’位—得出(8 * 1.125ms) + (8 * 2.25ms)。
■ 一个消息帧长度为67.5毫秒(扣除表示消息结束的最后562.5微秒高电平脉冲时间)。

REPEAT CODES
If the key on the remote controller is kept depressed, a repeat code will be issued, typically around 40ms after the pulse burst that signified the end of the message. A repeat code will continue to be sent out at 108ms intervals, until the key is finally released. The repeat code consists of the following, in order:
■ a 9ms leading pulse burst
■ a 2.25ms space
■ a 562.5µs pulse burst to mark the end of the space (and hence end of the transmitted repeat code).

翻译:
如果遥控器上的按键一直按下,一个重复代码就会被发出,通常是在消息结束脉冲发射40毫秒之后。重复代码将继续以108ms的间隔发送,直到按键最终被释放。重复代码由以下部分组成,顺序如下:
■ 一个9毫秒高电平引导脉冲
■ 一个2.25毫秒低电平脉冲
■ 一个562.5微秒高电平脉冲结束标志(结束了重复码传输)。

在这里插入图片描述

Figure 2 illustrates the transmission of two repeat codes after an initial message frame is sent.

翻译:
图2说明了发送初始消息帧后两个重复码的传输。
在这里插入图片描述
Figure 2. Example repeat codes sent for a key held down on the transmitting remote controller.

翻译:
图2为红外遥发射器一个按键一直被按下发送重复码的例子。

树莓派python示例代码:

#!/usr/bin/python
# -*- coding:utf-8 -*-
import RPi.GPIO as GPIO
import time
ERROR = 0xFE
PIN = 18     #定义红外接收器引脚
 
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(PIN, GPIO.IN, GPIO.PUD_UP)   #设置红外接收引脚为上拉模式
 
def getKey():                       
    byte = [0, 0, 0, 0]
    if IRStart() == False:      #判断红外引导脉冲
        time.sleep(0.11)        # One message frame lasts 108 ms.
        return ERROR
    else:
        for i in range(0, 4):
                byte[i] = getByte()  #接收32位红外数据(地址、地址反码、数据、数据反码)
        if byte[0] + byte[1] == 0xff and byte[2] + byte[3] == 0xff:  #校验接收数据是否正确
            return byte[2]
        else:
            return ERROR
	#return byte[2]
def IRStart():     #判断红外引导脉冲
    timeFallingEdge = [0, 0]
    timeRisingEdge = 0
    timeSpan = [0, 0]
    #通过脉冲上升沿和下降沿读取脉冲时间
    GPIO.wait_for_edge(PIN, GPIO.FALLING)
    timeFallingEdge[0] = time.time()
    GPIO.wait_for_edge(PIN, GPIO.RISING)
    timeRisingEdge = time.time()
    GPIO.wait_for_edge(PIN, GPIO.FALLING)
    timeFallingEdge[1] = time.time()
    
    timeSpan[0] = timeRisingEdge - timeFallingEdge[0]  #第一个脉冲时间
    timeSpan[1] = timeFallingEdge[1] - timeRisingEdge  #第二个脉冲时间
    if timeSpan[0] > 0.0085 and \       #判断第一个和第二个脉冲是否是红外引导脉冲
       timeSpan[0] < 0.0095 and \
       timeSpan[1] > 0.004 and \
       timeSpan[1] < 0.005:
        return True
    else:
        return False
def getByte():   #接收32位红外数据(地址、地址反码、数据、数据反码)
    byte = 0
    timeRisingEdge = 0
    timeFallingEdge = 0
    timeSpan = 0
    for i in range(0, 8):
        #通过脉冲上升沿和下降沿读取脉冲时间
        GPIO.wait_for_edge(PIN, GPIO.RISING)
        timeRisingEdge = time.time()
        GPIO.wait_for_edge(PIN, GPIO.FALLING)
        timeFallingEdge = time.time()
        
        timeSpan = timeFallingEdge - timeRisingEdge   #读取脉冲时间
        if timeSpan > 0.0016 and timeSpan < 0.0018:   #判断脉冲是否为代表1
            byte |= 1 << i
    return byte
print('IRM Test Start ...')
try:
    while True:
        key = getKey()     #读取红外脉冲
        if(key != ERROR):  #打印红外脉冲值
            print("Get the key: 0x%02x" %key)
except KeyboardInterrupt:
    GPIO.cleanup()

end!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值