关于qn8035收音机程序
顶一个,来个大神指点指点我呀
早上顶一个,来个大神帮帮忙,万分感谢
大神帮我看看这段大概对不对,思路是先初始化,然后就一直检测rds的信号质量,如果理想就开启声音,如果不理想就使能静音。中断检测功能键,如果有按键按下,就更改相应的数据,并写入8035寄存器。
unsigned char flag_fm,flag_aud;
unsigned int freq;
unsigned char aud;
unsigned char flag_on_off1=0;
unsigned char flag_on_off2=0;
/***************************************************************
*****************************************************************/
void timer0_init()
{
TMOD=0x01;
TH0=(65536-60000)/256;
TL0=(65536-60000)%256;
TR0=1;
ET0=1;
EA=1;
}
/****************************************************************
3?ê??ˉ8035
*******************************************************************/
void qn_8035_init()
{
send_1byte(0x00,0x81);
delay(10);
send_1byte(0x18,0x10);
send_1byte(0x2f,0x90);
send_1byte(0x40,0x01);
send_1byte(0x46,0x05);
send_1byte(0x47,0xd0);
send_1byte(0x48,0xa8);
send_1byte(0x14,0xc6);
send_1byte(0x00,0x51);
send_1byte(0x00,0x11);
send_1byte(0x01,0x49);
}
/***********************************************************
D′8035?μ?ê
************************************************************/
void write_8035freq(uint freq)
{
uchar freq_l;
uchar freq_h;
uint temp;
temp=(freq-6175)/5;
freq_l=temp%256;
freq_h=temp/256;
send_1byte(0x07,freq_l);
freq_h=freq_h&0x03;
send_1byte(0x0a,freq_h);
}
/***************************************************************
?á3?rdsμ???£??D??D?o??êá?
****************************************************************/
uchar rds_RSSI_read()
{
uchar val;
uchar temp;
temp=read_1byte(0x03);
if(temp>46)
{
val=temp-46;
}
else
val=0;
return val;
}
/********************************************************************
ò?á?μ÷?ú
***********************************************************************/
void audio_set(uchar aud)
{
send_1byte(0x14,aud);
}
/********************************************************************8
RDS3?ê??ˉ
**********************************************************************/
void rds_set()
{
send_1byte(0x00,0xa0);//enable rds
}
/************************************************************************
ê1?ü?2ò?
**************************************************************************/
void enable_mute()
{
sned_1byte(0x14,0xc6);
}
/***********************************************************************8
×??ˉ???÷
*************************************************************************/
/*
void auto_seek(uint freq_strat,uint freq_stop,uint freq_step)
{
uint freq_strat,freq_stop,freq_step;
uchar freq_h,freq_l;
uchar temp1,temp2;
freq_l=((freq_strat-6175)/5)%256;
freq_h=((freq_strat-6175)/5)/256;
temp1=freq_h;
send_1byte(0x08,freq_l);
freq_l=((freq_stop-6175)/5)%256;
freq_h=((freq_stop-6175)/5)/256;
temp2=freq_h;
send_1byte(0x09,freq_l);
freq_h=(temp1&0x0c)|(temp2&0x30)|(freq_step&0xc0);
send_1byte(0x0a,freq_h);
send_1byte(0x01,0x75);
send_1byte(0x00,0x10);
send_1byte(0x00,0x12);
delay(500);
}
*/
/***************************************************************
1|?ü?ü ?μ?ê?ó??oíéùò??ó??
********************************************************************/
void key_fm()
{
if(key1==0)
{
delay(3);
if(flag_on_off1==0)
{
flag_on_off=1;
if(key1==0)
{
freq++;
if(freq>1080)
freq=980;
flag_fmm=1;
}
}
}
else if(key2==0)
{
delay(3);
if(flag_on_off1==0)
{
flag_on_off1=1;
if(key2==0)
{
freq--;
if(freq<980)
freq=1080;
flag_fm=1;
}
}
}
else
flag_on_off1=0;
}
void key_audio()
{
if(key3==0)
{
delay(3);
if(flag_on_off2==0)
{
flag_on_off2=1;
if(key3==0)
{
aud++;
if(aud>8)
aud=8;
flag_aud=1;
}
}
}
else if(key4==0)
{
delay(3);
if(flag_on_off2==0)
{
flag_on_off2=1;
if(key4==0)
{
if(aud!=0)
aud--;
else
aud=0;
flag_aud=1;
}
}
}
else
flag_on_off2=0;
}
/****************************************************
*****************************************************/
void main()
{
uchar temp;
freq=980;
aud=4;
timer0_init();
qn_8035_init();
write_8035freq(freq);
//audio_set(aud);
rds_set();
mask=rds_RSSI_read();
if(temp)
audio_set(aud);
else
enable_mute();
while(1)
{
temp=rds_RSSI_read();
if(temp==0)
enable_mute();
if(flag_fm==1)
{
write_8035freq(freq);
delay(10);
flag_fm=0;
}
if(flag_aud==1)
{
audio_set(aud);
delay(10);
flag_aud=0;
}
}
}
void timer0() interrupt 1
{
TH0=(65536-60000)/256;
TL0=(65536-60000)%256;
key_fm();
key_audio();
}
这是完整的程序,路过的大神帮我看看,万分感谢
#include<reg52.h>
#include<intrins.h>
#include<stdio.h>
sfr P4=0xe8;
#define uchar unsigned char
#define uint unsigned int
sbit SDA=P2^6;
sbit CLK=P2^7;
sbit XCLK=P3^5;
bit ack;
void delay(uchar xms)
{
uchar i,j;
for(i=0;i<xms;i++)
for(j=0;j<110;j++);
}
void i2c_init()
{
SDA=1;
CLK=1;
}
void NOP()
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
void strat()
{
CLK=1;
NOP();
SDA=1;
NOP();
SDA=0;
NOP();
CLK=0;
NOP();
}
void stop()
{
SDA=0;
NOP();
CLK=1;
NOP();
SDA=1;
NOP();
}
bit send_byte(uchar date)
{
uchar i;
for(i=0;i<8;i++)
{
if((date<<i)&0x80)
SDA=1;
else
SDA=0;
_nop_();
CLK=1;
NOP();
CLK=0;
NOP();
}
SDA=1;
CLK=1;
NOP();
NOP();
if(SDA==1)
ack=0;
else
ack=1;
CLK=0;
return ack;
}
unsigned char read_byte()
{
uchar i,j;
SDA=1;
for(i=0;i<8;i++)
{
_nop_();
CLK=0;
NOP();
CLK=1;
NOP();
j=j<<1;
if(SDA==1)
j=j+1;
}
CLK=0;
return j;
}
/*
void send_ACK(bit a)
{
if(a==0)
SDA=0;
else
SDA=1;
_nop_();
CLK=1;
NOP();
CLK=0;
}
*/
bit send_1byte(uchar reg_addr,uchar date)
{
strat();
send_byte(0x20);
if(ack==0)
return 0;
send_byte(reg_addr);
if(ack==0)
return 0;
send_byte(date);
if(ack==0)
return 0;
stop();
return(1);
}
/*
bit send_nbyte(uchar reg_addr,uchar *s,uchar n)
{
uchar i;
strat();
send_byte(0x20);
if(ack==0)
return 0;
send_byte(reg_addr);
if(ack==0)
return 0;
for(i=0;i<n;i++)
{
send_byte(*s);
if(ack==0)
return 0;
s++;
}
stop();
return(1);
}
*/
unsigned char read_1byte(uchar reg_addr)
{
uchar date;
strat();
send_byte(0x20);
if(ack==0)
return 0;
send_byte(reg_addr);
if(ack==0)
return 0;
strat();
send_byte(0x21);
if(ack==0)
return 0;
date=read_byte();
stop();
return date;
}
/*
unsigned char read_nbyte(uchar reg_addr,uchar *c,uchar n)
{
uchar i;
strat();
send_byte(0x20);
if(ack==0)
return 0;
send_byte(reg_addr);
if(ack==0)
return 0;
strat();
send_byte(0x21);
if(ack==0)
return 0;
for(i=0;i<n;i++)
{
*c=read_byte();
send_ACK(0);
c++;
}
*c=read_byte();
send_ACK(1);
stop();
return(1);
}
*/
/***************************************************************************************
1602??ê?oˉêy
****************************************************************************************/
sbit EE=P1^0;
sbit RS=P1^2;
sbit RW=P1^1;
void wcom(uchar com)
{
RS=0;
RW=0;
P0=com;
delay(1);
EE=1;
EE=0;
}
void wdate(uchar date)
{
RS=1;
RW=0;
P0=date;
delay(1);
EE=1;
EE=0;
}
void lcd_init()
{
wcom(0x38);
wcom(0x0c);
wcom(0x06);
wcom(0x01);
}
/********************************************************************
********************************************************************/
sbit key1=P2^0;
sbit key2=P2^1;
sbit key3=P2^2;
sbit key4=P2^3;
unsigned char flag_fm,flag_aud;
unsigned int freq;
unsigned char aud;
unsigned char flag_on_off1=0;
unsigned char flag_on_off2=0;
/***************************************************************
*****************************************************************/
void timer0_init()
{
TMOD=0x01;
TH0=(65536-60000)/256;
TL0=(65536-60000)%256;
TR0=1;
ET0=1;
EA=1;
}
/****************************************************************
3?ê??ˉ8035
*******************************************************************/
void qn_8035_init()
{
send_1byte(0x00,0x81);
delay(10);
send_1byte(0x18,0x10);
send_1byte(0x2f,0x90);
send_1byte(0x40,0x01);
send_1byte(0x46,0x05);
send_1byte(0x47,0xd0);
send_1byte(0x48,0xa8);
send_1byte(0x14,0xc6);
send_1byte(0x00,0x51);
send_1byte(0x00,0x11);
send_1byte(0x01,0x49);
}
/***********************************************************
D′8035?μ?ê
************************************************************/
void write_8035freq(uint freq)
{
uchar freq_l;
uchar freq_h;
uint temp;
temp=(freq-6175)/5;
freq_l=temp%256;
freq_h=temp/256;
send_1byte(0x07,freq_l);
freq_h=freq_h&0x03;
send_1byte(0x0a,freq_h);
}
/***************************************************************
?á3?rdsμ???£??D??D?o??êá?
****************************************************************/
uchar rds_RSSI_read()
{
uchar val;
uchar temp;
temp=read_1byte(0x03);
if(temp>46)
{
val=temp-46;
}
else
val=0;
return val;
}
/********************************************************************
ò?á?μ÷?ú
***********************************************************************/
void audio_set(uchar aud)
{
send_1byte(0x14,aud);
}
/********************************************************************8
RDS3?ê??ˉ
**********************************************************************/
void rds_set()
{
send_1byte(0x00,0xa0);//enable rds
}
/************************************************************************
ê1?ü?2ò?
**************************************************************************/
void enable_mute()
{
send_1byte(0x14,0xc6);
}
/***********************************************************************8
×??ˉ???÷
*************************************************************************/
/*
void auto_seek(uint freq_strat,uint freq_stop,uint freq_step)
{
uint freq_strat,freq_stop,freq_step;
uchar freq_h,freq_l;
uchar temp1,temp2;
freq_l=((freq_strat-6175)/5)%256;
freq_h=((freq_strat-6175)/5)/256;
temp1=freq_h;
send_1byte(0x08,freq_l);
freq_l=((freq_stop-6175)/5)%256;
freq_h=((freq_stop-6175)/5)/256;
temp2=freq_h;
send_1byte(0x09,freq_l);
freq_h=(temp1&0x0c)|(temp2&0x30)|(freq_step&0xc0);
send_1byte(0x0a,freq_h);
send_1byte(0x01,0x75);
send_1byte(0x00,0x10);
send_1byte(0x00,0x12);
delay(500);
}
*/
/***************************************************************
1|?ü?ü ?μ?ê?ó??oíéùò??ó??
********************************************************************/
void key_fm()
{
if(key1==0)
{
delay(3);
if(flag_on_off1==0)
{
flag_on_off1=1;
if(key1==0)
{
freq++;
if(freq>1080)
freq=980;
flag_fm=1;
}
}
}
else if(key2==0)
{
delay(3);
if(flag_on_off1==0)
{
flag_on_off1=1;
if(key2==0)
{
freq--;
if(freq<980)
freq=1080;
flag_fm=1;
}
}
}
else
flag_on_off1=0;
}
void key_audio()
{
if(key3==0)
{
delay(3);
if(flag_on_off2==0)
{
flag_on_off2=1;
if(key3==0)
{
aud++;
if(aud>8)
aud=8;
flag_aud=1;
}
}
}
else if(key4==0)
{
delay(3);
if(flag_on_off2==0)
{
flag_on_off2=1;
if(key4==0)
{
if(aud!=0)
aud--;
else
aud=0;
flag_aud=1;
}
}
}
else
flag_on_off2=0;
}
void disp_freq(uint freq)
{
uchar qian,bai,shi,ge;
qian=freq/1000;
bai=freq/100%10;
shi=freq%100/10;
ge=freq%10;
wcom(0x80);
wdate('F');
wdate('M');
wdate(':');
wdate(' ');
wdate(qian+48);
wdate(bai+48);
wdate(shi+48);
wdate('.');
wdate(ge+48);
wdate('M');
wdate('H');
wdate('z');
}
void disp_vol(uchar aud)
{
wcom(0x80+0x40);
wdate('V');
wdate('O');
wdate('L');
wdate(':');
wdate(' ');
wdate(aud+48);
}
/****************************************************
*****************************************************/
void main()
{
uchar temp,mask;
freq=980;
aud=4;
i2c_init();
timer0_init();
qn_8035_init();
write_8035freq(freq);
//audio_set(aud);
rds_set();
mask=rds_RSSI_read();
if(temp)
audio_set(aud);
else
enable_mute();
lcd_init();
while(1)
{
temp=rds_RSSI_read();
if(temp==0)
enable_mute();
if(flag_fm==1)
{
write_8035freq(freq);
delay(10);
flag_fm=0;
}
if(flag_aud==1)
{
audio_set(aud);
delay(10);
flag_aud=0;
}
disp_freq(freq);
disp_vol(aud);
}
}
void timer0() interrupt 1
{
TH0=(65536-60000)/256;
TL0=(65536-60000)%256;
key_fm();
key_audio();
}
多发了一次,,,,,,,,
刚接触这芯片,也想了解下,发现芯片资料很少。请问下官网哪里有资料下载。能不能沟通下QQ464342065
我这有资料,都是在网上找的还有就是前辈们给的,不知道你现在还要不要
要啊,还在折腾中
小编 这段代码运行成功了没?能否把qn8035 也发我一份 2180742204@qq.com
小编请问你最后做好了吗,我现在急求
求资料 184164353@qq.com 跪谢
我这里有stm32调试好的QN8035,可以正常收音,接收RDS,需要嘛