找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2744|回复: 0
打印 上一主题 下一主题
收起左侧

关于stc15单片机 为什么红外遥控按了没反应,8位数码管就都显示0

[复制链接]
跳转到指定楼层
楼主
ID:256174 发表于 2017-12-26 15:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
10黑币
求助各为大神,帮忙分析下这个程序,为什么红外遥控按了没反应,8位数码管就都显示0


  1. #include <stc15.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int

  4. uchar code led_xs[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xA7,0xA1,0x86,0x8E};
  5. uchar code led_wei[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F};
  6. uchar t;

  7. sbit IR=P3^2;

  8. bit irok;//红外接收完标志位
  9. bit ieok;//红外处理完标志位

  10. uchar Ir_cd[4];
  11. uchar Ir_data[33];

  12. void iint();//设置准双向口
  13. void init();//外部中断0初始化
  14. void intt();//定时器0初始化
  15. void hwjmcl(); //红外解码处理
  16. void hwmzzh();//红外码值转换处理显示
  17. void delay(uint t);

  18. void main()
  19. {
  20.         intt();//设置准双向口
  21.         iint();//外部中断0初始化
  22.         init();//定时器0初始化
  23.         while(1)
  24.         {
  25.                 if(irok)  
  26.                 {
  27.                         irok=0;  
  28.                         ET0=0;   //禁止定时器0中断
  29.                         hwjmcl();//红外解码处理
  30.                 }
  31.                 if(ieok)   
  32.                 {
  33.                         ieok=0;
  34.                 }
  35.                 hwmzzh();  //红外码值转换处理显示
  36.         }
  37. }

  38. void hwjmcl()  //红外解码处理
  39. {
  40.         uchar i,j,k=1,value=0;
  41.         for(i=0;i<4;i++)   
  42.         {
  43.                 for(j=0;j<8;j++)   
  44.                 {
  45.                         value>>=1;        
  46.                         if(Ir_data[k]>6)
  47.                         {               
  48.                                 value|=0x80;  
  49.                         }
  50.                         k++;
  51.                 }
  52.                 Ir_cd[i]=value;  
  53.         }
  54.         ieok=1;            
  55. }

  56. void hwmzzh()  //红外码值转换处理显示
  57. {
  58.         P2=led_xs[Ir_cd[0]/16];      
  59.         P0=led_wei[0];delay(1);P0=0xFF;
  60.         P2=led_xs[Ir_cd[0]%16];
  61.         P0=led_wei[1];delay(1);P0=0xFF;
  62.         
  63.         P2=led_xs[Ir_cd[1]/16];      
  64.         P0=led_wei[2];delay(1);P0=0xFF;
  65.         P2=led_xs[Ir_cd[1]%16];
  66.         P0=led_wei[3];delay(1);P0=0xFF;
  67.         
  68.         P2=led_xs[Ir_cd[2]/16];        
  69.         P0=led_wei[4];delay(1);P0=0xFF;
  70.         P2=led_xs[Ir_cd[2]%16];
  71.         P0=led_wei[5];delay(1);P0=0xFF;
  72.         
  73.         P2=led_xs[Ir_cd[3]/16];      
  74.         P0=led_wei[6];delay(1);P0=0xFF;
  75.         P2=led_xs[Ir_cd[3]%16];
  76.         P0=led_wei[7];delay(1);P0=0xFF;
  77. }        

  78. void time_0(void) interrupt 1 //定时器0中断服务函数
  79. {
  80.         t++;
  81. }

  82. void INT_0(void) interrupt 0 //外部中断0服务函数
  83. {
  84.         static uchar i;
  85.         static bit flag;
  86.         ET0=1;         
  87.         if(t>35)        
  88.         {
  89.                 flag=1;      
  90.                 i=0;        
  91.         }
  92.         if(flag)        
  93.         {
  94.                 Ir_data[i]=t;
  95.                 i++;           
  96.                 t=0;           
  97.                 if(i>=33)
  98.                 {
  99.                         i=0;
  100.                         flag=0;
  101.                         irok=1;
  102.                 }
  103.         }
  104. }

  105. void delay(uint t)
  106. {
  107.         uint i,j;
  108.         for(i=t;i<50;i++)
  109.                 for(j=25;j>0;j--);
  110. }

  111. void init()
  112. {
  113.         TMOD&=0xF0;
  114.         TMOD|=0x02;
  115.         TH0=0;
  116.         TL0=0;
  117.         TR0=1;
  118. }

  119. void iint()
  120. {
  121.         IT0=1;
  122.         EX0=1;
  123.         EA=1;
  124. }

  125. void intt()
  126. {
  127.         P0M0=0;P0M1=0;
  128.         P1M0=0;P1M1=0;
  129.         P2M0=0;P2M1=0;
  130.         P3M0=0;P3M1=0;
  131.         P4M0=0;P4M1=0;
  132.         P5M0=0;P5M1=0;
  133. }
复制代码

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表