- /**********************************************************
- 读24c02子函数
- **********************************************************/
- void a24c02_read(void)
- {
- I2C_start();//启动总线
- I2C_write_byte(0xa0);//发送器件地址
- I2C_write_byte(0x00);////发送器件子地址
- I2C_start();//启动总线
- I2C_write_byte(0xa1);//发送器件读地址
- RDA_reg_data[2] = I2C_read_byte(I2C_ACK);
- RDA_reg_data[3] = I2C_read_byte(I2C_NACK);
- I2C_stop();
- }
- /**********************************************************
- 模块上电初始化子函数
- **********************************************************/
- void RDA5807_power(void)
- {
- delayms(50);
- // 发送软件复位指令
- RDA_reg_data[0] = 0x00;
- RDA_reg_data[1] = 0x02;
- RDA5807_write_reg();
- delayms(10);
- // 收音模块默认参数
- RDA_reg_data[0] = 0xd0;
- RDA_reg_data[1] = 0x01;
- a24c02_read();//读取保存的频率
- RDA_reg_data[3] += 0x10; //调谐启用
- RDA5807_write_reg();
- }
- /**********************************************************
- 频率计算子函数
- **********************************************************/
- void show_frequency(void)
- {
- unsigned int temp;
- temp = (RDA_reg_data[2]*256)+(RDA_reg_data[3]&0xc0); //计算
- temp = temp>>6;
- frequency = (unsigned long)(100*temp+87000)/100;
- }
- /**********************************************************
- 功能描述:收音模块自动寻台模式
- **********************************************************/
- void RDA5807_FM_seek(void)
- {
- uint chan;
- uchar reg_data[4] = {0x00, 0x00, 0x00, 0x00};
- RDA_reg_data[3] &= ~(1 << 4); //调谐禁用
- // 内部自动寻台使能
- RDA_reg_data[0] |= (1 << 0); //搜索位置1
- RDA5807_write_reg();
- // 等待STC 标志置位
- while(0 == (reg_data[0] & 0x40))
- {
- delayms(10);
- // 读取内部状态
- RDA5807_read_reg(reg_data);
- }
- // 获取当前工作频点
- chan = reg_data[0] & 0x03;
- chan = reg_data[1] | (chan << 8);
- chan = chan << 6;
- // 保存当前工作频点
- RDA_reg_data[2] = (chan >> 8) & 0xff;
- RDA_reg_data[3] = (chan & 0xff);
- a24c02_write();//保存当前频率
- }
- /************************************************************************
- led显示
- ************************************************************************/
- sbit ge=P2^4;
- sbit shi=P2^5;
- sbit bai=P2^6;
- sbit qan=P2^7;
- #define LED P0
- //unsigned char tab[]={ 0x3f,0x30,0x6d,0x79,0x72,0x5b,0x5f,0x31,0x7f,0x7b,0x40};//共阴
- //0, 1, 2 3 4 5 6 7 8 9
- unsigned char tab[]={ 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//共阳
- //0, 1, 2 3 4 5 6 7 8 9
|