本次主要实现红外遥控解码模块的实现,红外模块发送端采用的是HT6221的编码芯片,而在接收端由于红外对管,生成的正好是与发送端电平相反的信号。要实现解码模块程序编写,需先知道协议的过程以及编码的格式,还有模块的输入输出。

1. HT6221介绍

是一款基于红外遥控协议(NEC协议)的遥控编码芯片。一共24个引脚,其PIN定义如下:

When one of the keys (32 or 64 keys) is triggered for over 36ms, the oscillator is enabled and the chip is activated. If the key is pressed and held for 108ms or less, the 108ms transmission codes are enabled and comprised of a header code (9ms), an off code (4.5ms), low byte address codes (9ms~18ms), high byte address codes (9ms~18ms), 8-bit data codes (9ms~18ms), and the inverse codes of the 8-bit data codes (18ms~9ms). After the pressed key is held for 108ms, if the key is still held down, the transmission codes turn out to be a composition of header (9ms) and off codes (2.5ms) only.

To avoid mistakes made by keyboard scanning or simultaneous two-key inputs (except for the three double-key active functions (K21+K22, K21+K23, and K21+K24), the HT6221/HT6222 are facilitated with 36ms starting time. The HT6221/HT6222 also provide three double-key active functions (K21+K22, K21+K23, and K21+K24) for tape deck recording operations.

The double-key operation rules are shown in timing 4 and timing 6. Transmission Codes The transmission codes of the HT6221/HT6222 consist of a 9ms header code, a 4.5ms off code, 16-bit address codes (18ms~36ms), 9ms~18ms 8-bit data codes, and the inverse code of the 8-bit data codes. The following is an illustration of the transmission codes

如上,NEC协议主要时发送9ms的高电平,然后4.5ms的低电平,然后是地址和数据。其中地址和数据的1,0采用PPM编码,即用不同时长的高低电平表示二进制1,0。

2. 红外解码模块设计

模块接口如下,因为实际接收时,接收头接收到的信号后输出的波形刚好与编码产生的波形相反。因此需要decode模块将这个相反的时序识别出来。

1)计数模块

这里需要产生9ms,4.5ms,0.56ms,1.69ms这四个时间点判断,但由于不同硬件电路,晶振,不同实际场景下这个时间可能不会这么精确,因此需要以包含这个时间前后一段范围的时间段进行判断。

2)代码

整个NEC协议,在识别过程中主要是根据上面的时间点判断协议目前在那个状态,如果在数据传输状态则根据高低电平时间判断传输的是1还是0,然后将数据转换后输出。NEC协议只有4个状态,但是在数据传输这个状态下输出和判断信息比较复杂,所以用三段式的状态机实现。

