找回密码
 立即注册

QQ登录

只需一步,快速开始

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

lcd12864红外解码波形显示程序 diy制作

  [复制链接]
跳转到指定楼层
楼主
程序代码:

  1. /*******************************************************
  2.        "长沙太阳人"杯红外波形显示单片机设计大赛

  3.     程序名称:红外波形显示         程序设计人:汪建               
  4.    
  5.     硬件设计人:沈强               视频图片记录人:滕建
  6.    
  7.     设计日期:2015.6.3              版本:V1.0
  8. ********************************************************/
  9. #include
  10. #include
  11. #include
  12. #include"Beep.h"
  13. #include"LCD12864.h"
  14. #include"MacroAndConst.h"
  15. #include"InfraredRemoteControl.h"

  16. unsigned char ir_code[4];       /*遥控接收数据*/
  17. unsigned char ir_code_B_1[8];   //红外解码二进制形式(数据码)
  18. unsigned char ir_code_B_0[8];   //红外解码二进制形式(数据反码)

  19. //独立按键定义
  20. sbit Key_In     = P1^0;         //进入系统        
  21. sbit Key_Out    = P1^1;         //退出系统  
  22. sbit Key_Adjust = P1^2;         //调整界面
  23. sbit Key_Switch = P1^3;         //调整切换键
  24. sbit Key_Up     = P1^4;         //幅度、脉宽(增大)移动(上或右)
  25. sbit Key_Down   = P1^5;         //幅度、脉宽(减小)移动(下或左)

  26. unsigned char code num_to_char[]={"0123456789ABCDEF"}; /*数字转换为ASCII字符码*/

  27. bit System_in_flag,System_Adjust_flag; //进入系统、退出系统标志位
  28. unsigned char Switch_Num;  //转换按键次数
  29. unsigned char X0_Value=5;  //x坐标的初始化      
  30. unsigned char X0;          //定义坐标x
  31. unsigned char Y0=58;       //波形下限的所在位置(初始)
  32. unsigned char Y0_0=32;     //波形上限的所在位置(初始)
  33. unsigned char x0_0=2;      //波形的间隔的初始化
  34. unsigned char x0_0_1=5;    //Bit'0'的脉宽初始化
  35. unsigned char x1_1_1=10;   //Bit'1'的脉宽初始化

  36. void Delay_M(unsigned int a)                        //主函数延时函数 1MS/次
  37. {        
  38.         uchar i;
  39.         while(--a!=0)
  40.         {               
  41.            for(i=0;i<125;i++);
  42.         }                                    
  43. }
  44. void Decode_ir_code_1(unsigned char ir_code)    //用户数据码转换为二进制
  45. {
  46.    unsigned char ir_code_D_1;
  47.    ir_code_D_1=ir_code/0x10*16+ir_code%0x10;
  48.    ir_code_B_1[0]=ir_code_D_1%128%64%32%16%8%4%2;
  49.    ir_code_B_1[1]=ir_code_D_1%128%64%32%16%8%4/2;
  50.    ir_code_B_1[2]=ir_code_D_1%128%64%32%16%8/4;
  51.    ir_code_B_1[3]=ir_code_D_1%128%64%32%16/8;
  52.    ir_code_B_1[4]=ir_code_D_1%128%64%32/16;
  53.    ir_code_B_1[5]=ir_code_D_1%128%64/32;
  54.    ir_code_B_1[6]=ir_code_D_1%128/64;
  55.    ir_code_B_1[7]=ir_code_D_1/128;
  56. }
  57. void Decode_ir_code_0(unsigned char ir_code)    //用户数据反码转换为二进制
  58. {
  59.    unsigned char ir_code_D_0;
  60.    ir_code_D_0=ir_code/0x10*16+ir_code%0x10;
  61.    ir_code_B_0[0]=ir_code_D_0%128%64%32%16%8%4%2;
  62.    ir_code_B_0[1]=ir_code_D_0%128%64%32%16%8%4/2;
  63.    ir_code_B_0[2]=ir_code_D_0%128%64%32%16%8/4;
  64.    ir_code_B_0[3]=ir_code_D_0%128%64%32%16/8;
  65.    ir_code_B_0[4]=ir_code_D_0%128%64%32/16;
  66.    ir_code_B_0[5]=ir_code_D_0%128%64/32;
  67.    ir_code_B_0[6]=ir_code_D_0%128/64;
  68.    ir_code_B_0[7]=ir_code_D_0/128;
  69. }
  70. void Draw_Bit_0(unsigned char X0,unsigned char x0_0,unsigned char x0_0_1,unsigned char Y0,unsigned char Y0_0)              //比特0显示
  71. {
  72.   Lcd12864DrawLineX_f(X0,X0+x0_0,Y0,1);
  73.   Lcd12864DrawLineY_f(X0+x0_0,Y0_0,Y0-1,1);
  74.   Lcd12864DrawLineX_f(X0+x0_0+1,X0+x0_0_1,Y0_0,1);
  75.   Lcd12864DrawLineY_f(X0+x0_0_1,Y0_0,Y0,1);
  76. }
  77. void Draw_Bit_1(unsigned char X0,unsigned char x0_0,unsigned char x1_1_1,unsigned char Y0,unsigned char Y0_0)              //比特1显示
  78. {
  79.   Lcd12864DrawLineX_f(X0,X0+x0_0,Y0,1);
  80.   Lcd12864DrawLineY_f(X0+x0_0,Y0_0,Y0-1,1);
  81.   Lcd12864DrawLineX_f(X0+x0_0+1,X0+x1_1_1,Y0_0,1);
  82.   Lcd12864DrawLineY_f(X0+x1_1_1,Y0_0+1,Y0,1);
  83. }
  84. void Display_Interface_One(void)   //显示界面Ⅰ
  85. {
  86.     LCD12864_COM_Write(0x80);
  87.     LCD12864_WRITE_SWord("■红外波形显示■");  
  88.     LCD12864_COM_Write(0x90);
  89.     LCD12864_WRITE_SWord("原码: ");
  90.     LCD12864_COM_Write(0x94);
  91.     LCD12864_WRITE_SWord("反码: ");
  92.     LCD12864_COM_Write(0x88);
  93.     LCD12864_WRITE_SWord("用户识别码: ");
  94.     LCD12864_COM_Write(0x8f);
  95.     LCD12864_WRITE_SWord("■");
  96.     LCD12864_COM_Write(0x98);
  97.     LCD12864_WRITE_SWord("用户按键值: ");
  98.     LCD12864_COM_Write(0x9f);
  99.     LCD12864_WRITE_SWord("■");
  100. }
  101. void InfrareRemote_Display(void)                      //红外接收显示
  102. {
  103.     LCD12864_COM_Write(0x93);
  104.     LCD12864_Data_Write(num_to_char[ir_code[1]/0x10]);//用户数据码
  105.     LCD12864_Data_Write(num_to_char[ir_code[1]%0x10]);
  106.     LCD12864_COM_Write(0x97);
  107.     LCD12864_Data_Write(num_to_char[ir_code[0]/0x10]);//用户数据反码
  108.     LCD12864_Data_Write(num_to_char[ir_code[0]%0x10]);
  109.     LCD12864_COM_Write(0x8e);
  110.     LCD12864_Data_Write(num_to_char[ir_code[2]/0x10]);//用户识别码
  111.     LCD12864_Data_Write(num_to_char[ir_code[2]%0x10]);
  112.     LCD12864_COM_Write(0x9e);                         //用户按键值(十进制形式)
  113.     LCD12864_Data_Write(num_to_char[(ir_code[1]/0x10*16+ir_code[1]%0x10)/10]);
  114.     LCD12864_Data_Write(num_to_char[(ir_code[1]/0x10*16+ir_code[1]%0x10)%10]);
  115. }
  116. void Draw_Coordinate(void)           //坐标显示函数
  117. {
  118.    unsigned char i,Y0,X0;
  119.    X0=3,Y0=60;                      //x坐标和y坐标的初始化
  120.    /*波形坐标显示*/
  121.    Lcd12864DrawLineY_f(1,0,63,1);   //第1列
  122.    Lcd12864DrawLineX_f(0,127,62,1); //第62行
  123.    Lcd12864_DrawPoint_f(0,1,1);     //箭头点显示
  124.    Lcd12864_DrawPoint_f(2,1,1);
  125.    Lcd12864_DrawPoint_f(126,61,1);
  126.    Lcd12864_DrawPoint_f(126,63,1);
  127.    for(i=0;i<=28;i++)                 //y坐标标尺
  128.       {
  129.         Lcd12864_DrawPoint_f(2,Y0,1);
  130.         Y0=Y0-2;
  131.       }
  132.    for(i=0;i<=60;i++)                 //x坐标标尺
  133.       {
  134.         Lcd12864_DrawPoint_f(X0,61,1);
  135.         X0=X0+2;
  136.       }
  137. }
  138. void Display_Interface_Two(void)   //显示界面Ⅱ(用户数据码波形显示)
  139. {  
  140.    unsigned char i;
  141.    Draw_Coordinate();              //坐标显示
  142.    X0=X0_Value;
  143.    for(i=0;i<=7;i++)
  144.       {
  145.         if(ir_code_B_1[i]==1)      //Bit 1
  146.           {
  147.            Draw_Bit_1(X0,x0_0,x1_1_1,Y0,Y0_0);
  148.            X0=X0+x1_1_1;
  149.           }
  150.         if(ir_code_B_1[i]==0)      //Bit 0
  151.           {
  152.            Draw_Bit_0(X0,x0_0,x0_0_1,Y0,Y0_0);
  153.            X0=X0+x0_0_1;
  154.           }  
  155.      }
  156.   LCD12864_COM_Write(0x81);        //显示用户数据码(二进制)
  157.   for(i=0;i<=7;i++)
  158.    {
  159.      LCD12864_Data_Write(num_to_char[ir_code_B_1[i]]);
  160.    }
  161.   LCD12864_Data_Write(num_to_char[11]); //'B'
  162. }
  163. void Display_Interface_Three(void) //显示界面Ⅲ(用户数据反码波形显示)
  164. {
  165.    unsigned char i;
  166.    Draw_Coordinate();              //坐标显示
  167.    X0=X0_Value;                    //坐标的初始化
  168.    for(i=0;i<=7;i++)
  169.       {
  170.         if(ir_code_B_0[i]==1)      //Bit 1
  171.           {
  172.            Draw_Bit_1(X0,x0_0,x1_1_1,Y0,Y0_0);
  173.            X0=X0+x1_1_1;
  174.           }
  175.         if(ir_code_B_0[i]==0)      //Bit 0
  176.           {
  177.            Draw_Bit_0(X0,x0_0,x0_0_1,Y0,Y0_0);
  178.            X0=X0+x0_0_1;
  179.           }  
  180.      }
  181.   LCD12864_COM_Write(0x81);       //显示用户数据反码(二进制)
  182.   for(i=0;i<=7;i++)
  183.    {
  184.      LCD12864_Data_Write(num_to_char[ir_code_B_0[i]]);
  185.    }
  186.   LCD12864_Data_Write(num_to_char[11]); //'B'
  187. }
  188. void Screen_Adjust(void)    //画面调整函数(波形的调整)
  189. {
  190.   if(Key_Switch==0)
  191.          {
  192.            Delay_M(5);           //延时消抖
  193.            if(Key_Switch==0)
  194.            while(!Key_Adjust);   //等待按键松开
  195.            Switch_Num++;         //转换按键次数增加
  196.            if(Switch_Num==5)
  197.              Switch_Num=1;
  198.            Beep_key();           //按键音
  199.          }
  200.   switch(Switch_Num)         //调整内容
  201.          {
  202.            case 1:LCD12864_COM_Write(0x86);
  203.                   LCD12864_WRITE_SWord("调幅");break;
  204.            case 2:LCD12864_COM_Write(0x86);
  205.                   LCD12864_WRITE_SWord("调宽");break;
  206.            case 3:LCD12864_COM_Write(0x86);
  207.                   LCD12864_WRITE_SWord("↑↓");break;
  208.            case 4:LCD12864_COM_Write(0x86);
  209.                   LCD12864_WRITE_SWord("→←");break;
  210.         }
  211.   if(Switch_Num==1)               //波形调幅
  212.           {
  213.             if(Key_Up==0)             //加
  214.               {
  215.                 Delay_M(5);
  216.                 if(Key_Up==0)
  217.                 while(!Key_Up);
  218.                 Beep_key();           //按键音
  219.                 CLR_GD_RAM();         //清除绘图RAM(上次)
  220.                 Y0_0--;
  221.               }
  222.             if(Key_Down==0)            //减
  223.               {
  224.                 Delay_M(5);
  225.                 if(Key_Down==0)
  226.                 while(!Key_Down);
  227.                 Beep_key();           //按键音
  228.                 CLR_GD_RAM();         //清除绘图RAM(上次)
  229.                 Y0_0++;
  230.               }
  231.           }
  232.    if(Switch_Num==2)              //波形调宽
  233.           {
  234.             if(Key_Up==0)             //宽
  235.               {
  236.                 Delay_M(5);
  237.                 if(Key_Up==0)
  238.                 while(!Key_Up);
  239.                 Beep_key();           //按键音
  240.                 CLR_GD_RAM();         //清除绘图RAM(上次)
  241.                 x0_0++;
  242.                 x0_0_1=x0_0_1+2;
  243.                 x1_1_1=x1_1_1+2;
  244.               }
  245.             if(Key_Down==0)           //窄
  246.               {
  247.                 Delay_M(5);
  248.                 if(Key_Down==0)
  249.                 while(!Key_Down);
  250.                 Beep_key();           //按键音
  251.                 CLR_GD_RAM();         //清除绘图RAM(上次)
  252.                 x0_0--;
  253.                 x0_0_1=x0_0_1-2;
  254.                 x1_1_1=x1_1_1-2;
  255.               }
  256.           }
  257.    if(Switch_Num==3)              //波形移动(上下)
  258.           {
  259.             if(Key_Up==0)             //上
  260.               {
  261.                 Delay_M(5);
  262.                 if(Key_Up==0)
  263.                 while(!Key_Up);
  264.                 Beep_key();           //按键音
  265.                 CLR_GD_RAM();         //清除绘图RAM(上次)
  266.                 Y0_0--;
  267.                 Y0--;
  268.               }
  269.             if(Key_Down==0)           //下
  270.               {
  271.                 Delay_M(5);
  272.                 if(Key_Down==0)
  273.                 while(!Key_Down);
  274.                 Beep_key();           //按键音
  275.                 CLR_GD_RAM();         //清除绘图RAM(上次)
  276.                 Y0_0++;
  277.                 Y0++;
  278.               }
  279.           }  
  280.   if(Switch_Num==4)               //波形移动(左右)
  281.           {
  282.             if(Key_Up==0)             //右
  283.               {
  284.                 Delay_M(5);
  285.                 if(Key_Up==0)
  286.                 while(!Key_Up);
  287.                 Beep_key();           //按键音
  288.                 CLR_GD_RAM();         //清除绘图RAM(上次)
  289.                 X0_Value=X0_Value+1;
  290.               }
  291.             if(Key_Down==0)           //左
  292.               {
  293.                 Delay_M(5);
  294.                 if(Key_Down==0)
  295.                 while(!Key_Down);
  296.                 Beep_key();           //按键音
  297.                 CLR_GD_RAM();         //清除绘图RAM(上次)
  298.                 X0_Value=X0_Value-1;
  299.               }
  300.           }
  301. }
  302. void Init_all(void)        //初始化函数
  303. {
  304.    LCD12864_DA_PORT=0xFF;  //释放P0端口
  305.    ir_code[1]=0xFF;        //用户数据码初始化
  306.    ir_code[3]=0xFF;        //用户识别反码初始化
  307.    X0=X0_Value;            //初始坐标的初始化
  308.    open_yaokong();         //开启遥控接收
  309.    LCD12864_Init();        //12864的初始化
  310.    Beep_set();             //进入系统声音
  311.    LCD12864_WRITE_Screen();//显示开始界面
  312. }
  313. void main(void)            //主函数
  314. {
  315.    Init_all();             //系统初始化
  316.    Delay_M(2000);          //延时2秒
  317.    LCD12864_Init();        //12864初始化
  318.    Beep_set();             //进入系统确定音
  319.    while(1)
  320.       {
  321.        if(System_in_flag==0&&System_Adjust_flag==0) //系统进入键没有按下
  322.                  {
  323.                     Display_Interface_One();          //红外接收显示界面Ⅰ
  324.             if(ir_code[3]==0x38)              //红外接收成功
  325.                 {
  326.                         Beep_key();
  327.                         ir_code[3]=0xFF;              //用户识别反码初始化
  328.                 }
  329.            if(ir_code[1]<=0xFE)               //红外接收显示
  330.             {
  331.                 InfrareRemote_Display();
  332.                 Decode_ir_code_1(ir_code[1]); //用户数据码的转换
  333.                 Decode_ir_code_0(ir_code[0]); //用户数据反码的转换
  334.             }
  335.                  }
  336.        if(Key_In==0)                  //进入界面Ⅱ按键
  337.          {
  338.            Delay_M(5);                //延时消抖
  339.            if(Key_In==0)
  340.              {
  341.                 System_in_flag=1;     //置位进入系统标志位
  342.                 System_Adjust_flag=0; //清零系统调整位
  343.                 Switch_Num=0;         //切换界面次数清零
  344.              }
  345.            while(!Key_In);            //等待按键松开
  346.            /*以下2行是画图的初始化*/
  347.            LCD12864_Init();           //12864的初始化
  348.            CLR_GD_RAM();              //清除绘图RAM
  349.            Beep_key();                //按键音
  350.          }
  351.        if(Key_Out==0)                 //退出界面Ⅱ、Ⅲ按键
  352.          {
  353.            Delay_M(5);                //延时消抖
  354.            if(Key_Out==0)
  355.              {
  356.                 System_in_flag=0;     //进入系统标志位清零
  357.                 System_Adjust_flag=0; //系统界面调整标志位清零
  358.                 Switch_Num=0;         //切换界面次数清零
  359.              }
  360.            while(!Key_Out);           //等待按键松开
  361.            LCD12864_Init();           //12864的初始化
  362.            Beep_key();                //按键音
  363.          }
  364.        if(Key_Adjust==0)              //进入界面Ⅱ按键
  365.          {
  366.            Delay_M(5);                //延时消抖
  367.            if(Key_Adjust==0)
  368.              {
  369.                 System_Adjust_flag=1; //置位系统调整位
  370.                 System_in_flag=0;     //清零进入系统标志位
  371.                 Switch_Num=0;         //切换界面次数清零
  372.              }
  373.            while(!Key_Adjust);        //等待按键松开
  374.            /*以下2行是画图的初始化*/
  375.            LCD12864_Init();           //12864的初始化
  376.            CLR_GD_RAM();              //清除绘图RAM
  377.            Beep_key();                //按键音
  378.          }
  379.        if(System_in_flag==1)          //系统进入键按下
  380.          {
  381.           Screen_Adjust();            //画面调整
  382.           Display_Interface_Two();    //显示界面Ⅱ
  383.          }
  384.        if(System_Adjust_flag==1)      //系统调整键按下
  385.          {
  386.           Screen_Adjust();            //画面调整
  387.           Display_Interface_Three();  //数据反码波形显示
  388.          }
  389.           }
  390.       
  391. }
