|
MP3圖.jpg (122.2 KB, 下載次數(shù): 34)
下載附件
2019-3-5 20:15 上傳
IMG_20190305_191803.PNG (681.13 KB, 下載次數(shù): 28)
下載附件
2019-3-5 20:15 上傳
IMG_20190305_191809.PNG (600.07 KB, 下載次數(shù): 30)
下載附件
2019-3-5 20:15 上傳
IMG_20190305_191934.PNG (947.54 KB, 下載次數(shù): 47)
下載附件
2019-3-5 20:15 上傳
單片機(jī)源程序如下:
- /************************************************************
- 單片機(jī): STC15F104W/STC15W104
- 晶振: 12.000MHz
- 功能: 紅外遙控(4個(gè)IO口實(shí)現(xiàn)5個(gè)功能)
- 1.上一首 2.下一首 3.暫停 4.音量+ 5.音量-
- 注:單片機(jī)供電必需用USB口供電,不能用DC口供電
- *************************************************************/
- #include <STC15F2K60S2.H>
- #define uchar unsigned char
- #define uint unsigned int
- #define T50MS (65536-50000) //12T模式
- /************* 用戶(hù)系統(tǒng)配置 **************/
- //燒錄頻率請(qǐng)選12.000MHz
- #define MAIN_Fosc 12000000L //定義主時(shí)鐘, 模擬串口和紅外接收會(huì)自動(dòng)適應(yīng)。5~36MHZ
- #define D_TIMER0 125 //選擇定時(shí)器時(shí)間, us, 紅外接收要求在60us~250us之間
- #define User_code 0x00FF //定義紅外接收用戶(hù)碼(38K的迷你遙控器通用)
- /************* 以下宏定義用戶(hù)請(qǐng)勿修改 **************/
- #define freq_base (MAIN_Fosc / 1200)
- #define Timer0_Reload (65536 - (D_TIMER0 * freq_base / 10000))
- /************* 本地變量聲明 **************/
- bit P_IR_RX_temp; //Last sample
- bit B_IR_Sync; //已收到同步標(biāo)志
- uchar IR_SampleCnt; //采樣計(jì)數(shù)
- uchar IR_BitCnt; //編碼位數(shù)
- uchar IR_UserH; //用戶(hù)碼(地址)高字節(jié)
- uchar IR_UserL; //用戶(hù)碼(地址)低字節(jié)
- uchar IR_data; //數(shù)據(jù)原碼
- uchar IR_DataShit; //數(shù)據(jù)反碼
- bit B_IrUserErr; //User code error flag
- bit B_IR_Press; //Key press flag,include repeat key.
- uchar IR_code; //IR code 紅外鍵碼
- //MP3 IO口接線(xiàn)說(shuō)明
- sbit A1=P3^4; //接Next/V++的左側(cè)(高電平)
- sbit A2=P3^5; //接Prev/V++的右側(cè)(低電平)
- sbit B1=P3^1; //接Prev/V--的左側(cè)(高電平)
- sbit B2=P3^0; //接Prev/V--的右側(cè)(低電平)
- sbit P_IR_RX =P3^2; //定義紅外接收輸入端口
- uchar k,data1=0x01; //k=模式值
- /************* 本地函數(shù)聲明 **************/
- //////////////////////////////////////////
- void DelayMS(uint time)//延時(shí)函數(shù),有參函數(shù)
- {
- uint i4,j4;
- for(i4=time; i4>0; i4--)
- for(j4=110; j4>0; j4--);
- }
- /////////////////////////////////////////////////////////////
- //判斷接收的編碼,執(zhí)行相應(yīng)功能(根據(jù)需要自行修改)
- void _data_(void)
- {
- switch(IR_data) //紅外接收成功
- {
- //不要修改A1、A2、B1、B2的值,都是已經(jīng)測(cè)試好的
- case 0x07: //上一首
- k=1;
- A1=0;A2=0;B1=0;B2=1;
- DelayMS(2000); //相當(dāng)于按下輕觸按鍵后再松開(kāi)(這里用延時(shí)再還原的方法進(jìn)行模擬)
- A1=1;A2=0;B1=1;B2=0;
- break;
- case 0x09: //下一首
- k=1;
- B1=0;B2=0;
- DelayMS(2000); //同上可根據(jù)需求自行修改延時(shí)時(shí)間
- B1=1;B2=0;
- break;
- case 0x15: //暫停
- A1=0;A2=1;B1=0;B2=1;
- DelayMS(2000); //同上可根據(jù)需求自行修改延時(shí)時(shí)間
- A1=1;A2=0;B1=1;B2=0;
- break;
- case 0x40: //音量+
- k=1;
- A1=1;A2=0;B1=0;B2=0;
- DelayMS(20000); //同上可根據(jù)需求自行修改延時(shí)時(shí)間
- A1=1;A2=0;B1=1;B2=0;
- break;
- case 0x19: //音量-
- k=1;
- A1=0;A2=0;B1=0;B2=1;
- DelayMS(20000); //同上可根據(jù)需求自行修改延時(shí)時(shí)間
- A1=1;A2=0;B1=1;B2=0;
- break;
- default:break;
- }
- IR_data=0x00; //必須清零
- }
- ////////////////////////////////////////////
- void main(void) //主函數(shù)
- {
- IE = 0x82; //開(kāi)總中斷和T0中斷允許
- IE2 = 0x04; //T2中斷允許
- TMOD = 0; //for STC15Fxxx系列 Timer0 as 16bit reload timer.
- TH0 = Timer0_Reload / 256;
- TL0 = Timer0_Reload % 256;
- T2L = T50MS; //初始化計(jì)時(shí)值5ms中斷一次
- T2H = T50MS >> 8;
- TR0 =1;
- k =0;A1=1;A2=0;B1=1;B2=0; //初始化
- while(1) //無(wú)限循環(huán)
- {
- switch(k) //判斷k的值
- {
- case 0: AUXR=0x00; //停止中斷
- break;
- case 1: AUXR=0x10; //開(kāi)啟中斷
- break;
- }
- }
- }
- /*************紅外接收部分程序是引用STC官方的資料******************************/
- /******************** 紅外采樣時(shí)間宏定義, 用戶(hù)不要隨意修改 *******************/
- #if ((D_TIMER0 <= 250) && (D_TIMER0 >= 60))
- #define D_IR_sample D_TIMER0 //定義采樣時(shí)間,在60us~250us之間
- #endif
- #define D_IR_SYNC_MAX (15000/D_IR_sample) //SYNC max time
- #define D_IR_SYNC_MIN (9700 /D_IR_sample) //SYNC min time
- #define D_IR_SYNC_DIVIDE (12375/D_IR_sample) //decide data 0 or 1
- #define D_IR_DATA_MAX (3000 /D_IR_sample) //data max time
- #define D_IR_DATA_MIN (600 /D_IR_sample) //data min time
- #define D_IR_DATA_DIVIDE (1687 /D_IR_sample) //decide data 0 or 1
- #define D_IR_BIT_NUMBER 32 //bit number
- //*******************************************************************************************
- //**************************** IR RECEIVE MODULE ********************************************
- void IR_RX_HT6121(void)
- {
- uchar SampleTime;
- IR_SampleCnt++; //Sample + 1
- F0 = P_IR_RX_temp; //Save Last sample status
- P_IR_RX_temp = P_IR_RX; //Read current status
- if(F0 && !P_IR_RX_temp) //Last sample is high,and current sample is low, so is fall edge
- {
- SampleTime = IR_SampleCnt; //get the sample time
- IR_SampleCnt = 0; //Clear the sample counter
- if(SampleTime > D_IR_SYNC_MAX) B_IR_Sync = 0; //large the Maxim SYNC time, then error
- else if(SampleTime >= D_IR_SYNC_MIN) //SYNC
- {
- if(SampleTime >= D_IR_SYNC_DIVIDE)
- {
- B_IR_Sync = 1; //has received SYNC
- IR_BitCnt = D_IR_BIT_NUMBER; //Load bit number
- }
- }
- else if(B_IR_Sync) //has received SYNC
- {
- if(SampleTime > D_IR_DATA_MAX) B_IR_Sync=0; //data samlpe time to large
- else
- {
- IR_DataShit >>= 1; //data shift right 1 bit
- if(SampleTime >= D_IR_DATA_DIVIDE) IR_DataShit |= 0x80; //devide data 0 or 1
- if(--IR_BitCnt == 0) //bit number is over?
- {
- B_IR_Sync = 0; //Clear SYNC
- if(~IR_DataShit == IR_data) //判斷數(shù)據(jù)正反碼
- {
- if((IR_UserH == (User_code / 256)) &&
- IR_UserL == (User_code % 256))
- B_IrUserErr = 0; //User code is righe
- else B_IrUserErr = 1; //user code is wrong
-
- IR_code = IR_data;
- B_IR_Press = 1; //數(shù)據(jù)有效
- _data_();
- }
- }
- else if((IR_BitCnt & 7)== 0) //one byte receive
- ……………………
- …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
0.png (10.36 KB, 下載次數(shù): 31)
下載附件
2019-3-5 21:15 上傳
所有資料51hei提供下載:
STC15F104紅外 MP3模塊.zip
(153.14 KB, 下載次數(shù): 70)
2019-3-5 20:16 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|