module decoder_top(input clk,rst_n,input iIR,output wire [15:0]irData,output wire [15:0]irAddr,output reg end_flag);reg [19:0]tim_cnt;
reg tim_clear;
reg [3:0]main_state;
parameter IDLE   =4'b0000,ST_high=4'b0001,ST_low =4'b0010,ST_data=4'b0100;reg data_done;
reg [6:0] data_cnt;
reg [31:0]data_r;
assign irAddr=data_r[15:0];
assign irData=data_r[23:16];
/*************************************
parameter time_9ms=20'd900000;
parameter time_4_5ms=20'd450000;
parameter time_0_56ms=20'd56000;
parameter time_1_68ms=20'd168000;
*************************************/reg [1:0]iIR_r;
wire iIR_pos_flag,iIR_neg_flag;
assign iIR_pos_flag = (~iIR_r[1] & iIR_r[0])?1'b1:1'b0;
assign iIR_neg_flag = (iIR_r[1] & (~iIR_r[0]))?1'b1:1'b0;
always@(posedge clk or negedge rst_n)beginif(~rst_n) iIR_r<=0;else beginiIR_r[0]<=iIR;iIR_r[1]<=iIR_r[0];endend    always@(posedge clk or negedge rst_n)beginif(~rst_n) tim_cnt<=0;else if(tim_clear)  tim_cnt<=0;else tim_cnt<=tim_cnt+1'b1;endalways @(posedge clk or negedge rst_n) beginif(~rst_n)beginmain_state<=IDLE;tim_clear<=1;endelse if(tim_cnt<20'd500000) begincase (main_state)IDLE:beginif(iIR_neg_flag) beginmain_state<=ST_high;tim_clear<=1;endelse beginmain_state<=IDLE;tim_clear<=0;endendST_high:beginif (iIR_pos_flag)beginif (tim_cnt>20'd325000 && tim_cnt<20'd495000) beginmain_state<=ST_low;tim_clear<=1;endelse beginmain_state<=IDLE;tim_clear<=0;endendelse beginmain_state<=ST_high;tim_clear<=0;endendST_low:beginif(iIR_neg_flag)beginif(tim_cnt>20'd152500 &&tim_cnt<20'd277500)beginmain_state<=ST_data;tim_clear<=1;endelse beginmain_state<=IDLE;tim_clear<=0;endendelse beginmain_state<=ST_low;tim_clear<=0;endendST_data:beginif(data_done) beginmain_state<=IDLE;tim_clear<=0;endelse if(iIR_pos_flag)beginif(tim_cnt>20'd20000 && tim_cnt<20'd35000)begintim_clear<=1;endelse beginmain_state<=IDLE;tim_clear<=0;endendelse if(iIR_neg_flag)beginif((tim_cnt>20'd20000 && tim_cnt<20'd35000) || (tim_cnt>20'd75000 && tim_cnt<20'd90000))begintim_clear<=1;endelse beginmain_state<=IDLE;tim_clear<=0;endendelse beginmain_state<=ST_data;tim_clear<=0;endendendcaseendendalways @(posedge clk or negedge rst_n)beginif(~rst_n)begindata_done<=0;data_cnt<=0;data_r<=0;end_flag<=0;endelse if (main_state==IDLE)begindata_done<=0;end_flag<=0;data_r<=0;endelse if (main_state==ST_data) beginif(data_cnt==7'd32) begindata_cnt<=0;data_done<=1;end_flag<=1;endelse if(iIR_neg_flag )beginif(tim_cnt>20'd20000 && tim_cnt<20'd35000) data_r[data_cnt]<=0;if(tim_cnt>20'd75000 && tim_cnt<20'd90000) data_r[data_cnt]<=1;data_cnt<=data_cnt+1'b1;endendend
endmodule

实战篇:基于HT6221的红外遥控解码实现相关推荐

  1. 基于FPGA的红外遥控解码与PC串口通信

    基于FPGA的红外遥控解码与PC串口通信 zouxy09@qq.com http://blog.csdn.net/zouxy09 这是我的<电子设计EDA>的课程设计作业(呵呵,这个月都拿 ...

  2. 基于51单片机+红外遥控解码+LCD1602显示

    红外遥控解码(NEC) 基本介绍 什么是红外线? 红外线系统的组成 发射管和接收管 红外遥控发射(载波频率) 重要介绍 NEC协议 数据格式(必看) 位定义(必看) 编写程序思路(2种) 方式一 方式 ...

  3. HT6221红外遥控解码设计

    项目名称 HT6221红外遥控解码设计 具体要求 接收红外按键的数据在ISSP上观察 设计说明 下图为红外遥控器及按键图.红外接收头有三个引脚,电源.地和信号输出. HT6221芯片的红外遥控发送数据 ...

  4. 遥控窗帘c语言程序,基于单片机的红外遥控窗帘设计论文(含c语言源程序) 本科毕业论文(设计).doc...

    基于单片机的红外遥控窗帘设计论文(含c语言源程序) 本科毕业论文(设计) 摘 要 随着电子技术和自动化技术的发展,人们对生活质量的要求越来越高.家用电器产品也在不断的更新换代.从始初的晶体管.到电子管 ...

  5. 遥控窗帘c语言程序,基于单片机的红外遥控窗帘设计论文(含c语言源程序) 本科毕业论文.doc...

    基于单片机的红外遥控窗帘设计论文(含c语言源程序) 本科毕业论文 摘 要 随着电子技术和自动化技术的发展,人们对生活质量的要求越来越高.家用电器产品也在不断的更新换代.从始初的晶体管.到电子管:由模拟 ...

  6. 【电路方案】基于单片机智能市电温度控制系统设计-基于单片机RGB颜色智能识别系统设计-基于单片机四路红外遥控开关电路设计-基于单片机自行车自动防盗报警系统设计-基于单片机智能无线病床呼叫系统设计

    822基于单片机智能无线病床呼叫系统设计-设计资料下载 硬件构成:单片机+最小系统+LCD1602液晶显示模块+无线收发模块+蜂鸣器模块+LED指示灯模块+按键模块 本设计基于STC89C51/52( ...

  7. 深度学习实战篇-基于RNN的中文分词探索

    深度学习实战篇-基于RNN的中文分词探索 近年来,深度学习在人工智能的多个领域取得了显著成绩.微软使用的152层深度神经网络在ImageNet的比赛上斩获多项第一,同时在图像识别中超过了人类的识别水平 ...

  8. 树莓派云音乐c语言,基于树莓派的红外遥控版网易云音乐播放器

    基于树莓派的红外遥控版网易云音乐播放器.下面是遥控键盘示意图: CH- CH CH+ << >> || - + EQ 0 100+ 200+ 1 2 3 4 5 6 7 8 9 ...

  9. linux树莓派网易云音乐,基于树莓派的红外遥控版网易云音乐播放器

    基于树莓派的红外遥控版网易云音乐播放器.下面是遥控键盘示意图: CH- CH CH+ << >> || - + EQ 0 100+ 200+ 1 2 3 4 5 6 7 8 9 ...

最新文章

  1. 32位python-64位Python调用32位DLL方法(一)
  2. 《树莓派开发实战(第2版)》——2.8 利用VNC远程控制树莓派
  3. ML之分类预测:基于sklearn库的七八种机器学习算法利用糖尿病(diabetes)数据集(8→1)实现二分类预测
  4. 微服务间保持事务一致性
  5. PHP 实现获取服务器端IP地址
  6. 安装mysql 5.1 详细步骤
  7. 修改现有站点的主机标头
  8. 直接拿来用!Visual Studio 扩展工具利用 AI 强化你的代码
  9. 抽象类 VS 接口(1)
  10. 微信浪漫告白小程序java_厉害了,微信小程序可以这样表白,还怕他(她)拒绝你?...
  11. 一次 注册dll失败 的经历
  12. 利用npm bin创建可执行命令实现项目代码规范自动化
  13. 一次提交却发起了多次请求的一种可能的原因
  14. 王峻涛:大萧条中的机会
  15. 《三国塔防》为什么成功?
  16. 第11课:JSP指令 Include指令 Taglib指令 (JSP教程 JSP入门实战教程 黄菊华Java网站开发系列教程)
  17. 如何解决计算机黑屏问题,电脑黑屏怎么处理(三个键教您解决黑屏问题)
  18. 嵌入式系统之新建工程模版
  19. OFBIZ分享:如何让OFBIZ使用中文界面
  20. 证明:gcd(m,n)=gcd(n mod m,m)成立,m,n为正整数,m>0. 【Euclid算法证明】

热门文章

  1. Filebeat快速入门
  2. 计算机网络结课答辩,计算机网络技术结课论文.doc
  3. 免费数据集下载(持续更新中...)
  4. 阿里为何成立芯片公司,并取名平头哥?如何应对挑战?阿里CTO这样说
  5. python对市场营销的认识和理解_我对市场营销的认识
  6. LCD显示屏和LED显示屏的区别,LCD液晶屏与LED显示屏什么区别
  7. Android(12)浅析 偏好设置 Preference(一)
  8. 办公桌子和椅子的选择和注意点
  9. 齐志科技双层跳板机登陆机制v3.3.6 --shell脚本自动登陆实现
  10. 将图片快速批量转化成PDF格式文件