|
基于51的數(shù)控收音機(jī)(帶時(shí)鐘顯示溫度顯示)程序經(jīng)過測(cè)試可以用。
下面是主程序:
- #include "iic.h"
- #include "reg51.h"
- #include "delay.h"
- #include "radio.h"
- #include "24c02.h"
- #define uchar unsigned char
- #define uint unsigned int
- extern uchar data Display_FM[8];
- extern uchar data Display_Vol[6];
- sbit K1 = P3^2;
- sbit K2 = P3^3;
- sbit K3 = P3^4;
- sbit K4 = P3^5;
-
- unsigned long frequency;
- unsigned char RDA_reg_data[8] =
- {
- 0xd0,0x00, // 02H
- 0x00,0x00, // 03H
- 0x00,0x40, // 04H
- 0x90,0x80, // 05H
- };
-
- char code reserve[3]_at_ 0x3b; // //保留0x3b開始的3個(gè)字節(jié)
- void RDA5807_write_reg(void)
- {
- uchar i;
-
- I2C_start(); //收音模塊寫入操作
- I2C_write_byte(0x20);
- for(i=0; i<8; i++)
- {
- I2C_write_byte(RDA_reg_data[i]);
- }
-
- I2C_stop();
- }
-
- void RDA5807_read_reg(uchar *reg_buf) //連續(xù)讀寄存器子函數(shù)
- {
- I2C_start();
- I2C_write_byte(0x21); //寄存器連續(xù)讀操作
- reg_buf[0] = I2C_read_byte(0);
- reg_buf[1] = I2C_read_byte(0);
- reg_buf[2] = I2C_read_byte(0);
- reg_buf[3] = I2C_read_byte(1);
- I2C_stop();
- }
-
- void RDA5807_power(void) //模塊上電初始化子函數(shù)
- {
- Delay_ms(50);
- RDA_reg_data[0] = 0x00; //發(fā)送軟件復(fù)位指令
- RDA_reg_data[1] = 0x02;
- RDA5807_write_reg();
- Delay_ms(10);
- RDA_reg_data[0] = 0xd0; //收音模塊默認(rèn)參數(shù)
- RDA_reg_data[1] = 0x01;
- a24c02_read();//讀取保存的頻率
- RDA_reg_data[3] += 0x10; //調(diào)諧啟用
- RDA5807_write_reg();
- }
- void RDA5807_FM_seek(void) //功能描述:收音模塊自動(dòng)尋臺(tái)模式
- {
- uint chan;
- uchar reg_data[4] = {0x00, 0x00, 0x00, 0x00};
-
- RDA_reg_data[3] &= ~(1 << 4); //調(diào)諧禁用 內(nèi)部自動(dòng)尋臺(tái)使
- RDA_reg_data[0] |= (1 << 0); //SEEK位置 1
- RDA5807_write_reg();
- while(0 == (reg_data[0] & 0x40)) //等待 STC 標(biāo)志置位
- {
- Delay_ms(20);
-
-
-
- RDA5807_read_reg(reg_data); //讀取內(nèi)部狀態(tài)
- }
- chan = reg_data[0] & 0x03; //獲取當(dāng)前工作頻點(diǎn)
- chan = reg_data[1] | (chan << 8);
- chan = chan << 6;
- RDA_reg_data[2] = (chan >> 8) & 0xff; //保存當(dāng)前工作頻點(diǎn)
- RDA_reg_data[3] = (chan & 0xff);
- a24c02_write();//保存當(dāng)前頻率
- }
-
- void show_frequency(void) //頻率顯示子函數(shù)
- {
- unsigned char i;
- unsigned int temp;
-
- temp = (RDA_reg_data[2]*256)+(RDA_reg_data[3]&0xc0); //計(jì)算
- temp = temp>>6;
- frequency = (unsigned long)(100*temp+87000)/100;
-
- for(i=0; i<5; i++)
- Display_FM[i] = 0x00; //清顯存單元
- Display_FM[0] = (frequency)/1000 ; //數(shù)據(jù)轉(zhuǎn)換
- Display_FM[1] = (frequency%1000)/100;
- Display_FM[2] = (frequency%100)/10;
- Display_FM[3] = 0x2e;//小數(shù)點(diǎn)
- Display_FM[4] = (frequency%10);
-
- if( Display_FM[0] == 0)
- {
- Display_FM[0] = Display_FM[1]+0x30;
- Display_FM[1] = Display_FM[2]+0x30;
- Display_FM[2] = Display_FM[3];
- Display_FM[3] = Display_FM[4]+0x30;
- Display_FM[4] = 0x20;
- }
- else
- {
- Display_FM[0] += 0x30;
- Display_FM[1] += 0x30;
- Display_FM[2] += 0x30;
- Display_FM[4] += 0x30;
- }
- }
-
- void show_volume()//音量顯示子函數(shù)
- {
- unsigned char temp;
-
- temp = RDA_reg_data[7] & 0x0f; //取音量值
- Display_Vol[3] = temp/10;
- Display_Vol[4] = temp%10;
-
- if(Display_Vol[3] == 0)// 如果高位為0
-
- {
- Display_Vol[3] = Display_Vol[4]; //低位顯存內(nèi)容進(jìn)入高位顯存
- Display_Vol[4] = 0x20;//低位不顯示
- }
- else
- Display_Vol[4] += 0x30;
- Display_Vol[3] += 0x30;
- }
- void Set_Frq() //按鍵設(shè)置
- {
- if(K1 == 0)
- {
- Delay_ms(20);
- if(K1 == 0)
- {
- RDA_reg_data[0] |= (1 << 1); //SEEK UP
- RDA5807_FM_seek();
- while(K1 == 0);
- }
- }
- if(K2 == 0)
- {
- Delay_ms(20);
- if(K2 == 0)
- {
- RDA_reg_data[0] &= ~(1 << 1); //SEEK DOWN
- RDA5807_FM_seek();
- while(K2 == 0);
- }
- }
- if(K3 == 0)
- {
- Delay_ms(20);
- if(K3 == 0)
- {
- if((RDA_reg_data[7] & 0x0f) < 0x0f)
- {
- RDA_reg_data[0] = 0xd0;
- RDA_reg_data[1] = 0x01;
- RDA_reg_data[3] &= ~(1 << 4);
-
- RDA_reg_data[7]++; //音量遞增
- RDA5807_write_reg();
- while(K3 == 0);
- }
- }
- }
-
- if(K4 == 0)
- {
- Delay_ms(20);
- if(K4 == 0)
- {
- if((RDA_reg_data[7] & 0x0f) > 0x00)
- {
- RDA_reg_data[0] = 0xd0;
- RDA_reg_data[1] = 0x01;
- RDA_reg_data[3] &= ~(1 << 4);
-
- RDA_reg_data[7]--; //音量遞減
- RDA5807_write_reg();
- while(K4 == 0);
- }
- }
- }
- }
-
復(fù)制代碼
|
-
-
數(shù)控收音機(jī).rar
2016-3-11 22:52 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
105.53 KB, 下載次數(shù): 263, 下載積分: 黑幣 -5
程序
評(píng)分
-
查看全部評(píng)分
|