/*******************************************************
"长沙太阳人"杯红外波形显示单片机设计大赛
程序名称:红外波形显示 程序设计人:汪建
硬件设计人:沈强 视频图片记录人:滕建
设计日期:2010.6.3 版本:V1.0
********************************************************/
#include<reg52.h>
#include<string.h>
#include<intrins.h>
#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(); //按键音