|
0.png (71.46 KB, 下載次數(shù): 84)
下載附件
2016-9-11 22:21 上傳
本例程,實(shí)現(xiàn)單片機(jī)紅外接收解碼,并用nokia5110液晶屏來顯示內(nèi)容。完整keil工程文件下載:
http://www.zg4o1577.cn/bbs/dpj-55490-1.html
下面是部分程序代碼的預(yù)覽:
主程序:
- #include "IR_Receive.h"
- #include "Nokia5110.h"
- #include "delay.h"
- extern uint8_t IRcode_Type;//紅外數(shù)據(jù)類型,RCA或NEC8或NEC16
- extern uint16_t IRcode[2]; //紅外數(shù)據(jù)中的系統(tǒng)碼IRcode[0],紅外數(shù)據(jù)中的用戶碼IRcode[1]
- extern uint32_t RCAcode_Original;//RCA協(xié)議原碼
- extern uint32_t NECcode_Original;//NEC原始數(shù)據(jù)
- void main(void)
- {
- IRreceiver_Init();
- Nokia5110_Init();
-
- Nokia5110_WriteString(0,0,"*IR_Receiver*");
- Nokia5110_WriteString(2,0,"Rev:**********");
- Nokia5110_WriteString(3,0,"CodeType:****");
- Nokia5110_WriteString(4,0,"SysCode :****");
- Nokia5110_WriteString(5,0,"UserCode:****");
- while(1)
- {
- if(IRdata_Analysis())//解析成功串口打印正確紅外碼值
- {
- Nokia5110_Clear(1,5);
- switch(IRcode_Type)
- {
- case IRcode_TypeRCA:
- {
- Nokia5110_Printf(2,0,"Rev:",RCAcode_Original,Hex);//打印出未進(jìn)行解析的原始紅外RCA數(shù)據(jù)
- Nokia5110_WriteString(3,0,"CodeType: RCA");
- Nokia5110_Printf(4,0,"SysCode : ",IRcode[0],Hex);
- Nokia5110_Printf(5,0,"UserCode: ",IRcode[1],Hex);
- break;
- }
- case IRcode_TypeNEC8:
- {
- Nokia5110_Printf(2,0,"Rev:",NECcode_Original,Hex);//打印出未進(jìn)行解析的原始紅外NEC數(shù)據(jù)
- Nokia5110_WriteString(3,0,"CodeType: NEC8");
- Nokia5110_Printf(4,0,"SysCode : ",IRcode[0],Hex);
- Nokia5110_Printf(5,0,"UserCode: ",IRcode[1],Hex);
- break;
- }
- case IRcode_TypeNEC16:
- {
- Nokia5110_Printf(2,0,"Rev:",NECcode_Original,Hex);//打印出未進(jìn)行解析的原始紅外NEC數(shù)據(jù)
- Nokia5110_WriteString(3,0,"CodeType:NEC16");
- Nokia5110_Printf(4,0,"SysCode:",IRcode[0],Hex);
- Nokia5110_Printf(5,0,"UserCode:",IRcode[1],Hex);
- break;
- }
- default:{break;}
- }
- IRcode_Type = IRcode_TypeNone;
- Buzzer_Speak();//解碼成功,蜂鳴器響
- }
- }
- }
復(fù)制代碼- #include "Nokia5110.h"
- #include "ASII_Font.h"
- #include "IR_Receive.h"
- uint8_t Dex_Hex_Buffer[Length_Max];//數(shù)據(jù)緩沖區(qū)
- extern uint8_t IRcode_Type;//定義收到的紅外數(shù)據(jù)類型
- /*************************************************************************************
- 函數(shù):void Divide_Dex_Hex(uint32_t Num,uint8_t Format)
- 功能:數(shù)據(jù)分離,儲(chǔ)存在緩沖中數(shù)組中,低位~高位=[0]~[Length_Max-1],返回?cái)?shù)據(jù)位數(shù)
- *************************************************************************************/
- uint8_t Divide_Dex_Hex(uint32_t Num,uint8_t Format)
- {
- signed char i=0;
- uint8_t Num_Cnt = 0;
- for(i=0;i<Length_Max;i++) //緩沖清零
- {
- Dex_Hex_Buffer[i] = '0';
- }
- if(Num == 0)//Num = 0處理
- {
- if(Format == Dex)return 1;
- if(Format == Hex)return 2;
- }
- else if(Format == Dex)//把數(shù)據(jù)分離成十進(jìn)制數(shù)
- {
- i = 0;
- while(Num)
- {
- Dex_Hex_Buffer[i] = Num%10+'0';//處理成ASIIC碼
- Num /= 10;
- Num_Cnt++;
- i++;
- }
- }
- else if(Format == Hex)//把數(shù)據(jù)分離成十六進(jìn)制數(shù)
- {
- i = 0;
- while(Num)
- {
- Dex_Hex_Buffer[i] = Num%16;
- Num /= 16;
- Num_Cnt++;
- i++;
- }
- for(i=Num_Cnt-1;i>=0;i--) //把分離出來的十六進(jìn)制數(shù)據(jù)處理成ASIIC碼
- {
- if(Dex_Hex_Buffer[i]<10)
- {
- Dex_Hex_Buffer[i] += 0x30;
- }
- else
- {
- Dex_Hex_Buffer[i] = Dex_Hex_Buffer[i]-0x0A+0x41;
- }
- }
- if(Num_Cnt%2)Num_Cnt+=1; //十六進(jìn)制返回的位數(shù)強(qiáng)制為偶數(shù)
- }
- return Num_Cnt;//返回?cái)?shù)據(jù)十進(jìn)制或十六進(jìn)制位數(shù)
- }
- /*******************************************************
- 函數(shù):void Nokia5110_Write(uint8_t dat,bit data_cmd);
- 功能:向Nokia5110中寫入數(shù)據(jù)或命令;
- *******************************************************/
- void Nokia5110_Write(uint8_t dat,bit data_cmd)
- {
- uint8_t i;
- LCD_CE = 0; /*使能5110*/
- LCD_DC = data_cmd; /*DC=1,寫入數(shù)據(jù);DC=0,寫入命令*/
- for(i=0;i<8;i++)
- {
- if(dat&0x80)
- {
- LCD_DIN = 1;
- }
- else
- {
- LCD_DIN = 0;
- }
- LCD_CLK = 0;
- dat<<=1;
- LCD_CLK = 1;
- }
- LCD_CE = 1; /*關(guān)閉5110*/
- }
- /************************************************************************************************
- 函數(shù):void Nokia5110_Clear(uint8_t Y_Start, uint8_t Y_End);
- 功能:對(duì)Nokia5110選擇性區(qū)域進(jìn)行清屏;
- ***********************************************************************************************/
- void Nokia5110_Clear(uint8_t Y_Start, uint8_t Y_End)
- {
- uint16_t i;
- uint16_t AreaSize = 0;
-
- Nokia5110_Write(0x80|0x00,CMD);
- Nokia5110_Write(0x40|Y_Start,CMD);
-
- AreaSize = 84*(Y_End-Y_Start+1);
- for(i=0;i<AreaSize;i++)
- {
- Nokia5110_Write(0x00,DATA);
- }
- }
- /*******************************************************
- 函數(shù):void Nokia5110_Init();
- 功能:對(duì)Nokia5110進(jìn)行初始化;
- *******************************************************/
- void Nokia5110_Init(void)
- {
- delay_us(10);
- LCD_RST = 0;
- delay_us(10);
- LCD_RST = 1; //RST=1 復(fù)位,開始寫數(shù)據(jù)
- Nokia5110_Write(0x21,CMD); //使用擴(kuò)展指令集,水平尋址
- Nokia5110_Write(0xC5,CMD); //寫Vop到寄存器
- Nokia5110_Write(0x07,CMD); //溫度系數(shù)3
- Nokia5110_Write(0x13,CMD); //偏置值1:48
- Nokia5110_Write(0x20,CMD); //使用基本指令集,水平尋址
- Nokia5110_Write(0x0C,CMD); //選擇普通模式
- Nokia5110_Clear(0,5); //清屏
- }
- /*******************************************************
- 函數(shù):void Nokia5110_SetRC(uint8_t line,uint8_t lie);
- 功能:顯示屏坐標(biāo)設(shè)定,R:line=0~5,C:lie=0~13;
- *******************************************************/
- void Nokia5110_SetRC(uint8_t line,uint8_t lie)
- {
- lie*=6;
- Nokia5110_Write(0x40|line,CMD);
- Nokia5110_Write(0x80|lie, CMD);
- }
- /*******************************************************
- 函數(shù):void Nokia5110_WriteChar(uint8_t Char);
- 功能:向5110液晶屏中寫入一個(gè)字節(jié);
- *******************************************************/
- void Nokia5110_WriteChar(uint8_t Char)
- {
- uint8_t i,j;
- i = Char-0x20;
- for(j=0;j<6;j++)
- {
- Nokia5110_Write(ASII_Font[i][j],DATA);
- }
- }
- /*************************************************************************************
- 函數(shù):void Nokia5110_WriteString(uint8_t line,uint8_t lie,uint8_t *pString);
- 功能:向5110液晶屏指定地址開始寫入字符串;
- ************************************************************************************/
- void Nokia5110_WriteString(uint8_t line,uint8_t lie,uint8_t *pString)
- {
- Nokia5110_SetRC(line,lie);
-
- while(*pString != '\0')
- {
- Nokia5110_WriteChar(*pString);
- pString++;
- }
- }
- /*************************************************************************************
- 函數(shù):void Nokia5110_ClearData(uint8_t line,uint8_t lie,uint8_t Length);
- 功能:清除指定坐標(biāo)中的指定長度數(shù)據(jù)
- ************************************************************************************/
- void Nokia5110_ClearData(uint8_t line,uint8_t lie,uint8_t Length)
- {
- uint8_t i=0;
- Nokia5110_SetRC(line,lie);
- for(i=0;i<Length;i++)
- {
- Nokia5110_WriteChar(' ');
- }
- }
- /***************************************************************************************************
- 函數(shù):void Nokia5110_Printf(uint8_t hang,uint8_t,lie,uint8_t *String,uint32_t Value,uint8_t Format);
- 功能:以十進(jìn)制或者十六進(jìn)制往5110液晶屏中寫ASIIC數(shù)據(jù);
- **************************************************************************************************/
- void Nokia5110_Printf(uint8_t hang,uint8_t lie,uint8_t *pString,uint32_t Value,uint8_t Format)
- {
- uint8_t i;
- static uint8_t SysCode4Bit_Flag = 0;//系統(tǒng)碼為4位標(biāo)志位,用于顯示NEC16系統(tǒng)碼高八位為0
- uint8_t Num_Cnt = 0;
- Num_Cnt = Divide_Dex_Hex(Value,Format);
-
- if((IRcode_Type==IRcode_TypeRCA)&&(Num_Cnt==4))//處理RCA系統(tǒng)碼為0的情況,原碼需要把00顯示出來
- {
- Num_Cnt = 6;
- }
- if((IRcode_Type==IRcode_TypeNEC8)&&(Num_Cnt==6))//處理NEC8系統(tǒng)碼為0的情況,原碼需要把00顯示出來
- {
- Num_Cnt = 8;
- }
- if((IRcode_Type==IRcode_TypeNEC16)&&(Num_Cnt==6))//處理NEC16系統(tǒng)碼高八位為0的情況,原碼需要把00顯示出來
- {
- Num_Cnt = 8;
- SysCode4Bit_Flag = 1;
- }
- if((SysCode4Bit_Flag==1)&&(Num_Cnt==2))//處理NEC16系統(tǒng)碼高八位為0的情況,系統(tǒng)碼需要把00顯示出來
- {
- SysCode4Bit_Flag = 0;
- Num_Cnt = 4;
- }
-
- Nokia5110_WriteString(hang,lie,pString);
- if(Format==Hex)
- {
- Nokia5110_WriteChar('0');
- Nokia5110_WriteChar('x');
- }
- for(i=0;i<Num_Cnt;i++)
- {
- Nokia5110_WriteChar(Dex_Hex_Buffer[(Num_Cnt-1)-i]);
- }
- }
復(fù)制代碼
|
評(píng)分
-
查看全部評(píng)分
|