|
20100826_8a7ff1ed1718270e2546BtzHxM1OxgOe.jpg (171 KB, 下載次數: 196)
下載附件
2015-6-6 03:45 上傳
20100826_6121de495d137d17e3a9b2S74oF5l7l7.jpg (34.13 KB, 下載次數: 201)
下載附件
2015-6-6 03:45 上傳
20100826_f60724af0965726580f8Srci992AjhKD.jpg (43.29 KB, 下載次數: 220)
下載附件
2015-6-6 03:45 上傳
20100826_e4fada29a75df36561abQvAd3KET5Sih.jpg (44.1 KB, 下載次數: 198)
下載附件
2015-6-6 03:45 上傳
20100826_3bb4bc3a678f1291b122c72HHGQqcg7c.jpg (38.23 KB, 下載次數: 197)
下載附件
2015-6-6 03:45 上傳
程序代碼:
- /*******************************************************
- "長沙太陽人"杯紅外波形顯示單片機設計大賽
- 程序名稱:紅外波形顯示 程序設計人:汪建
-
- 硬件設計人:沈強 視頻圖片記錄人:滕建
-
- 設計日期: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)
2015-6-6 03:42 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|
評分
-
查看全部評分
|