复制代码

完整源码下载: 红外波形显示源程序.zip (81.65 KB, 下载次数: 175)

评分

参与人数 1黑币 +5 收起 理由
嘿小毅 + 5

查看全部评分

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

使用道具 举报

沙发
ID:112503 发表于 2016-4-6 14:56 | 只看该作者
新手学习了,感谢楼主
回复

使用道具 举报

板凳
ID:112503 发表于 2016-4-6 14:57 | 只看该作者
新手学习了,感谢楼主
回复

使用道具 举报

地板
ID:63924 发表于 2016-5-8 00:27 | 只看该作者
楼主您好,我想更改程序里的引脚定义,改不了,而且下载您源程序12864显示乱码。楼主可以看看下吗
12864蓝屏液晶带字库
回复

使用道具 举报

5#
ID:63924 发表于 2016-5-8 00:31 | 只看该作者
Build target 'Target 1'assembling STARTUP.A51...A51 MACRO ASSEMBLER V8.02 - SN: K1RMC-KVWRICCOPYRIGHT KEIL ELEKTRONIK GmbH 1987 - 2008"C:\Keil\C51\BIN\A51.EXE" "C:\Documents and Settings\yongli03\桌面\红外波形显示2010.05.28\STARTUP.A51" SET (SMALL) DEBUG PRINT(.\output\STARTUP.lst) OBJECT(.\output\STARTUP.obj) EPA51 FATAL ERROR -  FILE:       C:\Documents and Settings\yongli03\桌面\红外波形显示2010.05.28\STARTUP.A51  ERROR:      FILE DOES NOT EXISTA51 TERMINATED.Target not created



