|
程序代码:
- /*******************************************************
- "长沙太阳人"杯红外波形显示单片机设计大赛
- 程序名称:红外波形显示 程序设计人:汪建
-
- 硬件设计人:沈强 视频图片记录人:滕建
-
- 设计日期:2015.6.3 版本:V1.0
- ********************************************************/
- #include
- #include
- #include
- #include"Beep.h"
- #include"LCD12864.h"
- #include"MacroAndConst.h"
- #include"InfraredRemoteControl.h"
- unsigned char ir_code[4]; /*遥控接收数据*/
- unsigned char ir_code_B_1[8]; //红外解码二进制形式(数据码)
- unsigned char ir_code_B_0[8]; //红外解码二进制形式(数据反码)
- //独立按键定义
- sbit Key_In = P1^0; //进入系统
- sbit Key_Out = P1^1; //退出系统
- sbit Key_Adjust = P1^2; //调整界面
- sbit Key_Switch = P1^3; //调整切换键
- sbit Key_Up = P1^4; //幅度、脉宽(增大)移动(上或右)
- sbit Key_Down = P1^5; //幅度、脉宽(减小)移动(下或左)
- unsigned char code num_to_char[]={"0123456789ABCDEF"}; /*数字转换为ASCII字符码*/
- bit System_in_flag,System_Adjust_flag; //进入系统、退出系统标志位
- unsigned char Switch_Num; //转换按键次数
- unsigned char X0_Value=5; //x坐标的初始化
- unsigned char X0; //定义坐标x
- unsigned char Y0=58; //波形下限的所在位置(初始)
- unsigned char Y0_0=32; //波形上限的所在位置(初始)
- unsigned char x0_0=2; //波形的间隔的初始化
- unsigned char x0_0_1=5; //Bit'0'的脉宽初始化
- unsigned char x1_1_1=10; //Bit'1'的脉宽初始化
- void Delay_M(unsigned int a) //主函数延时函数 1MS/次
- {
- uchar i;
- while(--a!=0)
- {
- for(i=0;i<125;i++);
- }
- }
- void Decode_ir_code_1(unsigned char ir_code) //用户数据码转换为二进制
- {
- unsigned char ir_code_D_1;
- ir_code_D_1=ir_code/0x10*16+ir_code%0x10;
- ir_code_B_1[0]=ir_code_D_1%128%64%32%16%8%4%2;
- ir_code_B_1[1]=ir_code_D_1%128%64%32%16%8%4/2;
- ir_code_B_1[2]=ir_code_D_1%128%64%32%16%8/4;
- ir_code_B_1[3]=ir_code_D_1%128%64%32%16/8;
- ir_code_B_1[4]=ir_code_D_1%128%64%32/16;
- ir_code_B_1[5]=ir_code_D_1%128%64/32;
- ir_code_B_1[6]=ir_code_D_1%128/64;
- ir_code_B_1[7]=ir_code_D_1/128;
- }
- void Decode_ir_code_0(unsigned char ir_code) //用户数据反码转换为二进制
- {
- unsigned char ir_code_D_0;
- ir_code_D_0=ir_code/0x10*16+ir_code%0x10;
- ir_code_B_0[0]=ir_code_D_0%128%64%32%16%8%4%2;
- ir_code_B_0[1]=ir_code_D_0%128%64%32%16%8%4/2;
- ir_code_B_0[2]=ir_code_D_0%128%64%32%16%8/4;
- ir_code_B_0[3]=ir_code_D_0%128%64%32%16/8;
- ir_code_B_0[4]=ir_code_D_0%128%64%32/16;
- ir_code_B_0[5]=ir_code_D_0%128%64/32;
- ir_code_B_0[6]=ir_code_D_0%128/64;
- ir_code_B_0[7]=ir_code_D_0/128;
- }
- void Draw_Bit_0(unsigned char X0,unsigned char x0_0,unsigned char x0_0_1,unsigned char Y0,unsigned char Y0_0) //比特0显示
- {
- Lcd12864DrawLineX_f(X0,X0+x0_0,Y0,1);
- Lcd12864DrawLineY_f(X0+x0_0,Y0_0,Y0-1,1);
- Lcd12864DrawLineX_f(X0+x0_0+1,X0+x0_0_1,Y0_0,1);
- Lcd12864DrawLineY_f(X0+x0_0_1,Y0_0,Y0,1);
- }
- void Draw_Bit_1(unsigned char X0,unsigned char x0_0,unsigned char x1_1_1,unsigned char Y0,unsigned char Y0_0) //比特1显示
- {
- Lcd12864DrawLineX_f(X0,X0+x0_0,Y0,1);
- Lcd12864DrawLineY_f(X0+x0_0,Y0_0,Y0-1,1);
- Lcd12864DrawLineX_f(X0+x0_0+1,X0+x1_1_1,Y0_0,1);
- Lcd12864DrawLineY_f(X0+x1_1_1,Y0_0+1,Y0,1);
- }
- void Display_Interface_One(void) //显示界面Ⅰ
- {
- LCD12864_COM_Write(0x80);
- LCD12864_WRITE_SWord("■红外波形显示■");
- LCD12864_COM_Write(0x90);
- LCD12864_WRITE_SWord("原码: ");
- LCD12864_COM_Write(0x94);
- LCD12864_WRITE_SWord("反码: ");
- LCD12864_COM_Write(0x88);
- LCD12864_WRITE_SWord("用户识别码: ");
- LCD12864_COM_Write(0x8f);
- LCD12864_WRITE_SWord("■");
- LCD12864_COM_Write(0x98);
- LCD12864_WRITE_SWord("用户按键值: ");
- LCD12864_COM_Write(0x9f);
- LCD12864_WRITE_SWord("■");
- }
- void InfrareRemote_Display(void) //红外接收显示
- {
- LCD12864_COM_Write(0x93);
- LCD12864_Data_Write(num_to_char[ir_code[1]/0x10]);//用户数据码
- LCD12864_Data_Write(num_to_char[ir_code[1]%0x10]);
- LCD12864_COM_Write(0x97);
- LCD12864_Data_Write(num_to_char[ir_code[0]/0x10]);//用户数据反码
- LCD12864_Data_Write(num_to_char[ir_code[0]%0x10]);
- LCD12864_COM_Write(0x8e);
- LCD12864_Data_Write(num_to_char[ir_code[2]/0x10]);//用户识别码
- LCD12864_Data_Write(num_to_char[ir_code[2]%0x10]);
- LCD12864_COM_Write(0x9e); //用户按键值(十进制形式)
- LCD12864_Data_Write(num_to_char[(ir_code[1]/0x10*16+ir_code[1]%0x10)/10]);
- LCD12864_Data_Write(num_to_char[(ir_code[1]/0x10*16+ir_code[1]%0x10)%10]);
- }
- void Draw_Coordinate(void) //坐标显示函数
- {
- unsigned char i,Y0,X0;
- X0=3,Y0=60; //x坐标和y坐标的初始化
- /*波形坐标显示*/
- Lcd12864DrawLineY_f(1,0,63,1); //第1列
- Lcd12864DrawLineX_f(0,127,62,1); //第62行
- Lcd12864_DrawPoint_f(0,1,1); //箭头点显示
- Lcd12864_DrawPoint_f(2,1,1);
- Lcd12864_DrawPoint_f(126,61,1);
- Lcd12864_DrawPoint_f(126,63,1);
- for(i=0;i<=28;i++) //y坐标标尺
- {
- Lcd12864_DrawPoint_f(2,Y0,1);
- Y0=Y0-2;
- }
- for(i=0;i<=60;i++) //x坐标标尺
- {
- Lcd12864_DrawPoint_f(X0,61,1);
- X0=X0+2;
- }
- }
- void Display_Interface_Two(void) //显示界面Ⅱ(用户数据码波形显示)
- {
- unsigned char i;
- Draw_Coordinate(); //坐标显示
- X0=X0_Value;
- for(i=0;i<=7;i++)
- {
- if(ir_code_B_1[i]==1) //Bit 1
- {
- Draw_Bit_1(X0,x0_0,x1_1_1,Y0,Y0_0);
- X0=X0+x1_1_1;
- }
- if(ir_code_B_1[i]==0) //Bit 0
- {
- Draw_Bit_0(X0,x0_0,x0_0_1,Y0,Y0_0);
- X0=X0+x0_0_1;
- }
- }
- LCD12864_COM_Write(0x81); //显示用户数据码(二进制)
- for(i=0;i<=7;i++)
- {
- LCD12864_Data_Write(num_to_char[ir_code_B_1[i]]);
- }
- LCD12864_Data_Write(num_to_char[11]); //'B'
- }
- void Display_Interface_Three(void) //显示界面Ⅲ(用户数据反码波形显示)
- {
- unsigned char i;
- Draw_Coordinate(); //坐标显示
- X0=X0_Value; //坐标的初始化
- for(i=0;i<=7;i++)
- {
- if(ir_code_B_0[i]==1) //Bit 1
- {
- Draw_Bit_1(X0,x0_0,x1_1_1,Y0,Y0_0);
- X0=X0+x1_1_1;
- }
- if(ir_code_B_0[i]==0) //Bit 0
- {
- Draw_Bit_0(X0,x0_0,x0_0_1,Y0,Y0_0);
- X0=X0+x0_0_1;
- }
- }
- LCD12864_COM_Write(0x81); //显示用户数据反码(二进制)
- for(i=0;i<=7;i++)
- {
- LCD12864_Data_Write(num_to_char[ir_code_B_0[i]]);
- }
- LCD12864_Data_Write(num_to_char[11]); //'B'
- }
- void Screen_Adjust(void) //画面调整函数(波形的调整)
- {
- if(Key_Switch==0)
- {
- Delay_M(5); //延时消抖
- if(Key_Switch==0)
- while(!Key_Adjust); //等待按键松开
- Switch_Num++; //转换按键次数增加
- if(Switch_Num==5)
- Switch_Num=1;
- Beep_key(); //按键音
- }
- switch(Switch_Num) //调整内容
- {
- case 1:LCD12864_COM_Write(0x86);
- LCD12864_WRITE_SWord("调幅");break;
- case 2:LCD12864_COM_Write(0x86);
- LCD12864_WRITE_SWord("调宽");break;
- case 3:LCD12864_COM_Write(0x86);
- LCD12864_WRITE_SWord("↑↓");break;
- case 4:LCD12864_COM_Write(0x86);
- LCD12864_WRITE_SWord("→←");break;
- }
- if(Switch_Num==1) //波形调幅
- {
- if(Key_Up==0) //加
- {
- Delay_M(5);
- if(Key_Up==0)
- while(!Key_Up);
- Beep_key(); //按键音
- CLR_GD_RAM(); //清除绘图RAM(上次)
- Y0_0--;
- }
- if(Key_Down==0) //减
- {
- Delay_M(5);
- if(Key_Down==0)
- while(!Key_Down);
- Beep_key(); //按键音
- CLR_GD_RAM(); //清除绘图RAM(上次)
- Y0_0++;
- }
- }
- if(Switch_Num==2) //波形调宽
- {
- if(Key_Up==0) //宽
- {
- Delay_M(5);
- if(Key_Up==0)
- while(!Key_Up);
- Beep_key(); //按键音
- CLR_GD_RAM(); //清除绘图RAM(上次)
- x0_0++;
- x0_0_1=x0_0_1+2;
- x1_1_1=x1_1_1+2;
- }
- if(Key_Down==0) //窄
- {
- Delay_M(5);
- if(Key_Down==0)
- while(!Key_Down);
- Beep_key(); //按键音
- CLR_GD_RAM(); //清除绘图RAM(上次)
- x0_0--;
- x0_0_1=x0_0_1-2;
- x1_1_1=x1_1_1-2;
- }
- }
- if(Switch_Num==3) //波形移动(上下)
- {
- if(Key_Up==0) //上
- {
- Delay_M(5);
- if(Key_Up==0)
- while(!Key_Up);
- Beep_key(); //按键音
- CLR_GD_RAM(); //清除绘图RAM(上次)
- Y0_0--;
- Y0--;
- }
- if(Key_Down==0) //下
- {
- Delay_M(5);
- if(Key_Down==0)
- while(!Key_Down);
- Beep_key(); //按键音
- CLR_GD_RAM(); //清除绘图RAM(上次)
- Y0_0++;
- Y0++;
- }
- }
- if(Switch_Num==4) //波形移动(左右)
- {
- if(Key_Up==0) //右
- {
- Delay_M(5);
- if(Key_Up==0)
- while(!Key_Up);
- Beep_key(); //按键音
- CLR_GD_RAM(); //清除绘图RAM(上次)
- X0_Value=X0_Value+1;
- }
- if(Key_Down==0) //左
- {
- Delay_M(5);
- if(Key_Down==0)
- while(!Key_Down);
- Beep_key(); //按键音
- CLR_GD_RAM(); //清除绘图RAM(上次)
- X0_Value=X0_Value-1;
- }
- }
- }
- void Init_all(void) //初始化函数
- {
- LCD12864_DA_PORT=0xFF; //释放P0端口
- ir_code[1]=0xFF; //用户数据码初始化
- ir_code[3]=0xFF; //用户识别反码初始化
- X0=X0_Value; //初始坐标的初始化
- open_yaokong(); //开启遥控接收
- LCD12864_Init(); //12864的初始化
- Beep_set(); //进入系统声音
- LCD12864_WRITE_Screen();//显示开始界面
- }
- void main(void) //主函数
- {
- Init_all(); //系统初始化
- Delay_M(2000); //延时2秒
- LCD12864_Init(); //12864初始化
- Beep_set(); //进入系统确定音
- while(1)
- {
- if(System_in_flag==0&&System_Adjust_flag==0) //系统进入键没有按下
- {
- Display_Interface_One(); //红外接收显示界面Ⅰ
- if(ir_code[3]==0x38) //红外接收成功
- {
- Beep_key();
- ir_code[3]=0xFF; //用户识别反码初始化
- }
- if(ir_code[1]<=0xFE) //红外接收显示
- {
- InfrareRemote_Display();
- Decode_ir_code_1(ir_code[1]); //用户数据码的转换
- Decode_ir_code_0(ir_code[0]); //用户数据反码的转换
- }
- }
- if(Key_In==0) //进入界面Ⅱ按键
- {
- Delay_M(5); //延时消抖
- if(Key_In==0)
- {
- System_in_flag=1; //置位进入系统标志位
- System_Adjust_flag=0; //清零系统调整位
- Switch_Num=0; //切换界面次数清零
- }
- while(!Key_In); //等待按键松开
- /*以下2行是画图的初始化*/
- LCD12864_Init(); //12864的初始化
- CLR_GD_RAM(); //清除绘图RAM
- Beep_key(); //按键音
- }
- if(Key_Out==0) //退出界面Ⅱ、Ⅲ按键
- {
- Delay_M(5); //延时消抖
- if(Key_Out==0)
- {
- System_in_flag=0; //进入系统标志位清零
- System_Adjust_flag=0; //系统界面调整标志位清零
- Switch_Num=0; //切换界面次数清零
- }
- while(!Key_Out); //等待按键松开
- LCD12864_Init(); //12864的初始化
- Beep_key(); //按键音
- }
- if(Key_Adjust==0) //进入界面Ⅱ按键
- {
- Delay_M(5); //延时消抖
- if(Key_Adjust==0)
- {
- System_Adjust_flag=1; //置位系统调整位
- System_in_flag=0; //清零进入系统标志位
- Switch_Num=0; //切换界面次数清零
- }
- while(!Key_Adjust); //等待按键松开
- /*以下2行是画图的初始化*/
- LCD12864_Init(); //12864的初始化
- CLR_GD_RAM(); //清除绘图RAM
- Beep_key(); //按键音
- }
- if(System_in_flag==1) //系统进入键按下
- {
- Screen_Adjust(); //画面调整
- Display_Interface_Two(); //显示界面Ⅱ
- }
- if(System_Adjust_flag==1) //系统调整键按下
- {
- Screen_Adjust(); //画面调整
- Display_Interface_Three(); //数据反码波形显示
- }
- }
-
- }
复制代码
完整源码下载:
红外波形显示源程序.zip
(81.65 KB, 下载次数: 182)
|
评分
-
查看全部评分
|