回复

使用道具 举报

6#
ID:134271 发表于 2020-2-16 17:56 | 只看该作者
晶振有没有要求?
回复

使用道具 举报

7#
ID:734574 发表于 2020-5-29 15:45 来自手机 | 只看该作者
pangjineng 发表于 2020-2-16 17:56
晶振有没有要求?

老哥,你做出来了嘛
回复

使用道具 举报

8#
ID:822707 发表于 2020-11-2 19:38 | 只看该作者
其实不用这么复杂,用音频软件,加一个红外接收头做一个简单示波器,波形一目了然。
回复

使用道具 举报

9#
ID:796012 发表于 2023-3-2 13:51 | 只看该作者
CC51hei6 发表于 2020-11-2 19:38
其实不用这么复杂,用音频软件,加一个红外接收头做一个简单示波器,波形一目了然。

找不到用什么音频软件
回复

使用道具 举报

10#
ID:796012 发表于 2023-3-2 14:46 | 只看该作者
84533243 发表于 2016-5-8 00:31
Build target 'Target 1'assembling STARTUP.A51...A51 MACRO ASSEMBLER V8.02 - SN: K1RMC-KVWRICCOPYRIGH ...

重建工程,楼主文件存的不是C盘,编译器报错
回复

使用道具 举报

11#
ID:69038 发表于 2023-3-3 11:08 | 只看该作者
玉萌业余发展 发表于 2023-3-2 14:46
重建工程,楼主文件存的不是C盘,编译器报错

goldwave~~网上有的是,体积也不大。
回复

使用道具 举报

12#
ID:102702 发表于 2023-3-4 13:16 | 只看该作者
请问楼主能发个电路图吗?
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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